Struct gdnative::core_types::Aabb

source ·
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§

source§

impl Aabb

source

pub fn new(position: Vector3, size: Vector3) -> Aabb

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.

source

pub fn end(self) -> Vector3

Ending corner. This is calculated as position + size.

source

pub fn set_end(&mut self, new_end: Vector3)

Ending corner. Setting this value will change the size.

source

pub fn abs(self) -> Aabb

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

source

pub fn volume(self) -> f32

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

This method corresponds to the get_area GDScript method.

source

pub fn has_no_volume(self) -> bool

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.

source

pub fn has_no_surface(self) -> bool

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

source

pub fn contains_point(self, point: Vector3) -> bool

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.

source

pub fn is_equal_approx(self, b: Aabb) -> bool

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

source

pub fn get_endpoint(self, index: usize) -> Option<Vector3>

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.

source

pub fn longest_axis(self) -> (Axis, f32)

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();
source

pub fn shortest_axis(self) -> (Axis, f32)

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();
source

pub fn get_support(self, dir: Vector3) -> Vector3

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.

source

pub fn grow(self, by: f32) -> Aabb

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).

source

pub fn intersects(self, b: Aabb) -> bool

Returns true if the bounding box overlaps with b.

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

source

pub fn intersects_plane(self, plane: Plane) -> bool

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

source

pub fn intersects_segment(self, from: Vector3, to: Vector3) -> bool

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

source

pub fn intersection(self, b: Aabb) -> Option<Aabb>

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.

source

pub fn merge(self, b: Aabb) -> Aabb

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

Trait Implementations§

source§

impl Clone for Aabb

source§

fn clone(&self) -> Aabb

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CoerceFromVariant for Aabb

source§

impl Debug for Aabb

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Aabb

source§

fn default() -> Aabb

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Aabb

source§

fn deserialize<__D>(
    __deserializer: __D
) -> Result<Aabb, <__D as Deserializer<'de>>::Error>where
    __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Export for Aabb

§

type Hint = NoHint

A type-specific hint type that is valid for the type being exported. Read more
source§

fn export_info(_hint: Option<<Aabb as Export>::Hint>) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

impl FromVariant for Aabb

source§

impl PartialEq<Aabb> for Aabb

source§

fn eq(&self, other: &Aabb) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Aabb

source§

fn serialize<__S>(
    &self,
    __serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl ToVariant for Aabb

source§

impl Copy for Aabb

source§

impl StructuralPartialEq for Aabb

Auto Trait Implementations§

§

impl RefUnwindSafe for Aabb

§

impl Send for Aabb

§

impl Sync for Aabb

§

impl Unpin for Aabb

§

impl UnwindSafe for Aabb

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> OwnedToVariant for Twhere
    T: ToVariant,

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere
    T: for<'de> Deserialize<'de>,