Represents a rectangle in 2D space, parallel to the XY axes.

invariant: w ≥ 0, h ≥ 0, immutable

Hierarchy (view full)

Constructors

Properties

area: number
h: number
size: Vec3
topLeft: Vec3

Derived state: topLeft assumes up is -y

w: number
x: number
y: number
empty: Rect2 = ...
unitSquare: Rect2 = ...

Accessors

Methods

  • Returns true if and only if the given point is contained within this shape.

    epsilon is a small number used to counteract floating point error. Thus, if point is within epsilon of the inside of this shape, containsPoint may also return true.

    The default implementation relies on signedDistance. Subclasses may override this method to provide a more efficient implementation.

    Parameters

    Returns boolean

  • Returns a the subdivision of this into [columns] columns and [rows] rows. For example, Rect2.unitSquare.divideIntoGrid(2, 2) -> [ Rect2(0, 0, 0.5, 0.5), Rect2(0.5, 0, 0.5, 0.5), Rect2(0, 0.5, 0.5, 0.5), Rect2(0.5, 0.5, 0.5, 0.5) ] The rectangles are ordered in row-major order.

    Parameters

    • columns: number
    • rows: number

    Returns Rect2[]

  • Parameters

    • other: Rect2
    • tolerance: number = 0

    Returns boolean

    true iff this is equal to other ± tolerance

  • Returns a bounding box that precisely fits the content of this shape.

    Note: This bounding box should aligned with the x/y axes. (Thus, it may be possible to find a tighter bounding box not axes-aligned).

    Returns Rect2

  • Returns this grown by [margin] in both the x and y directions.

    Parameters

    • margin: number

    Returns Rect2

  • Returns a rectangle containing this and [point]. [margin] is the minimum distance between the new point and the edge of the resultant rectangle.

    Parameters

    • point: Vec3
    • margin: number = 0

    Returns Rect2

  • Returns the overlap of this and [other], or null, if no such overlap exists

    Parameters

    Returns null | Rect2

  • Parameters

    Returns boolean

    true iff this and other overlap

  • Returns true iff all points in this rectangle are within distance from point:

    If RR is the set of points in this rectangle, returns true iff aR,pointa<radius \forall {\bf a} \in R, |\texttt{point} - {\bf a}| < \texttt{radius}

    Parameters

    • radius: number
    • point: Vec3

    Returns boolean

  • [affineTransform] is a transformation matrix that both scales and translates. the bounding box of this' four corners after transformed by the given affine transformation.

    Parameters

    Returns Rect2

  • Returns a box that contains all points in [points] with at least [margin] between each point and the edge of the box.

    Parameters

    • points: Vec3[]
    • margin: number = 0

    Returns Rect2

  • Parameters

    Returns Rect2

    a rectangle that contains all of the given rectangles, the bounding box of the given rectangles.

Generated using TypeDoc

OpenSource licenses