Skip to main content

Collision

Struct Collision 

Source
pub struct Collision {
    pub body_i: usize,
    pub body_j: usize,
    pub contact_point: Vec3<f64>,
    pub contact_normal: Vec3<f64>,
    pub penetration_depth: f64,
}
Expand description

Result of a collision query between two geometries.

Fields§

§body_i: usize

Index of first body involved.

§body_j: usize

Index of the second body involved, or Collision::WORLD for the static world (ground, terrain, any immovable half-space).

This is an in-band sentinel, kept for the moment because the whole contact pipeline is written against it. Prefer Collision::attachment_j over comparing to WORLD by hand: it returns a phyz_model::Attachment, which makes the world a distinct variant instead of a reserved index, and is what the Jacobian and constraint APIs take. The hazard the typed form removes is that usize::MAX looks like an ordinary index, so a stale one is silently reinterpreted as “the world” and the contact quietly stops pushing back on one side.

§contact_point: Vec3<f64>

Contact point in world frame.

§contact_normal: Vec3<f64>

Contact normal: the direction body_i must move to separate from body_j, i.e. it points from j toward i.

Stated this way because the two producers used to disagree and only one of them was ever exercised. find_ground_contacts emits +z for a body resting on the ground — the separating direction for that body, and the sense the contact solver is built around, since its non-penetration row is J·v ≥ 0 with J = J_i − J_j. find_contacts used to pass Manifold::normal straight through, and that points from shape a toward shape b — the exact opposite. The constraint therefore measured approach instead of separation and the solver drove overlapping bodies together: a box dropped on a box sank clean through it to full overlap, with four contacts detected the whole way down. Invisible until bodies other than the feet had collision geometry, because before that no body-body contact ever occurred.

§penetration_depth: f64

Penetration depth (positive = penetrating).

Implementations§

Source§

impl Collision

Source

pub const WORLD: usize = usize::MAX

The value of Collision::body_j that means “the static world”.

Named so the magic number appears once, here, instead of being spelled usize::MAX at every comparison site — where it reads as a bounds check rather than as a semantic test and is easy to get backwards.

Source

pub fn attachment_j(&self) -> Attachment

Collision::body_j as a typed Attachment.

This is the accessor to reach for: it turns the sentinel into a variant at the one place that knows the convention, so consumers never compare an index against usize::MAX themselves.

Source

pub fn is_world_j(&self) -> bool

Whether the second side of this contact is the static world.

Trait Implementations§

Source§

impl Clone for Collision

Source§

fn clone(&self) -> Collision

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 Debug for Collision

Source§

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

Formats the value using the given formatter. Read more

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.