Rect
class Rect extends Polygon
a rectangle Object
Constructor
new Rect(x: number, y: number, w: number, h: number) → {}
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 |
Summary
Properties from Rect
Methods from Rect
Rect |
|
Rect |
|
boolean |
|
Rect |
|
boolean |
|
boolean |
|
boolean |
|
Rect |
|
Rect |
|
Rect |
|
Polygon |
|
Rect |
|
Methods inherited from Polygon
Bounds |
|
Array<number> |
|
boolean |
|
Polygon |
|
Polygon |
|
Polygon |
|
Polygon |
|
|
|
Polygon |
|
Polygon |
|
Polygon |
|
Polygon |
|
Bounds |
|
Public Properties
centerX: number
number
absolute center of this rectangle on the horizontal axis
centerY: number
number
absolute center of this rectangle on the vertical axis
Public Methods
centerOn(x: number, y: number) → {Rect}
center the rectangle position around the given coordinates
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 |
Type | Description |
---|---|
Rect |
this rectangle |
clone() → {Rect}
clone this rectangle
Type | Description |
---|---|
Rect |
new rectangle |
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
}
Name | Type | Attributes | Description |
---|---|---|---|
x | number | Vector2d | Rect |
x coordinate or a vector point, or a rectangle to test |
|
y | number |
<optional> |
y coordinate |
Type | Description |
---|---|
boolean |
True if the rectangle contain the given point or rectangle, otherwise false |
copy(rect: Rect) → {Rect}
copy the position and size of the given rectangle into this one
Name | Type | Description |
---|---|---|
rect | Rect |
Source rectangle |
Type | Description |
---|---|
Rect |
new rectangle |
equals(rect: Rect) → {boolean}
check if this rectangle is identical to the specified one
Name | Type | Description |
---|---|---|
rect | Rect |
Type | Description |
---|---|
boolean |
true if equals |
isFinite() → {boolean}
determines whether all coordinates of this rectangle are finite numbers.
Type | Description |
---|---|
boolean |
false if all coordinates are positive or negative Infinity or NaN; otherwise, true. |
overlaps(rect: Rect) → {boolean}
check if this rectangle is intersecting with the specified one
Name | Type | Description |
---|---|---|
rect | Rect |
Type | Description |
---|---|
boolean |
true if overlaps |
resize(w: number, h: number) → {Rect}
resize the rectangle
Name | Type | Description |
---|---|---|
w | number |
new width of the rectangle |
h | number |
new height of the rectangle |
Type | Description |
---|---|
Rect |
this rectangle |
scale(x: number, y: number) → {Rect}
scale the rectangle
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. |
Type | Description |
---|---|
Rect |
this rectangle |
setShape(x: number, y: number, w: number | Vector2d<Array>, h: number) → {Rect}
set new value to the rectangle shape
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 |
Type | Description |
---|---|
Rect |
this rectangle |
toPolygon() → {Polygon}
Returns a polygon whose edges are the same as this box.
Type | Description |
---|---|
Polygon |
a new Polygon that represents this rectangle. |
union(rect: Rect) → {Rect}
merge this rectangle with another one
Name | Type | Description |
---|---|---|
rect | Rect |
other rectangle to union with |
Type | Description |
---|---|
Rect |
the union(ed) rectangle |