use core::cmp::Ordering;
use parry::{math::Real, query::ShapeCastHit};
pub struct Contact<P = ()> {
hit: ShapeCastHit,
weight_ratio: Real,
payload: P,
}
impl<P> Contact<P> {
#[inline]
pub fn new(hit: ShapeCastHit, weight_ratio: Real, payload: P) -> Self {
Self {
hit,
weight_ratio,
payload,
}
}
#[inline]
pub fn hit(&self) -> &ShapeCastHit {
&self.hit
}
#[inline]
pub fn weight_ratio(&self) -> Real {
self.weight_ratio
}
#[inline]
pub fn payload(&self) -> &P {
&self.payload
}
#[inline]
pub fn payload_mut(&mut self) -> &mut P {
&mut self.payload
}
pub fn order(&self, other: &Self, epsilon: Real) -> Ordering {
let ta = self.hit.time_of_impact;
let tb = other.hit.time_of_impact;
if (ta - tb).abs() < epsilon {
Ordering::Equal
} else if ta < tb {
Ordering::Less
} else {
Ordering::Greater
}
}
}