number-pairs
Javascript utility for dealing with ranges of numbers and/or dates expressed as length-2 arrays.
contains
tests if a range expressed as a pair of numbers contains some other value
// true, 4 is in contained in the range 2-6 // false
A range is considered to contain its lower bound but not its upper:
// true // true // false
centredOn
Creates a new range of the same size, but centred around a new value (think panning):
// [-9.5, 10.5]
mid
Calculates the midpoint of a pair of numbers
// 0 // 7.5
pairExtent
// 11
interpolateBetweenPair
// 7.5 // 5 // 10
rangesOverlap
// returns true - these ranges overlap // returns false - these ranges do notoverlap
overlap
// same as:
expandPair
Expand a range so that it the returned value is proptionally larger (or smaller) than the given value.
it holds that:
/ === n
so, to double the extent of a range:
to half the extent of a range:
max
Enforces the maximum extent of a range, while keeping the centre point the same (think viewport minimum)
min
Enforces the minimum extent of a range, while keeping the centre point the same (think viewport minimum)