godot::prelude

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

§All bounding-box types

DimensionFloating-pointInteger
2DRect2Rect2i
3DAabb

§Godot docs

AABB

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 contains_point(self, point: Vector3) -> bool

Returns true if the AABB contains a point (excluding right/bottom edge).

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_point(self, point: Vector3) -> bool

👎Deprecated: Renamed to contains_point(), for consistency with Rect2i

pub fn has_surface(self) -> bool

Returns if this bounding box has a surface or a length, i.e. at least one component of Self::size is greater than 0.

pub fn has_area(self) -> bool

👎Deprecated: Replaced with has_surface(), which has different semantics

Returns true if at least one of the size’s components (X, Y, Z) is greater than 0.

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 intersect(self, b: Aabb) -> Option<Aabb>

Returns the intersection between two AABBs.

§Panics (Debug)

If self.size is negative.

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

👎Deprecated: Renamed to intersect()

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, ray_from: Vector3, ray_dir: Vector3) -> bool

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

Semantically equivalent to self.intersects_ray(ray_from, ray_dir).is_some(); might be microscopically faster.

§Panics (Debug)

If self.size is negative.

pub fn intersect_ray( self, ray_from: Vector3, ray_dir: Vector3, ) -> Option<Vector3>

Returns the point where the given (infinite) ray intersects with this AABB, or None if there is no intersection.

§Panics (Debug)

If self.size is negative, or if ray_dir is zero. Note that this differs from Godot, which treats rays that degenerate to points as intersecting if inside, and not if outside the AABB.

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. TODO(v0.3): make private, change to debug_assert().

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 export_hint() -> 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 ParamType for Aabb

§

fn owned_to_arg<'v>(self) -> <Aabb as ParamType>::Arg<'v>

Converts an owned value to the canonical argument type, which can be passed to impl AsArg<T>. Read more
§

impl PartialEq for Aabb

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl ToGodot for Aabb

§

type ToVia<'v> = <Aabb as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
§

fn to_godot(&self) -> <Aabb as ToGodot>::ToVia<'_>

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

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl Var for Aabb

§

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

§

fn set_property(&mut self, value: <Aabb as GodotConvert>::Via)

§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
§

impl ArrayElement for Aabb

§

impl AsArg<Aabb> 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§

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

🔬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,

Source§

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§

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>,

Source§

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>,

Source§

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.