|
sfcode
An Online Competing and Development Environment
|
Utility for normalizing a numeric range, with a wrapping function useful for polar coordinates.
Normalizes a values that "wraps around". For example, in a polar coordinate system, 270˚ can also be represented as -90˚. For wrapping purposes we assume max is functionally equivalent to min, and that wrap(max + 1) === wrap(min + 1). Wrap always assumes that min is inclusive, and max is exclusive. In other words, if value === max the function will wrap it, and return min, but min will not be wrapped.
You are not restricted to whole numbers, and ranges can be negative.
Normalize the value by bringing it within the range. If value is greater than max, max will be returned. If value is less than min, min will be returned. Otherwise, value is returned unaltered. Both ends of this range are inclusive.
Returns true if value is within the range, false otherwise. It defaults to inclusive on both ends of the range, but that can be changed by setting minExclusive and/or maxExclusive to a truthy value.
Returns value or throws an error if value is outside the specified range.
Returns a string representing this range in range notation.
Convenience method for currying all method arguments except value.
Required
Type: number
The minimum value (inclusive) of the range.
Required
Type: number
The maximum value (exclusive) of the range.
Required
Type: number
The value to be normalized.
Type: number
The normalized value.
npm test: tests, linting, coverage and style checks.npm run watch: autotest mode for active development.npm run debug: run tests without coverage (istanbul can obscure line #'s)Release via cut-release tool.
MIT © James Talmage