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

    Class AnchoredRect

    Mutable axis-aligned rectangle with an explicit anchor point.

    The rectangle is defined by its edges (left, top, right, bottom) and an independent anchor (anchorX, anchorY) that acts as a logical pivot for scaling, sectioning, and layout operations.

    The anchor does not need to lie at the geometric center of the rectangle.

    All coordinates use the same coordinate space and orientation (top ≤ bottom, left ≤ right).

    Index

    Constructors

    • Create an empty rectangle at the origin. All edges and anchor coordinates are set to zero.

      Returns AnchoredRect

    • Create a rectangle from { left, top, width, height }. The anchor is placed at the geometric center.

      Parameters

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

      Returns AnchoredRect

    • Create a deep copy of another AnchoredRect.

      Parameters

      Returns AnchoredRect

    • Create a rectangle from edge coordinates. The anchor is placed at the geometric center.

      Parameters

      • left: number

        Left edge

      • right: number

        Right edge

      • top: number

        Top edge

      • bottom: number

        Bottom edge

      Returns AnchoredRect

    • Create a rectangle with explicit edge and anchor coordinates.

      Parameters

      • left: number

        Left edge

      • anchorX: number

        Anchor x-coordinate

      • right: number

        Right edge

      • top: number

        Top edge

      • anchorY: number

        Anchor y-coordinate

      • bottom: number

        Bottom edge

      Returns AnchoredRect

    Properties

    anchorX: number
    anchorY: number
    bottom: number
    left: number
    right: number
    top: number

    Accessors

    • get bottomh(): number

      Distance from anchor to bottom edge.

      Returns number

    • get centerX(): number

      Geometric center x-coordinate (ignores anchor).

      Returns number

    • get centerY(): number

      Geometric center y-coordinate (ignores anchor).

      Returns number

    • get height(): number

      Rectangle height (bottom - top).

      Returns number

    • get leftw(): number

      Distance from left edge to anchor.

      Returns number

    • get rightw(): number

      Distance from anchor to right edge.

      Returns number

    • get toph(): number

      Distance from top edge to anchor.

      Returns number

    • get width(): number

      Rectangle width (right - left).

      Returns number

    Methods

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

      Parameters

      • x: number
      • y: number

      Returns boolean

    • Test if this rect equals with given rect.

      Parameters

      Returns boolean

    • Test if edges of this equal with given Rect, ignoring anchorX and anchorY.

      Parameters

      Returns boolean

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

      The rectangle edges are moved outward by the given amounts. The anchor position is preserved.

      Parameters

      • dx: number

        Horizontal expansion applied to left and right edges.

      • dy: number = dx

        Vertical expansion applied to top and bottom edges. Defaults to dx.

      Returns AnchoredRect

      A new AnchoredRect expanded on all sides.

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

      The rectangle edges are moved inward by the given amounts. The anchor position is preserved.

      Parameters

      • dx: number

        Horizontal inset applied to left and right edges.

      • dy: number = dx

        Vertical inset applied to top and bottom edges. Defaults to dx.

      Returns AnchoredRect

      A new AnchoredRect inset from all sides.

    • Test whether this rectangle intersects another rectangle.

      Edge-touching is considered an intersection. Accepts either an AnchoredRect or a rect-like object with { left, top, width, height }.

      Parameters

      Returns boolean

    • Test whether this rectangle intersects another rectangle.

      Edge-touching is considered an intersection. Accepts either an AnchoredRect or a rect-like object with { left, top, width, height }.

      Parameters

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

      Returns boolean

    • Move this rect by (dx, dy).

      Parameters

      • dx: number

        Offset amount in x-direction.

      • dy: number

        Offset amount in y-direction.

      Returns AnchoredRect

      • Copy with applied offset.
    • Move this rect by (dx, dy).

      Parameters

      • dx: number

        Offset amount in x-direction.

      • dy: number

        Offset amount in y-direction.

      Returns AnchoredRect

      • Modified this.
    • Scale Rect. Anchor pos is (anchorX, anchorY). Immutable, returns modified copy.

      Parameters

      • scaleX: number

        Scale x-amount.

      • scaleY: number = scaleX

        Scale y-amount. If undefined then scale x-amount is used.

      Returns AnchoredRect

      Scaled copy of this AnchoredRect.

    • Scale this rectangle around its anchor point. Edges are moved relative to the anchor.

      Parameters

      • scaleX: number
      • scaleY: number = scaleX

      Returns AnchoredRect

    • Reset this rectangle to the origin. All edges and anchor coordinates are set to zero.

      Returns AnchoredRect

    • Set rectangle edges. The anchor is repositioned to the geometric center.

      Parameters

      • left: number
      • right: number
      • top: number
      • bottom: number

      Returns AnchoredRect

    • Set rectangle edges and anchor explicitly.

      Parameters

      • left: number
      • anchorX: number
      • right: number
      • top: number
      • anchorY: number
      • bottom: number

      Returns AnchoredRect

    • Convert to a basic Rect using geometric edges. Anchor information is discarded.

      Returns Rect

    • String of this rect.

      Returns string

    • Create rect from basic left, top, width and height arguments.

      Parameters

      • left: number

        Left coordinate.

      • top: number

        Top coordinate.

      • width: number

        Width.

      • height: number

        Height.

      Returns AnchoredRect

      • AnchoredRect.
    • Create rect from anchorX, anchorY, width, height arguments.

      Parameters

      • centerX: number

        Center x-coordinate.

      • centerY: number

        Center y-coordinate.

      • width: number

        Width.

      • height: number

        Height.

      Returns AnchoredRect

      • AnchoredRect.
    • Create rect from sections.

      Parameters

      • leftw: number

        Left section width.

      • rightw: number

        Right section width.

      • toph: number

        Top section height.

      • bottomh: number

        Bottomsection height.

      Returns AnchoredRect

      • AnchoredRect.
    • Test if edges of given rects are equal, ignoring anchorX and anchorY.

      Parameters

      Returns boolean