Skip to main content

BoxShape

Struct BoxShape 

Source
pub struct BoxShape {
    pub half_extents: Vec3,
}
Expand description

An axis-aligned box defined by half-extents.

Fields§

§half_extents: Vec3

Half-extents along each axis.

Implementations§

Source§

impl BoxShape

Source

pub fn new(half_extents: Vec3) -> Self

Create a new box with the given half-extents.

Source

pub fn volume_explicit(&self) -> Real

Volume: (2hx)(2hy)(2hz).

Source

pub fn surface_area(&self) -> Real

Surface area: 2*(2hx2hy + 2hy2hz + 2hx*2hz).

Source

pub fn inertia_tensor_array(&self, mass: f64) -> [[f64; 3]; 3]

Inertia tensor as [[f64;3\];3] row-major. Diagonal: m/12*(b²+c², a²+c², a²+b²) where a,b,c are full side lengths.

Source

pub fn ray_cast_array( &self, origin: [f64; 3], direction: [f64; 3], max_toi: f64, ) -> Option<(f64, [f64; 3])>

Ray cast returning (t, normal) as plain arrays (slab method).

Source

pub fn support(&self, direction: [f64; 3]) -> [f64; 3]

GJK support function: farthest point in direction (componentwise sign).

Source

pub fn vertex_list(&self) -> [[f64; 3]; 8]

All 8 vertices of the box.

Source

pub fn face_normals() -> [[f64; 3]; 6]

Returns the 6 face normals of the box (axis-aligned, outward).

Source

pub fn edge_list() -> [(usize, usize); 12]

Returns the 12 edges of the box as pairs of vertex indices into vertex_list().

Source

pub fn face_vertex_indices() -> [[usize; 4]; 6]

Returns the 6 faces as groups of 4 vertex indices (into vertex_list()). Each face’s vertices are in counter-clockwise order from outside.

Source

pub fn face_areas(&self) -> [f64; 6]

Area of each face: returns [+X, -X, +Y, -Y, +Z, -Z].

Source

pub fn closest_point(&self, p: [f64; 3]) -> [f64; 3]

Closest point on (or inside) the box to point p.

Source

pub fn contains_point(&self, p: [f64; 3]) -> bool

Returns true if p is inside (or on the surface of) the box.

Source

pub fn signed_distance(&self, p: [f64; 3]) -> f64

Signed distance from a point to the box surface. Negative if inside, positive if outside.

Source

pub fn clip_segment(&self, a: [f64; 3], b: [f64; 3]) -> Option<(f64, f64)>

Clip a line segment (from a to b) against this box. Returns Some((t_enter, t_exit)) where 0 <= t_enter <= t_exit <= 1, or None if the segment doesn’t intersect the box.

Source

pub fn classify_face(&self, p: [f64; 3]) -> usize

Determine which face a surface point is on. Returns the face index (0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z).

Source

pub fn diagonal_length(&self) -> f64

Diagonal length of the box: 2 * sqrt(hx² + hy² + hz²).

Source

pub fn edge_lengths(&self) -> [f64; 3]

Edge lengths: [2hx, 2hy, 2*hz].

Source

pub fn project_on_axis(&self, axis: [f64; 3]) -> (f64, f64)

Project the box onto an axis and return (min, max) interval.

Trait Implementations§

Source§

impl Clone for BoxShape

Source§

fn clone(&self) -> BoxShape

Returns a duplicate 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 Debug for BoxShape

Source§

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

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

impl Shape for BoxShape

Source§

fn bounding_box(&self) -> Aabb

Compute the axis-aligned bounding box of this shape (in local space).
Source§

fn support_point(&self, direction: &Vec3) -> Vec3

Compute the support point in the given direction (for GJK).
Source§

fn volume(&self) -> Real

Compute the volume of this shape.
Source§

fn center_of_mass(&self) -> Vec3

Compute the center of mass in local space.
Source§

fn inertia_tensor(&self, mass: Real) -> Mat3

Compute the inertia tensor for the given mass.
Source§

fn ray_cast( &self, ray_origin: &Vec3, ray_direction: &Vec3, max_toi: Real, ) -> Option<RayHit>

Cast a ray against this shape (in local space). Returns the first intersection within max_toi.
Source§

fn mass_properties(&self, density: Real) -> MassProperties

Compute full mass properties for a given density.

Auto Trait Implementations§

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
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.