Class: Box2
Represents a box in 2D space. Needing two Vec2 vectors describing the corners
#
Constructors#
constructor• new Box2(p0?
, p1?
)
Creates a Box2 object using Vec2s. In case the parameters are not passed by, their values are pre-defined:
p0 is a Vec2 with Number.POSITIVE_INFINITY
p1 is a Vec2 with Number.NEGATIVE_INFINITY
#
ParametersName | Type | Description |
---|---|---|
p0? | Vec2 | A point representing the corners of a 2D box. |
p1? | Vec2 | A point representing the corners of a 2D box. |
#
Defined in#
Properties#
p0• p0: Vec2
#
Defined in#
p1• p1: Vec2
#
Defined in#
Methods#
addPoint▸ addPoint(point
): void
Expands the Box2 to contain the new point.
#
ParametersName | Type | Description |
---|---|---|
point | Vec2 | A point represents the corners of a 2D box. |
#
Returnsvoid
#
Defined in#
center▸ center(): Vec2
Returns the center point of a Box2.
#
Returns- Returns a Vec2.
#
Defined in#
clone▸ clone(): Box2
Clones this Vec2 and returns a new Vec2.
#
Returns- Returns a new Vec2.
#
Defined in#
diagonal▸ diagonal(): Vec2
Returns the size of a Box2 - the same as size().
#
Returns- Returns a Vec2.
#
Defined in#
isValid▸ isValid(): boolean
Returns true
if the box has been expanded to contain a point.
#
Returnsboolean
- The return value.
#
Defined in#
reset▸ reset(): void
Resets the box2 back to an uninitialized state.
see
Number.POSITIVE_INFINITY
and Number.NEGATIVE_INFINITY
#
Returnsvoid
#
Defined in#
set▸ set(p0
, p1
): void
Sets both Vec2 points
#
ParametersName | Type | Description |
---|---|---|
p0 | Vec2 | A point representing the corners of a 2D box. |
p1 | Vec2 | A point representing the corners of a 2D box. |
#
Returnsvoid
#
Defined in#
size▸ size(): number
Returns the length of the diagonal of the box.
#
Returnsnumber
- Returns the distance.
#
Defined in#
toJSON▸ toJSON(): Record
<string
, Record
<string
, number
>>
Encodes Box2
Class as a JSON object for persistence.
#
ReturnsRecord
<string
, Record
<string
, number
>>
- The json object.
#
Defined in#
toString▸ toString(): string
Calls toJSON
method and stringifies it.
#
Returnsstring
- The return value.