Skip to main content

Aabb

Struct Aabb 

Source
pub struct Aabb<T, I> {
    min: T,
    max: T,
    p: PhantomData<I>,
}
Expand description

Generic axis-aligned bounding box.

T is the vector type (e.g. DVec3 or IVec3) and I is a marker that differentiates coordinate spaces (block-local, world, structure).

Fields§

§min: T

Minimum corner of the box.

§max: T

Maximum corner of the box.

§p: PhantomData<I>

Implementations§

Source§

impl<T: AabbVector, I> Aabb<T, I>

Source

pub fn min(&self, axis: Axis) -> T::Scalar

Returns the minimum coordinate on axis.

Source

pub fn max(&self, axis: Axis) -> T::Scalar

Returns the maximum coordinate on axis.

Source

pub fn from_min_max(min: T, max: T) -> Self

Creates an AABB ensuring min <= max on every axis.

Source

pub fn translate(self, delta: T) -> Self

Translates the box by a vector.

Source

pub fn inflate(self, amount: T::Scalar) -> Self

Expands the box in every direction by amount.

Source

pub fn inflate_xyz(self, x: T::Scalar, y: T::Scalar, z: T::Scalar) -> Self

Expands the box independently on each axis.

Source

pub fn encapsulating(a: &Self, b: &Self) -> Self

Returns the smallest AABB that contains both a and b.

Source§

impl<I> Aabb<DVec3, I>

Source

pub const fn min_corner(&self) -> DVec3

Returns the minimum corner.

Source

pub const fn max_corner(&self) -> DVec3

Returns the maximum corner.

Source

pub const fn min_x(&self) -> f64

Returns the minimum X coordinate.

Source

pub const fn min_y(&self) -> f64

Returns the minimum Y coordinate.

Source

pub const fn min_z(&self) -> f64

Returns the minimum Z coordinate.

Source

pub const fn max_x(&self) -> f64

Returns the maximum X coordinate.

Source

pub const fn max_y(&self) -> f64

Returns the maximum Y coordinate.

Source

pub const fn max_z(&self) -> f64

Returns the maximum Z coordinate.

Source

pub fn distance_to_sqr(self, point: DVec3) -> f64

Returns the squared distance from point to this box.

Mirrors vanilla AABB.distanceToSqr.

Source

pub const fn closest_point_to(self, point: DVec3) -> DVec3

Returns the closest point inside this box to point.

Mirrors the per-box clamp used by vanilla VoxelShape.closestPointTo.

Source§

impl<I> Aabb<IVec3, I>

Source

pub const fn min_corner(&self) -> IVec3

Returns the minimum corner.

Source

pub const fn max_corner(&self) -> IVec3

Returns the maximum corner.

Source

pub const fn min_x(&self) -> i32

Returns the minimum X coordinate.

Source

pub const fn min_y(&self) -> i32

Returns the minimum Y coordinate.

Source

pub const fn min_z(&self) -> i32

Returns the minimum Z coordinate.

Source

pub const fn max_x(&self) -> i32

Returns the maximum X coordinate.

Source

pub const fn max_y(&self) -> i32

Returns the maximum Y coordinate.

Source

pub const fn max_z(&self) -> i32

Returns the maximum Z coordinate.

Source§

impl<T: AabbVector, I> Aabb<T, I>

Source

pub fn deflate(self, amount: T::Scalar) -> Self

Shrinks the box by amount in every direction.

Source§

impl<T: AabbVector, I: Space> Aabb<T, I>

Source

fn axis_overlaps( min1: T::Scalar, max1: T::Scalar, min2: T::Scalar, max2: T::Scalar, ) -> bool

Source

fn axis_contains(min: T::Scalar, max: T::Scalar, v: T::Scalar) -> bool

Source

pub fn is_empty(&self) -> bool

Returns true when this box has no positive volume on at least one axis.

Source

pub fn intersects(self, other: Self) -> bool

Returns whether this bounding box intersects another.

Source

pub fn intersects_bounds(self, min: T, max: T) -> bool

Returns true if this box intersects the given bounds.

Source

pub fn intersects_xz( self, min_x: T::Scalar, min_z: T::Scalar, max_x: T::Scalar, max_z: T::Scalar, ) -> bool

Returns whether this bounding box intersects the given XZ range.

