Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/intervals

Index

Functions

Const centroid

Const clamp

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

    Parameters

    • i: Readonly<Interval>

      -

    • x: number

      -

    • eps: number = ...

      -

    Returns number

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 ]
    

    Parameters

    Returns Classifier

Const closed

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

    Parameters

    • min: number
    • max: number

    Returns Interval

Const closedOpen

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

    Parameters

    • min: number
    • max: number

    Returns Interval

Const compare

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

    Parameters

    Returns number

Const contains

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

    Parameters

    Returns boolean

Const distance

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

    Parameters

    Returns number

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.

    Parameters

    Returns Interval

Const infinity

Const intersection

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

    Parameters

    Returns undefined | Interval

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).

    Parameters

    Returns boolean

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).

    Parameters

    Returns boolean

Const isEmpty

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

    Parameters

    Returns boolean

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.

    Parameters

    • i: Readonly<Interval>

      -

    • x: number

      -

    • eps: number = ...

      -

    Returns number

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.

    Parameters

    • i: Readonly<Interval>

      -

    • x: number

      -

    • eps: number = ...

      -

    Returns number

Const open

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

    Parameters

    • min: number
    • max: number

    Returns Interval

Const openClosed

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

    Parameters

    • min: number
    • max: number

    Returns Interval

Const overlaps

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

    Parameters

    Returns boolean

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]")
    

    Parameters

    • src: string

      -

    Returns Interval

Const prefix

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]
    

    Parameters

    Returns Generator<number, void, unknown>

Const suffix

Const transform

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

    Parameters

    • i: Readonly<Interval>

      -

    • fn: Fn<number, number>

      -

    Returns Interval

Const union

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.

    Parameters

    Returns Generator<number, void, unknown>

Const withMax

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

    Parameters

    • max: number

      -

    • open: boolean = false

      -

    Returns Interval

Const withMin

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

    Parameters

    • min: number

      -

    • open: boolean = false

      -

    Returns Interval

Generated using TypeDoc