#[repr(C)]
pub struct Aabb { pub position: Vector3, pub size: Vector3, }
Expand description

Axis-aligned bounding box.

Aabb consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

The 2D counterpart to Aabb is Rect2.

Fields

position: Vector3

The bounding box’s position in 3D space.

size: Vector3

Width, height, and depth of the bounding box.

Implementations

Creates an Aabb by position and size.

Note that while size components are allowed to be negative, they can lead to unintuitive results. It is recommended to use abs on such AABBs.

Ending corner. This is calculated as position + size.

Ending corner. Setting this value will change the size.

Returns an Aabb with equivalent position and area, modified so that the most-negative corner is the origin and the size is positive.

Returns the volume of the bounding box. See also has_no_volume.

This method corresponds to the get_area GDScript method.

Returns true if the bounding box is flat or empty. See also volume.

This method corresponds to the has_no_area GDScript method.

Note: If the bounding box has a negative size and is not flat or empty, this method will return true.

Returns true if the bounding box is empty or all of its dimensions are negative.

Returns true if the bounding box contains a point. By convention, the right and bottom edges of the Rect2 are considered exclusive, so points on these edges are not included.

Note: This method is not reliable for bounding boxes with a negative size. Use abs to get a positive sized equivalent box to check for contained points.

Returns true if this bounding box and b are approximately equal, by calling is_equal_approx on each component.

Gets the position of the 8 endpoints of the bounding box in space.

The index returns an arbitrary point, but all points are guaranteed to be unique.

Returns the longest side of this AABB as an axis index and its length.

If multiple axes have the same length, then the first in order X, Y, Z is returned.
To get the unit vector along the axis, use Axis::to_unit_vector().

If you want to emulate the separate GDScript methods, you can do this:

let (index, size) = aabb.longest_axis();
let axis = index.to_unit_vector();

Returns the shortest side of this AABB as an axis index and its length.

If multiple axes have the same length, then the first in order X, Y, Z is returned.
To get the unit vector along the axis, use Axis::to_unit_vector().

If you want to emulate the separate GDScript methods, you can do this:

let (index, size) = aabb.shortest_axis();
let axis = index.to_unit_vector();

Returns the support point in a given direction. This is useful for collision detection algorithms.

The support point is a point on the boundary of the AABB, which is the furthest from the center in the given direction dir. In other words, when you cast a ray from the AABB’s center toward dir and intersect that with the AABB boundary, you will get the support point.

Mathematically, the support point corresponds to the point which maximizes its dot product with dir. See also 1 and 2 for more information.

Returns a copy of the bounding box, grown a given amount of units on all 6 sides.

It is possible to specify a negative amount to shrink the AABB (note that this can invert the AABB).

Returns true if the bounding box overlaps with b.

This excludes borders; if the intersection has no volume, false is returned.

Returns true if the bounding box is on both sides of a plane.

Returns true if the bounding box intersects the line segment between from and to.

Returns the intersection between two bounding boxes, or None if there is no intersection.

This excludes borders; if the intersection has no volume, None is returned.

Returns a larger bounding box that contains both this Aabb and b.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.