Source

pub fn contains(self, pos: T) -> bool

Returns whether the given coordinates are inside this bounding box.

Source

pub fn contains_xyz(self, x: T::Scalar, y: T::Scalar, z: T::Scalar) -> bool

Returns whether the given coordinates are inside this bounding box.

Source§

impl<T: AabbVector, I: Space> Aabb<T, I>

Source

fn span(raw: T::Scalar) -> T::Scalar

Source

pub fn width(&self) -> T::Scalar

Get the width of bounding box (X Span)

Source

pub fn height(&self) -> T::Scalar

Get the height of bounding box (Y Span)

Source

pub fn depth(&self) -> T::Scalar

Get the depth of bounding box (Z Span)

Source

pub fn center(&self) -> T

Returns the center point of the bounding box.

Source§

impl<I: Space> Aabb<IVec3, I>

Source

pub fn contains_blockpos(self, pos: BlockPos) -> bool

Returns whether the given coordinates are inside this bounding box.

Source§

impl<I: Space> Aabb<DVec3, I>

Source

pub const FULL_BLOCK: Self

A full block from (0, 0, 0) to (1, 1, 1).

Source

pub const EMPTY: Self

A zero-volume box.

Source

pub const fn new( min_x: f64, min_y: f64, min_z: f64, max_x: f64, max_y: f64, max_z: f64, ) -> Self

Creates an AABB and normalizes endpoint order like vanilla AABB.

Source

pub fn of_size(center: DVec3, size_x: f64, size_y: f64, size_z: f64) -> Self

Creates a box centered at center with the supplied side lengths.

Vanilla equivalent: AABB.ofSize(center, sizeX, sizeY, sizeZ).

Source

pub fn size(self) -> f64

Vanilla equivalent: AABB.getSize().

Source§

impl Aabb<DVec3, BlockLocal>

Source

pub fn at_block(self, pos: BlockPos) -> Aabb<DVec3, World>

Converts this block-local box to a world-space box at pos.

Source§

impl Aabb<DVec3, World>

Source

pub fn entity_box(x: f64, y: f64, z: f64, half_width: f64, height: f64) -> Self

Creates an entity bounding box centered on X/Z and using y as feet.

Source

pub fn expand_towards(self, delta: DVec3) -> Self

Expands the box only in the direction of delta.

Source

pub fn intersects_block(self, pos: BlockPos) -> bool

Returns true if this box intersects the full block at pos.

Source§

impl Aabb<IVec3, Structure>

Source

pub const fn new(pos1: IVec3, pos2: IVec3) -> Self

Creates a new bounding box, normalizing so min <= max on each axis.

Source

pub const fn from_corners(a: BlockPos, b: BlockPos) -> Self

Creates a bounding box from two corner block positions.

Source

pub fn distance_to_sqr(self, point: DVec3) -> f64

Returns the squared distance from point to this box.

Mirrors vanilla AABB.distanceToSqr.

Trait Implementations§

Source§

impl<T: Clone, I: Clone> Clone for Aabb<T, I>

Source§

fn clone(&self) -> Aabb<T, I>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Copy, I: Copy> Copy for Aabb<T, I>

Source§

impl<T: Debug, I: Debug> Debug for Aabb<T, I>

Source§

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

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

impl<T: Eq, I: Eq> Eq for Aabb<T, I>

Source§

impl<T: Hash, I: Hash> Hash for Aabb<T, I>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq, I: PartialEq> PartialEq for Aabb<T, I>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq, I: PartialEq> StructuralPartialEq for Aabb<T, I>

Auto Trait Implementations§

§

impl<T, I> Freeze for Aabb<T, I>
where T: Freeze,

§

impl<T, I> RefUnwindSafe for Aabb<T, I>

§

impl<T, I> Send for Aabb<T, I>
where T: Send, I: Send,

§

impl<T, I> Sync for Aabb<T, I>
where T: Sync, I: Sync,

§

impl<T, I> Unpin for Aabb<T, I>
where T: Unpin, I: Unpin,

§

impl<T, I> UnsafeUnpin for Aabb<T, I>
where T: UnsafeUnpin,

§

impl<T, I> UnwindSafe for Aabb<T, I>
where T: UnwindSafe, I: UnwindSafe,

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Shared<Self>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more