Class Interval

A connected set represented by its endpoints lowerBound and upperBound.

Remarks

Consider using the aliases described down below instead of specifying bound inclusion by hand.

Some common intervals are already defined like Real and NonNegative.

All intervals can be constructed with a NumberTransform that can be used to

  • include sanity checks like Number.isSafeInteger(x) (think of them as type constraints)
  • actually transform the bounds, for example clamping the values to nonnegative numbers

The NumberTransform is propagated by all functions returning Interval or NumberSet using the NumberTransform from the called Interval.

Aliases:

Hierarchy

  • Interval

Constructors

  • Parameters

    • __namedParameters: {
          lowerBound: number;
          lowerBoundIncluded: boolean;
          numberTransform?: NumberTransform;
          upperBound: number;
          upperBoundIncluded: boolean;
      }
      • lowerBound: number
      • lowerBoundIncluded: boolean
      • Optional numberTransform?: NumberTransform
      • upperBound: number
      • upperBoundIncluded: boolean

    Returns Interval

Properties

lowerBound: number
lowerBoundIncluded: boolean
numberTransform: NumberTransform
upperBound: number
upperBoundIncluded: boolean
BottomClosed: ((lowerBound: number, upperBound: number, numberTransform?: NumberTransform) => Interval) = ...

Type declaration

BottomOpen: ((lowerBound: number, upperBound: number, numberTransform?: NumberTransform) => Interval) = ...

Type declaration

Closed: ((lowerBound: number, upperBound: number, numberTransform?: NumberTransform) => Interval) = ...

Type declaration

Open: ((lowerBound: number, upperBound: number, numberTransform?: NumberTransform) => Interval) = ...

Type declaration

TopClosed: ((lowerBound: number, upperBound: number, numberTransform?: NumberTransform) => Interval) = ...

Type declaration

TopOpen: ((lowerBound: number, upperBound: number, numberTransform?: NumberTransform) => Interval) = ...

Type declaration

Methods

  • Returns

    True if x is included in this Interval

    Parameters

    • x: number

      Number to search for

    Returns boolean

  • Example

    Interval.Closed(0,1).scaleBy(-2) // "[-2,0]"
    

    Returns

    The Interval scaled by the factor

    Throws

    RangeError if factor === Infinity or factor === -Infinity

    Parameters

    • factor: number

      scale factor

    Returns Interval

  • Transforms the Interval to its string representation using square brackets for included and parentheses for excluded endpoints

    Example

    console.log(Interval.BottomClosed(0,1)) // "[0,1)"
    

    Returns

    This interval's string representation

    Returns string

  • Constructs an Interval from a string representation

    Remarks

    Included endpoints are denoted by square brackets and excluded ones by either parentheses or reversed square brackets. Prefer constructing directly from number values instead of strings if possible

    Example

    Interval.fromString("[0,1)").equals(Interval.BottomClosed(0,1)) // true
    Interval.fromString("[0,1[").equals(Interval.fromString("[0,1)")) // true

    Returns

    Interval corresponding to the string representation

    Throws

    ParseError if s is malformed

    Parameters

    Returns Interval

Generated using TypeDoc