Creates a sorted interval from two values. The values don't need to be provided in order as they are sorted when the interval is constructed. This means that the T0 value may be reassigned to T1 if it's the largest value, and vice versa.
One end of the interval. This value may be assigned to T1 if it is the largest parameter.
The other end of the interval. This value may be assigned to T0 if it is the smallest parameter.
Gets the start of the interval.
Gets the end of the interval.
A sorted interval is always increasing, so this will return false.
A sorted interval is always increasing, so this will return true.
Gets T1, which is always the min value in a sorted interval.
Gets T0, which is always the min value in a sorted interval.
Creates an interval of a given length, centered on a value.
The middle value of the interval.
The length of the interval.
Finds the overlapping portion of two intervals and returns the resulting interval.
An interval representing the overlap between these two intervals. If there is no overlap, returns undefined.
Converts the interval into an IntervalSorted and returns the sorted interval.
Checks whether a value is within the interval.
The value to check for containment.
The amount the value can be outside the interval and still be considered inside.
Checks whether the value is within the interval and returns the result using the PointContainment enum. The value will be considered coincident if it equals the interval's min or max.
The value to check for containment.
The distance the value can be from the interval's min or max and still considered coincident.
The interval to compare against.
Creates a copy of this interval expanded to contain a given value. The direction of the interval, whether it is increasing or decreasing, will be preserved. Depending on where the value falls in relation to the interval, either T0 or T1 will change to accommodate the value.
Value to contain within the new interval.
Moves the min and max apart by a set amount. Returns the enlarged interval.
const interval = new IntervalSorted(5, 10);
const expanded = interval.inflate(2);
console.log(expanded.min);
// => 3
console.log(expanded.max);
// => 12
The distance to move the min and max values. If positive, the overall length of the interval will grow. If negative, the overall length will shrink.
Remaps a value from the global number system into the normalized parameters of this interval. See valueAt to understand how the parameters are calculated.
Value to remap to the parameter of the interval.
The value as a normalized parameter for the interval.
Gets the interval as a string in the format: [T0,T1]
.
Remaps a value from normalized parameters of this interval into the global number system. The interval's parameters range from 0 to 1.
A parameter of 0 is equal to the start of the interval (T0). A parameter of 0.5 is the mid point of the interval. And a parameter of 1 is the end of the interval (T1).
The parameter to remap.
The parameter remapped to the global number system.
Creates a copy of this interval with a different max value.
New max value for the new interval
Creates a copy of this interval with a different min value.
New min value for the new interval
Creates a copy of the interval with a different T0 value.
Creates a copy of the interval with a different T1 value.
Generated using TypeDoc
A special Interval where T0 is always the smallest value and T1 is always the largest. As a result, isIncreasing will always return
true
.Example
import { IntervalSorted } from 'shapetypes' // Create sorted interval const interval = new IntervalSorted(5, 10); // Get properties of the interval console.log(interval.length); // => 5 console.log(interval.mid); // => 7.5 console.log(interval.contains(8)); // => True console.log(interval.isIncreasing); // => True