Struct godot::prelude::Aabb

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

Axis-aligned bounding box in 3D space.

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

Currently most methods are only available through InnerAabb.

The 2D counterpart to Aabb is Rect2.

Fields§

§position: Vector3§size: Vector3

Implementations§

§

impl Aabb

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

Create a new Aabb from a position and a size.

Godot equivalent: Aabb(Vector3 position, Vector3 size)

pub fn from_corners(position: Vector3, end: Vector3) -> Aabb

Create a new Aabb with the first corner at position and opposite corner at end.

pub fn abs(self) -> Aabb

Returns an AABB with the same geometry, with most-negative corner as position and non-negative size.

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

Whether self covers at least the entire area of b (and possibly more).

pub fn expand(self, to: Vector3) -> Aabb

Returns a copy of this AABB expanded to include a given point.

§Panics

If self.size is negative.

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

Returns a larger AABB that contains this AABB and b.

§Panics

If either self.size or b.size is negative.

pub fn volume(self) -> f32

Returns the volume of the AABB.

§Panics

If self.size is negative.

pub fn center(self) -> Vector3

Returns the center of the AABB, which is equal to position + (size / 2).

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

Returns a copy of the AABB grown by the specified amount on all sides.

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

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

§Panics

If self.size is negative.

pub fn has_area(self) -> bool

Returns true if the AABB has area, and false if the AABB is linear, empty, or has a negative size. See also Aabb.area().

pub fn has_volume(self) -> bool

Returns true if the AABB has a volume, and false if the AABB is flat, linear, empty, or has a negative size.

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

Returns the intersection between two AABBs.

§Panics

If self.size is negative.

pub fn is_finite(self) -> bool

Returns true if this AABB is finite, by calling @GlobalScope.is_finite on each component.

pub fn end(self) -> Vector3

The end of the Aabb calculated as position + size.

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

Set size based on desired end-point.

NOTE: This does not make the AABB absolute, and Aabb.abs() should be called if the size becomes negative.

pub fn longest_axis(self) -> Option<Vector3>

Returns the normalized longest axis of the AABB.

pub fn longest_axis_index(self) -> Option<Vector3Axis>

Returns the index of the longest axis of the AABB (according to Vector3’s AXIS_* constants).

pub fn longest_axis_size(self) -> f32

Returns the scalar length of the longest axis of the AABB.

pub fn shortest_axis(self) -> Option<Vector3>

Returns the normalized shortest axis of the AABB.

pub fn shortest_axis_index(self) -> Option<Vector3Axis>

Returns the index of the shortest axis of the AABB (according to Vector3::AXIS* enum).

pub fn shortest_axis_size(self) -> f32

Returns the scalar length of the shortest axis of the AABB.

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

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

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

Checks whether two AABBs have at least one point in common.

Also returns true if the AABBs only touch each other (share a point/edge/face). See intersects_exclude_borders if you want to return false in that case.

Godot equivalent: AABB.intersects(AABB b, bool include_borders = true)

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

Checks whether two AABBs have at least one inner point in common (not on the borders).

Returns false if the AABBs only touch each other (share a point/edge/face). See intersects if you want to return true in that case.

Godot equivalent: AABB.intersects(AABB b, bool include_borders = false)

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

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

pub fn intersects_ray(self, from: Vector3, dir: Vector3) -> bool

Returns true if the given ray intersects with this AABB. Ray length is infinite.

§Panics

If self.size is negative.

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

Returns true if the given ray intersects with this AABB. Segment length is finite.

§Panics

If self.size is negative.

pub fn assert_nonnegative(self)

Assert that the size of the Aabb is not negative.

Most functions will fail to give a correct result if the size is negative.

Trait Implementations§

§

impl ApproxEq for Aabb

§

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

Returns true if the two Aabbs are approximately equal, by calling is_equal_approx on position and size.

§

impl Clone for Aabb

§

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
§

impl Debug for Aabb

§

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

Formats the value using the given formatter. Read more
§

impl Default for Aabb

§

fn default() -> Aabb

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

impl Display for Aabb

§

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

Formats Aabb to match godot’s display style.

§Example
use godot::prelude::*;
let aabb = Aabb::new(Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 1.0, 1.0));
assert_eq!(format!("{}", aabb), "[P: (0, 0, 0), S: (1, 1, 1)]");
§

impl Export for Aabb

§

fn default_export_info() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
§

impl FromGodot for Aabb

§

fn try_from_godot( via: <Aabb as GodotConvert>::Via, ) -> Result<Aabb, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl GodotConvert for Aabb

§

type Via = Aabb

The type through which Self is represented in Godot.
§

impl Mul<Aabb> for Transform3D

§

fn mul(self, rhs: Aabb) -> <Transform3D as Mul<Aabb>>::Output

Transforms each coordinate in rhs.position and rhs.end() individually by this transform, then creates an Aabb containing all of them.

§

type Output = Aabb

The resulting type after applying the * operator.
§

impl PartialEq for Aabb

§

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

impl ToGodot for Aabb

§

fn to_godot(&self) -> <Aabb as GodotConvert>::Via

Converts this type to the Godot type by reference, usually by cloning.
§

fn into_godot(self) -> <Aabb as GodotConvert>::Via

Converts this type to the Godot type. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl TypeStringHint for Aabb

§

fn type_string() -> String

Returns the representation of this type as a type string. Read more
§

impl Var for Aabb

§

impl ArrayElement for Aabb

§

impl Copy for Aabb

§

impl GodotType for Aabb

§

impl StructuralPartialEq for Aabb

Auto Trait Implementations§

§

impl Freeze for Aabb

§

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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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> ToOwned for T
where 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.