Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Rectangle

Rectangle class provides static functions to create and operate on rectangles. A rectangle is usually represented as a Group of 2 Pts, marking the top-left and bottom-right corners of the rectangle. You can use the static function as-is, or apply the op method in Group or Pt to many of these functions. See Op guide for details.

Hierarchy

  • Rectangle

Index

Methods

Static boundingBox

  • Given an array of rectangles, get a rectangle that bounds all of them

    Parameters

    • rects: GroupLike[]

      an array of Groups that represent rectangles

    Returns Group

    the bounding rectangle as a Group

Static center

  • Get the center of this rectangle

    Parameters

    • pts: GroupLike

      a Group of 2 Pts representing a Rectangle

    Returns Pt

Static corners

  • Get the 4 corners of this rectangle as a Group

    Parameters

    • rect: GroupLike

      a Group of 2 Pts representing a Rectangle

    Returns Group

Static from

  • from(topLeft: PtLike | number[], widthOrSize: number | PtLike, height?: number): Group
  • Same as Rectangle.fromTopLeft

    Parameters

    • topLeft: PtLike | number[]
    • widthOrSize: number | PtLike
    • Optional height: number

    Returns Group

Static fromCenter

  • fromCenter(center: PtLike | number[], widthOrSize: number | PtLike, height?: number): Group
  • Create a rectangle given a center position and a size

    Parameters

    • center: PtLike | number[]
    • widthOrSize: number | PtLike

      width as a number, or a Pt that defines its size

    • Optional height: number

      optional height as a number

    Returns Group

Static fromTopLeft

  • fromTopLeft(topLeft: PtLike | number[], widthOrSize: number | PtLike, height?: number): Group
  • Create a rectangle given a top-left position and a size

    Parameters

    • topLeft: PtLike | number[]

      top-left point

    • widthOrSize: number | PtLike

      width as a number, or a Pt that defines its size

    • Optional height: number

      optional height as a number

    Returns Group

Static hasIntersectRect2D

  • Check if a rectangle is within the bounds of another rectangle

    Parameters

    • rect1: GroupLike

      a Group of 2 Pts representing a rectangle

    • rect2: GroupLike

      a Group of 2 Pts representing a rectangle

    Returns boolean

Static intersectRect2D

  • Quick way to check rectangle intersection. For more optimized implementation, store the rectangle's sides separately (eg, Rectangle.sides()) and use Polygon.intersect2D().

    Parameters

    • rect1: GroupLike

      a Group of 2 Pts representing a rectangle

    • rect2: GroupLike

      a Group of 2 Pts representing a rectangle

    Returns Group

Static lines

Static polygon

  • Convert this rectangle into a Group representing a polygon

    Parameters

    • rect: GroupLike

      a Group of 2 Pts representing a Rectangle

    Returns Group

Static quadrants

  • Subdivide this rectangle into 4 rectangles, one for each quadrant

    Parameters

    • rect: GroupLike

      a Group of 2 Pts representing a Rectangle

    • Optional center: PtLike

    Returns Group[]

    an array of 4 Groups

Static sides

  • Get the 4 sides of this rectangle as an array of 4 Groups

    Parameters

    • rect: GroupLike

      a Group of 2 Pts representing a Rectangle

    Returns Group[]

    an array of 4 Groups, each of which represents a line segment

Static size

  • Get the size of this rectangle as a Pt

    Parameters

    • pts: GroupLike

      a Group of 2 Pts representing a Rectangle

    Returns Pt

Static toCircle

  • Convert this rectangle to a circle that fits within the rectangle

    see

    Circle

    Parameters

    Returns Group

    a Group that represents a circle

Static toSquare

  • Create a square that either fits within or encloses a rectangle

    Parameters

    • pts: GroupLike

      a Group of 2 Pts representing a rectangle

    • Default value enclose: boolean = false

      if true, the square will enclose the rectangle. Default is false, which will fit the square inside the rectangle.

    Returns Group

Static withinBound

  • Check if a point is within a rectangle

    Parameters

    • rect: GroupLike

      a Group of 2 Pts representing a Rectangle

    • pt: PtLike

      the point to check

    Returns boolean

Generated using TypeDoc