Class Rect

a rectangle Object

Hierarchy (view full)

Constructors

Properties

_bounds: undefined | object
points: Vector2d[]

Array of points defining the Polygon
Note: If you manually change points, you must call recalcafterwards so that the changes get applied correctly.

origin point of the Polygon

type: string

the shape type (used internally)

"Polygon"

Accessors

Methods

  • center the rectangle position around the given coordinates

    Parameters

    • x: number

      the x coordinate around which to center this rectangle

    • y: number

      the y coordinate around which to center this rectangle

    Returns Rect

    this rectangle

  • Returns true if the rectangle contains the given point or rectangle

    Parameters

    • Rest...args: any

    Returns boolean

    True if the rectangle contain the given point or rectangle, otherwise false

    if (rect.contains(10, 10)) {
    // do something
    }
    // or
    if (rect.contains(myVector2d)) {
    // do something
    }
    if (rect.contains(myRect)) {
    // do something
    }
  • returns a list of indices for all triangles defined in this polygon

    Returns number[]

    an array of vertex indices for all triangles forming this polygon.

  • Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).

    Returns boolean

    true if the vertices are convex, false if not, null if not computable

  • determines whether all coordinates of this rectangle are finite numbers.

    Returns boolean

    false if all coordinates are positive or negative Infinity or NaN; otherwise, true.

  • check if this rectangle is intersecting with the specified one

    Parameters

    Returns boolean

    true if overlaps

  • Computes the calculated collision polygon. This must be called if the points array, angle, or offset is modified manually.

    Returns Polygon

    Reference to this object for method chaining

  • scale the rectangle

    Parameters

    • x: number

      a number representing the abscissa of the scaling vector.

    • Optionaly: number = x

      a number representing the ordinate of the scaling vector.

    Returns Rect

    this rectangle

  • set new value to the rectangle shape

    Parameters

    • x: number

      position of the Rectangle

    • y: number

      position of the Rectangle

    • w: number | Vector2d[]

      width of the rectangle, or an array of vector defining the rectangle

    • Optionalh: number

      height of the rectangle, if a numeral width parameter is specified

    • Rest...args: any

    Returns Rect

    this rectangle

  • Shifts the Polygon to the given position vector.

    Parameters

    • Rest...args: any

    Returns void

    polygon.shift(10, 10);
    // or
    polygon.shift(myVector2d);
  • translate the Polygon by the specified offset

    Parameters

    • Rest...args: any

    Returns Polygon

    Reference to this object for method chaining

    polygon.translate(10, 10);
    // or
    polygon.translate(myVector2d);