Options
All
• Public
• Public/Protected
• All

# @thi.ng/intervals

## Functions

### Const clamp

• clamp(i: Readonly<Interval>, x: number, eps?: number): number
• Clamps `x` to interval `i`, using {@link Interval.min} and {@link Interval.max}.

-

-

-

### Const classify

• Returns classifier for interval `a` WRT given interval `b`. E.g. if the result is `Classifier.SUPERSET`, then interval `a` fully contains `b`.

``````EQUIV
[   a     ]
[   b     ]

DISJOINT_LEFT
[ b ]
[ a ]

DISJOINT_RIGHT
[ a ]
[ b ]

SUPERSET
[ a         ]
[ b   ]

SUBSET
[ b         ]
[ a ]

OVERLAP_RIGHT
[ a     ]
[ b ]

OVERLAP_LEFT
[ b     ]
[ a ]
``````

-

-

### Const closed

• closed(min: number, max: number): Interval
• Returns a closed interval `(min..max)`.

### Const closedOpen

• closedOpen(min: number, max: number): Interval
• Returns a semi-open interval `[min..max)`, open on the RHS.

### Const compare

• Compares interval `a` with `b` and returns a comparator value (-1, 0 or 1). Comparison order is: LHS, RHS, openness.

-

-

### Const contains

• contains(i: Readonly<Interval>, x: number): boolean
• Returns true if `x` is lies within interval `i`.

-

-

### Const distance

• Returns the distance between intervals, or zero if they touch or overlap.

-

-

### Const include

• Returns a new version of interval `i` such that `x` is included. If `x` lies outside the current interval, the new one will be extended correspondingly.

-

-

### Const infinity

• Returns new infinite interval `[-∞..∞]`

### Const intersection

• Returns the intersection of the two given intervals, taken their openness into account. Returns undefined if `a` and `b` don't overlap.

### interval

• interval(spec: string): Interval
• interval(l: number, r: number, lopen?: boolean, ropen?: boolean): Interval

### Const isAfter

• Returns true iff interval `i` LHS > `x`, taking into account openness. If `x` is an interval, then checks `i` LHS is greater than RHS of `x` (again with openness).

-

-

### Const isBefore

• Returns true iff interval `i` RHS < `x`, taking into account openness. If `x` is an interval, then checks `i` RHS is less than LHS of `x` (again with openness).

-

-

### Const isEmpty

• Returns true, if interval has zero range, i.e. if LHS >= RHS.

-

### Const max

• max(i: Readonly<Interval>, x: number, eps?: number): number
• Returns the greater value of either `x` or interval `i`'s LHS value. If the interval is open on the LHS, and `x <= l`, then `l + eps` will be returned.

-

-

-

### Const min

• min(i: Readonly<Interval>, x: number, eps?: number): number
• Returns the lesser value of either `x` or interval `i`'s RHS value. If the interval is open on the RHS, and `x >= r`, then `r - eps` will be returned.

-

-

-

### Const open

• open(min: number, max: number): Interval
• Returns an open interval `(min..max)`

### Const openClosed

• openClosed(min: number, max: number): Interval
• Returns a semi-open interval `(min..max]`, open on the LHS.

### Const overlaps

• Returns true if interval `a` intersects `b` in any way (incl. subset / superset).

-

-

### Const parse

• Parses given ISO 80000-2 interval notation into a new `Interval` instance. In addition to the comma separator, `..` can be used alternatively. The following symbols (with optional sign) can be used for infinity (case insensitive):

• inf
• infinity
• ∞ (\u221e)

An empty LHS defaults to `-Infinity`. The RHS defaults to `+Infinity`.

Openness / closedness symbols:

• LHS: open: `]` / `(`, closed: `[`
• RHS: open: `[` / `)`, closed: `]`
``````// semi-open interval between -∞ and +1
Interval.parse("[,1)")

// closed interval between -1 and +1
Interval.parse("[-1 .. 1]")
``````

-

### samples

• samples(i: Readonly<Interval>, n: number): Generator<number, void, unknown>
• Returns an iterator yielding up to `n` uniformly spaced samples in given interval. If the interval is open on either side, the first and/or last sample will be omitted.

example
``````[...samples(closed(10, 12), 5)]
// [10, 10.5, 11, 11.5, 12]

[...samples(open(10, 12), 5)]
// [10.5, 11, 11.5]
``````

-

-

### Const transform

• Applies given `fn` to both sides of interval `i` and returns a new Interval of transformed end points.

-

-

### Const union

• Returns the union of the two given intervals, taken their openness into account.

### Const values

• values(i: Readonly<Interval>, step: number): Generator<number, void, unknown>
• Returns iterator of values in given interval at given `step` size. If the interval is open on either side, the first and/or last sample will be omitted.

-

-

### Const withMax

• withMax(max: number, open?: boolean): Interval
• Returns new interval of `[∞..max]` or `[∞..max)` depending on if `open` is true (default: false).

-

-

### Const withMin

• withMin(min: number, open?: boolean): Interval
• Returns new interval of `[min..∞]` or `(min..∞]` depending on if `open` is true (default: false).

-

-

#### Returns Interval

Generated using TypeDoc