use crate::math::{Isometry, Point, Real};
use std::mem;
#[derive(Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes)
)]
pub enum ClosestPoints {
Intersecting,
WithinMargin(Point<Real>, Point<Real>),
Disjoint,
}
impl ClosestPoints {
pub fn flip(&mut self) {
if let ClosestPoints::WithinMargin(ref mut p1, ref mut p2) = *self {
mem::swap(p1, p2)
}
}
#[must_use]
pub fn flipped(&self) -> Self {
if let ClosestPoints::WithinMargin(p1, p2) = *self {
ClosestPoints::WithinMargin(p2, p1)
} else {
*self
}
}
#[must_use]
pub fn transform_by(self, pos1: &Isometry<Real>, pos2: &Isometry<Real>) -> Self {
if let ClosestPoints::WithinMargin(p1, p2) = self {
ClosestPoints::WithinMargin(pos1 * p1, pos2 * p2)
} else {
self
}
}
}