Performs a calculation within a wrapping number range. This is a lower-level function.
See also: wrapInteger for simple wrapping within a range.
min and max define the start and end of the valid range, inclusive. Eg for hue degrees it'd be 0, 360.
a and b is the range you want to work in.
For example, let's say you want to get the middle point between a hue of 30 and a hue of 330 (ie warmer colours):
wrapRange(0,360, (distance) => { // for a:0 and b:330, distance would be 90 from 30 degrees to 330 (via zero) returndistance * 0.5; // eg return middle point }, 30, 330);
The return value of the callback should be in the range of 0-distance. wrapRange will subsequently
conform it to the min and max range before it's returned to the caller.
Performs a calculation within a wrapping number range. This is a lower-level function. See also: wrapInteger for simple wrapping within a range.
min
andmax
define the start and end of the valid range, inclusive. Eg for hue degrees it'd be 0, 360.a
andb
is the range you want to work in.For example, let's say you want to get the middle point between a hue of 30 and a hue of 330 (ie warmer colours):
The return value of the callback should be in the range of 0-distance.
wrapRange
will subsequently conform it to themin
andmax
range before it's returned to the caller.