Box2
Class representing an axis-aligned bounding box (AABB) in 2D space. A Box2 represents a rectangular box in 2D space that is aligned with the world coordinate axes. It is defined by two Vector2 points: min (lower-left corner) and max (upper-right corner).
Methods
Box2()
Default constructor - creates an empty box
Box2(const Vector2& min, const Vector2& max)
Constructor with min and max vectors
| min | lower boundary of the box | (+∞, +∞) |
| max | upper boundary of the box | (-∞, -∞) |
Box2& set(const Vector2& min, const Vector2& max)
Sets the lower and upper boundaries of this box
| min | Vector2 representing the lower boundary | |
| max | Vector2 representing the upper boundary |
Box2& setFromCenterAndSize(const Vector2& center, const Vector2& size)
Centers this box on center and sets its dimensions
| center | desired center position of the box | |
| size | desired x and y dimensions of the box |
Box2& setFromPoints(const vector<Vector2>& points)
Sets the box to contain all points in the array
| points | array of Vector2s that the box will contain |
Box2 clone() const
Returns a new Box2 with the same min and max as this one
Box2& copy(const Box2& box)
Copies the min and max from box to this box
| box | Box2 to copy from |
Box2& makeEmpty()
Makes this box empty
bool isEmpty() const
Returns true if this box includes zero points within its bounds
Box2& expandByPoint(const Vector2& point)
Expands the boundaries of this box to include point
| point | Vector2 that should be included in the box |
Box2& expandByVector(const Vector2& vector)
Expands this box equilaterally by the given vector
| vector | Vector2 to expand the box by |
Box2& expandByScalar(f32 scalar)
Expands each dimension of the box by scalar
| scalar | distance to expand the box by |
bool containsPoint(const Vector2& point) const
Returns true if the specified point lies within or on the boundaries
| point | Vector2 to check for inclusion |
bool containsBox(const Box2& box) const
Returns true if this box includes the entirety of box
| box | Box2 to test for inclusion |
Vector2& clampPoint(const Vector2& point, Vector2& target) const
Clamps the given point within the bounds of this box
| point | Vector2 to clamp | |
| target | result will be copied into this Vector2 |
f32 distanceToPoint(const Vector2& point) const
Returns the euclidean distance from any edge of this box to the specified point
| point | Vector2 to measure distance to |
Box2& intersect(const Box2& box)
Computes the intersection of this and box
| box | Box to intersect with |
Box2& unionBox(const Box2& box)
Computes the union of this box and box
| box | Box that will be unioned with this box |
bool intersectsBox(const Box2& box) const
Determines whether or not this box intersects box
| box | Box to check for intersection against |
Box2& translate(const Vector2& offset)
Adds offset to both the upper and lower bounds of this box
| offset | direction and distance of offset |
Vector2& getCenter(Vector2& target) const
Returns the center point of the box as a Vector2
| target | result will be copied into this Vector2 |
Vector2& getSize(Vector2& target) const
Returns the width and height of this box
| target | result will be copied into this Vector2 |
Vector2& getParameter(const Vector2& point, Vector2& target) const
Returns a point as a proportion of this box's width and height
| point | Vector2 to get parameter for | |
| target | result will be copied into this Vector2 |
bool equals(const Box2& box) const
Returns true if this box and box share the same lower and upper bounds
| box | Box to compare with this one |
bool operator==(const Box2& box) const
Checks if this box equals another
| box | Box to compare with |
bool operator!=(const Box2& box) const
Checks if this box does not equal another
| box | Box to compare with |
Properties
| enabled | bool | Active/inactive |
| id | u32 | Unique identifier |
| isBox2 | bool | Read-only tag |
| max | Vector2 | upper boundary of the box |
| min | Vector2 | lower boundary of the box |
| name | string | Optional display name |
| uuid | string | UUID string |
| version | u32 | Bumps on change |