Bounds
class Bounds
a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
Constructor
Summary
Properties from Bounds
Methods from Bounds
|
|
|
|
|
|
|
|
|
|
reset the bound |
|
Bounds |
|
boolean |
|
boolean |
|
boolean |
|
|
|
|
|
Polygon |
|
|
|
|
Public Properties
Public Methods
add(vertices: Array<Vector2d> | Array<Point>, clear: boolean) → {}
add the given vertices to the bounds definition.
addBounds(bounds: Bounds, clear: boolean) → {}
add the given bounds to the bounds definition.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bounds | Bounds | |||
clear | boolean |
<optional> |
false |
either to reset the bounds before adding the new vertices |
addFrame(x0: number, y0: number, x1: number, y1: number, m: Matrix2d) → {}
add the given quad coordinates to this bound definition, multiplied by the given matrix
Name | Type | Attributes | Description |
---|---|---|---|
x0 | number |
left X coordinates of the quad |
|
y0 | number |
top Y coordinates of the quad |
|
x1 | number |
right X coordinates of the quad |
|
y1 | number |
bottom y coordinates of the quad |
|
m | Matrix2d |
<optional> |
an optional transform to apply to the given frame coordinates |
addPoint(point: Vector2d | Point, m: Matrix2d) → {}
add the given point to the bounds definition.
centerOn(x: number, y: number) → {}
center the bounds position around the given coordinates
Name | Type | Description |
---|---|---|
x | number |
the x coordinate around which to center this bounds |
y | number |
the y coordinate around which to center this bounds |
contains(x: number | Vector2d, y: number) → {boolean}
Returns true if the bounds contains the given point.
if (bounds.contains(10, 10)) {
// do something
}
// or
if (bounds.contains(myVector2d)) {
// do something
}
Name | Type | Attributes | Description |
---|---|---|---|
x | number | Vector2d |
x coordinate or a vector point to check |
|
y | number |
<optional> |
y coordinate |
Type | Description |
---|---|
boolean |
True if the bounds contain the point, otherwise false |
isFinite() → {boolean}
determines whether all coordinates of this bounds are finite numbers.
Type | Description |
---|---|
boolean |
false if all coordinates are positive or negative Infinity or NaN; otherwise, true. |
overlaps(bounds: Bounds | Rect) → {boolean}
Returns true if the two bounds intersect.
Type | Description |
---|---|
boolean |
True if the bounds overlap, otherwise false |
setMinMax(minX: number, minY: number, maxX: number, maxY: number) → {}
sets the bounds to the given min and max value
Name | Type | Description |
---|---|---|
minX | number | |
minY | number | |
maxX | number | |
maxY | number |
shift(x: number | Vector2d, y: number) → {}
Shifts the bounds to the given x, y position.
bounds.shift(10, 10);
// or
bounds.shift(myVector2d);
Name | Type | Attributes | Description |
---|---|---|---|
x | number | Vector2d |
x coordinate or a vector point to shift to |
|
y | number |
<optional> |
toPolygon() → {Polygon}
Returns a polygon whose edges are the same as this bounds.
Type | Description |
---|---|
Polygon |
a new Polygon that represents this bounds. |
translate(x: number | Vector2d, y: number) → {}
Translates the bounds by the given point
bounds.translate(10, 10);
// or
bounds.translate(myVector2d);
Name | Type | Attributes | Description |
---|---|---|---|
x | number | Vector2d |
x coordinate or a vector point to translate by |
|
y | number |
<optional> |
update(vertices: Array<Vector2d> | Array<Point>) → {}
Updates bounds using the given vertices