Rect

class Rect extends Polygon

a rectangle Object

Constructor


new Rect(x: number, y: number, w: number, h: number) → {}
Parameters:
Name Type Description
x number

position of the Rectangle

y number

position of the Rectangle

w number

width of the rectangle

h number

height of the rectangle

Public Properties


bottom rectangle.js:89
bottom: number

number

bottom coordinate of the Rectangle

centerX rectangle.js:124
centerX: number

number

absolute center of this rectangle on the horizontal axis

centerY rectangle.js:141
centerY: number

number

absolute center of this rectangle on the vertical axis

height rectangle.js:111
height: number

number

height of the Rectangle

left rectangle.js:64
left: number

number

left coordinate of the Rectangle

top rectangle.js:81
top: number

number

top coordinate of the Rectangle

type rectangle.js:25
type: string = "Rectangle"

string

the shape type (used internally)

width rectangle.js:98
width: number

number

width of the Rectangle

Public Methods


centerOn rectangle.js:158
centerOn(x: number, y: number) → {Rect}

center the rectangle position around the given coordinates

Parameters:
Name Type Description
x number

the x coordinate around which to center this rectangle

y number

the y coordinate around which to center this rectangle

Returns:
Type Description
Rect

this rectangle

clone rectangle.js:194
clone() → {Rect}

clone this rectangle

Returns:
Type Description
Rect

new rectangle

contains rectangle.js:244
contains(x: number | Vector2d | Rect, y: number) → {boolean}

Returns true if the rectangle contains the given point or rectangle

if (rect.contains(10, 10)) {
  // do something
}
// or
if (rect.contains(myVector2d)) {
  // do something
}
if (rect.contains(myRect)) {
  // do something
}
Parameters:
Name Type Attributes Description
x number | Vector2d | Rect

x coordinate or a vector point, or a rectangle to test

y number

<optional>

y coordinate

Returns:
Type Description
boolean

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

copy rectangle.js:202
copy(rect: Rect) → {Rect}

copy the position and size of the given rectangle into this one

Parameters:
Name Type Description
rect Rect

Source rectangle

Returns:
Type Description
Rect

new rectangle

equals rectangle.js:290
equals(rect: Rect) → {boolean}

check if this rectangle is identical to the specified one

Parameters:
Name Type Description
rect Rect
Returns:
Type Description
boolean

true if equals

isFinite rectangle.js:304
isFinite() → {boolean}

determines whether all coordinates of this rectangle are finite numbers.

Returns:
Type Description
boolean

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

overlaps rectangle.js:230
overlaps(rect: Rect) → {boolean}

check if this rectangle is intersecting with the specified one

Parameters:
Name Type Description
rect Rect
Returns:
Type Description
boolean

true if overlaps

resize rectangle.js:170
resize(w: number, h: number) → {Rect}

resize the rectangle

Parameters:
Name Type Description
w number

new width of the rectangle

h number

new height of the rectangle

Returns:
Type Description
Rect

this rectangle

scale rectangle.js:182
scale(x: number, y: number) → {Rect}

scale the rectangle

Parameters:
Name Type Attributes Default Description
x number

a number representing the abscissa of the scaling vector.

y number

<optional>

x

a number representing the ordinate of the scaling vector.

Returns:
Type Description
Rect

this rectangle

setShape rectangle.js:38
setShape(x: number, y: number, w: number | Vector2d<Array>, h: number) → {Rect}

set new value to the rectangle shape

Parameters:
Name Type Attributes Description
x number

position of the Rectangle

y number

position of the Rectangle

w number | Vector2d<Array>

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

h number

<optional>

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

Returns:
Type Description
Rect

this rectangle

toPolygon rectangle.js:312
toPolygon() → {Polygon}

Returns a polygon whose edges are the same as this box.

Returns:
Type Description
Polygon

a new Polygon that represents this rectangle.

union rectangle.js:211
union(rect: Rect) → {Rect}

merge this rectangle with another one

Parameters:
Name Type Description
rect Rect

other rectangle to union with

Returns:
Type Description
Rect

the union(ed) rectangle


Powered by webdoc!