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 halves

  • Subdivde a rectangle into 2 rectangles, by row or by column

    Parameters

    • rect: GroupLike

      Group of 2 Pts representing a Rectangle

    • Default value ratio: number = 0.5

      a value between 0 to 1 to indicate the split ratio

    • Default value asRows: boolean = false

      if true, split into 2 rows. Default is false which splits into 2 columns.

    Returns Group[]

    an array of 2 Groups of rectangles

Static hasIntersectRect2D

  • hasIntersectRect2D(rect1: GroupLike, rect2: GroupLike, resetBoundingBox?: boolean): boolean
  • 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

    • Default value resetBoundingBox: boolean = false

      if true, reset the bounding box. Default is false which assumes the rect's first Pt at is its top-left corner.

    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.intersectPolygon2D().

    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 a 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 of rectangles

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