An immutable rectangle whose boundaries are stored with double floating point precision.

Note that for DoubleRect we regard the vertical coordinate as increasing upwards, so the top coordinate is greater than the bottom coordinate. This is in contrast to HTML5 canvas where vertical coordinates increase downwards.

to do: consider implementing a 'real' equals method, see Bloch, Effective Java

to do: consider making a mutable version, and providing methods that work on that.

Constructors

  • Parameters

    • left: number

      left side of DoubleRect, must be less than right

    • bottom: number

      bottom of DoubleRect, must be less than top

    • right: number

      right side of DoubleRect

    • top: number

      top of DoubleRect

    Returns DoubleRect

    Throws

    when left > right or bottom > top

Properties

EMPTY_RECT: DoubleRect = ...

The empty rectangle (0, 0, 0, 0).

Methods

  • Returns true if the given point is within this rectangle.

    Parameters

    Returns boolean

    true if the point is within this rectangle, or exactly on an edge

  • Returns true if the object is a DoubleRect with the same coordinates.

    Parameters

    • obj: any

      the object to compare to

    Returns boolean

    true if the object is a DoubleRect with the same coordinates.

  • Returns a copy of this DoubleRect expanded by the given margin in x and y dimension.

    Parameters

    • marginX: number

      the margin to add at left and right

    • Optional marginY: number

      the margin to add at top and bottom; if undefined then marginX is used for both x and y dimension

    Returns DoubleRect

    a DoubleRect with same center as this DoubleRect, but expanded or contracted

  • Returns the smallest vertical coordinate of this DoubleRect

    Returns number

    smallest vertical coordinate of this DoubleRect

  • Returns the horizontal coordinate of center of this DoubleRect.

    Returns number

    horizontal coordinate of center of this DoubleRect

  • Returns the vertical coordinate of center of this DoubleRect.

    Returns number

    vertical coordinate of center of this DoubleRect

  • Returns the vertical height of this DoubleRect

    Returns number

    vertical height of this DoubleRect

  • Returns the smallest horizontal coordinate of this DoubleRect

    Returns number

    smallest horizontal coordinate of this DoubleRect

  • Returns the largest horizontal coordinate of this DoubleRect

    Returns number

    largest horizontal coordinate of this DoubleRect

  • Returns the largest vertical coordinate of this DoubleRect

    Returns number

    largest vertical coordinate of this DoubleRect

  • Returns the horizontal width of this DoubleRect

    Returns number

    horizontal width of this DoubleRect

  • Returns a rectangle that is the intersection of this and another rectangle.

    Parameters

    • rect: DoubleRect

      the other rectangle to form the intersection with

    Returns DoubleRect

    the intersection of this and the other rectangle, possibly an empty rectangle.

  • Returns true if width or height of this DoubleRect are zero (within given tolerance).

    Parameters

    • Optional opt_tolerance: number

      optional tolerance for the test; a width or height smaller than this is regarded as zero; default is 1E-16

    Returns boolean

    true if width or height of this DoubleRect are zero (within given tolerance)

  • Returns true if the line between the two points might be visible in the rectangle.

    Parameters

    Returns boolean

    true if the line between the two points might be visible in the rectangle

  • Returns true if this DoubleRect is nearly equal to another DoubleRect. The optional tolerance value corresponds to the epsilon in Util.veryDifferent, so the actual tolerance used depends on the magnitude of the numbers being compared.

    Parameters

    • rect: DoubleRect

      the DoubleRect to compare with

    • Optional opt_tolerance: number

      optional tolerance for equality test

    Returns boolean

    true if this DoubleRect is nearly equal to another DoubleRect

  • Returns a copy of this DoubleRect expanded by the given factors in both x and y dimension. Expands (or contracts) about the center of this DoubleRect by the given expansion factor in x and y dimensions.

    Parameters

    • factorX: number

      the factor to expand width by; 1.1 gives a 10 percent expansion; 0.9 gives a 10 percent contraction

    • Optional factorY: number

      factor to expand height by; if undefined then factorX is used for both x and y dimension

    Returns DoubleRect

    a DoubleRect with same center as this DoubleRect, but expanded or contracted

  • Returns a copy of this rectangle translated by the given amount.

    Parameters

    • x: number | GenericVector

      horizontal amount to translate by, or Vector to translate by

    • Optional y: number

      vertical amount to translate by; required when x is a number.

    Returns DoubleRect

    a copy of this rectangle translated by the given amount

    Throws

    when x is a number and y is not defined

  • Returns a DoubleRect centered at the given point with given height and width.

    Parameters

    • center: GenericVector

      center of the DoubleRect

    • width: number

      width of the DoubleRect

    • height: number

      height of the DoubleRect

    Returns DoubleRect

    a DoubleRect centered at the given point with given height and width

Generated using TypeDoc