Utility for normalizing a numeric range, with a wrapping function useful for polar coordinates.
var nr = ;nr;//=> 40nr;//=> 270nr;//=> 100nr;//=> 0// There is a convenient currying functionvar wrapAngle = nrwrap;var limitTo10 = nrlimit;;//=> 330
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 will not be wrapped.
nr === 0;nr === 0;nr === 1;nr === 359;
You are not restricted to whole numbers, and ranges can be negative.
var π = MathPI;var radianRange = nr;redianRange === 0;nr === -π;nr === -2 * π / 3;
Normalize the value by bringing it within the range.
value is greater than
max will be returned.
value is less than
min will be returned.
value is returned unaltered.
Both ends of this range are inclusive.
value is within the range,
It defaults to
inclusive on both ends of the range, but that can be
changed by setting
maxExclusive to a truthy value.
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
var angle = ;angle//=> -90angle//=> 180angle//=> trueangle//=> throws an Errorangle // or angle.name()//=> "[-180,180)"
The minimum value (inclusive) of the range.
The maximum value (exclusive) of the range.
The value to be normalized.
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)
MIT © James Talmage