math-interval-2
Version:
Create math intervals like '(-∞, 100]' and test values
94 lines (93 loc) • 2.96 kB
TypeScript
export declare class MathInterval {
/**
* Returns an interval equivalent to:
* (a, b) = {x | a < x < b}
*/
static open(lower: number, upper: number): MathInterval;
/**
* Returns an interval equivalent to:
* [a, b] = {x | a <= x <= b}
*/
static closed(lower: number, upper: number): MathInterval;
/**
* Returns an interval equivalent to:
* [a, b) = {x | a <= x < b}
*/
static closedOpen(lower: number, upper: number): MathInterval;
/**
* Returns an interval equivalent to:
* (a, b] = {x | a < x <= b}
*/
static openClosed(lower: number, upper: number): MathInterval;
/**
* Returns an interval equivalent to:
* (a, ∞) = {x | a < x < ∞}
*/
static greaterThan(lower: number): MathInterval;
/**
* Returns an interval equivalent to:
* [a, ∞) = {x | a < x < ∞}
*/
static atLeast(lower: number): MathInterval;
/**
* Returns an interval equivalent to:
* (-∞, a) = {x | -∞ < x < a}
*/
static lessThan(upper: number): MathInterval;
/**
* Returns an interval equivalent to:
* (-∞, a] = {x | -∞ < x <= a}
*/
static atMost(upper: number): MathInterval;
/**
* Returns an interval equivalent to:
* (-∞, ∞) = {x | -∞ < x < ∞}
*/
static all(): MathInterval;
/**
* Returns an interval equivalent to:
* for interval(a, true, b, false) -> [a, b) = {x | a <= x < b}
*/
static interval(lower: number, lowerClosed: boolean, upper: number, upperClosed: boolean): MathInterval;
private readonly lowerBound;
private readonly upperBound;
private readonly intervalString;
private constructor();
private validate();
private getIntervalString();
isLowerBoundClosed(): boolean;
isUpperBoundClosed(): boolean;
lowerEndpoint(): number;
upperEndpoint(): number;
containsAll(numbers: number[]): boolean;
/**
* Behaves exactly as you might expect
*/
contains(n: number): boolean;
/**
* Returns true,
* if there is some interval enclosed by both of these intervals
*/
isConnected(other: MathInterval): boolean;
/**
* Returns true,
* if the bounds of the inner interval do not extend outside the bounds of the outer interval
*/
encloses(other: MathInterval): boolean;
/**
* Returns the minimal interval that encloses both this interval and other.
* If the intervals are both connected, this is their union.
*/
span(other: MathInterval): MathInterval;
/**
* Returns the maximal interval enclosed by both this interval and other
* if they are connect, otherwise throws error
*/
intersection(connected: MathInterval): MathInterval;
equals(other: MathInterval): boolean;
/**
* Returns string representation of the interval
* in form of `[a, b)`
*/
toString(): string;
}