@tspro/ts-utils-lib - v3.4.0
    Preparing search index...

    Class Rect

    Mutable axis-aligned 2D rectangle defined by a top-left corner (x, y) and non-negative size (width, height).

    This class represents a basic geometric rectangle without an anchor. All operations assume a coordinate system where:

    • left = x
    • top = y
    • right = x + width
    • bottom = y + height

    Width and height are always non-negative. An error is thrown if violated.

    Index

    Constructors

    • Create an empty rectangle at the origin.

      Returns Rect

    • Create a copy of another Rect.

      Parameters

      Returns Rect

    • Create a rectangle from a rect-like object.

      Accepts { left, top, width, height }.

      Parameters

      • other: { height: number; left: number; top: number; width: number }

      Returns Rect

    • Create a rectangle with size only. The rectangle is positioned at the origin.

      Parameters

      • width: number
      • height: number

      Returns Rect

    • Create a rectangle from position and size.

      Parameters

      • x: number

        Left coordinate

      • y: number

        Top coordinate

      • width: number

        Rectangle width (must be non-negative)

      • height: number

        Rectangle height (must be non-negative)

      Returns Rect

    Properties

    height: number
    width: number
    x: number
    y: number

    Accessors

    • get area(): number

      Rectangle area (width * height).

      Returns number

    • get bottom(): number

      Bottom edge coordinate.

      Returns number

    • get center(): { x: number; y: number }

      Geometric center point.

      Returns { x: number; y: number }

    • get centerX(): number

      Geometric center x-coordinate.

      Returns number

    • get centerY(): number

      Geometric center y-coordinate.

      Returns number

    • get isEmpty(): boolean

      Whether this rectangle has zero or negative area. Note: width and height are guaranteed non-negative.

      Returns boolean

    • get left(): number

      Left edge coordinate.

      Returns number

    • get right(): number

      Right edge coordinate.

      Returns number

    • get top(): number

      Top edge coordinate.

      Returns number

    Methods

    • Create a copy with all edges rounded up.

      Returns Rect

    • Create a deep copy of this rectangle.

      Returns Rect

    • Test whether a point lies inside or on the edges of this rectangle.

      Parameters

      • px: number
      • py: number

      Returns boolean

    • Test whether another rectangle is fully contained within this rectangle.

      Parameters

      Returns boolean

    • Test for exact equality with another rectangle.

      Parameters

      Returns boolean

    • Expand this rectangle to include a point.

      Parameters

      • px: number
      • py: number

      Returns Rect

    • Create a copy with all edges rounded down.

      Returns Rect

    • Create an inflated (expanded) copy of this rectangle.

      Parameters

      • dx: number

        Horizontal expansion

      • dy: number

        Vertical expansion

      Returns Rect

    • Create an inset (shrunken) copy of this rectangle.

      Parameters

      • dx: number

        Horizontal inset

      • dy: number

        Vertical inset

      Returns Rect

    • Compute the intersection of this rectangle with another rectangle.

      Returns an empty rectangle if there is no overlap.

      Parameters

      Returns Rect

    • Compute the intersection of this rectangle with another rectangle.

      Returns an empty rectangle if there is no overlap.

      Parameters

      • other: { height: number; left: number; top: number; width: number }

      Returns Rect

    • Test whether this rectangle intersects another rectangle.

      Edge-touching is considered an intersection.

      Parameters

      Returns boolean

    • Test whether this rectangle intersects another rectangle.

      Edge-touching is considered an intersection.

      Parameters

      • other: { height: number; left: number; top: number; width: number }

      Returns boolean

    • Create a translated copy of this rectangle.

      Parameters

      • dx: number
      • dy: number

      Returns Rect

    • Move this rectangle by the given offset. Modifies this instance.

      Parameters

      • dx: number
      • dy: number

      Returns Rect

    • Create a copy with all edges rounded to the nearest integer.

      Returns Rect

    • Create a scaled copy of this rectangle. Scaling is performed around the geometric center.

      Parameters

      • scaleX: number
      • scaleY: number = scaleX

      Returns Rect

    • Scale this rectangle around its geometric center. Modifies this instance.

      Parameters

      • scaleX: number

        Horizontal scale factor

      • scaleY: number = scaleX

        Vertical scale factor (defaults to scaleX)

      Returns Rect

    • Reset this rectangle to the origin with zero size.

      Returns Rect

    • Set rectangle size and reset position to the origin.

      Parameters

      • width: number

        Rectangle width (must be non-negative)

      • height: number

        Rectangle height (must be non-negative)

      Returns Rect

    • Set rectangle position and size.

      Parameters

      • x: number

        Left coordinate

      • y: number

        Top coordinate

      • width: number

        Rectangle width (must be non-negative)

      • height: number

        Rectangle height (must be non-negative)

      Returns Rect

    • Convert this rectangle to an AnchoredRect. The anchor is placed at the geometric center.

      Returns AnchoredRect

    • Returns string

    • Compute the union of this rectangle with another rectangle.

      Parameters

      Returns Rect

    • Compute the union of this rectangle with another rectangle.

      Parameters

      • other: { height: number; left: number; top: number; width: number }

      Returns Rect

    • Create a rectangle centered at the given point.

      Parameters

      • cx: number

        Center x-coordinate

      • cy: number

        Center y-coordinate

      • width: number

        Rectangle width

      • height: number

        Rectangle height

      Returns Rect

    • Create the smallest rectangle enclosing two points.

      Parameters

      • p1: { x: number; y: number }
      • p2: { x: number; y: number }

      Returns Rect