parry3d/query/closest_points/
closest_points.rs1use crate::math::{Isometry, Point, Real};
2
3use core::mem;
4
5#[derive(Debug, PartialEq, Clone, Copy)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8#[cfg_attr(
9 feature = "rkyv",
10 derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
11 archive(check_bytes)
12)]
13pub enum ClosestPoints {
14 Intersecting,
16 WithinMargin(Point<Real>, Point<Real>),
18 Disjoint,
20}
21
22impl ClosestPoints {
23 pub fn flip(&mut self) {
25 if let ClosestPoints::WithinMargin(ref mut p1, ref mut p2) = *self {
26 mem::swap(p1, p2)
27 }
28 }
29
30 #[must_use]
32 pub fn flipped(&self) -> Self {
33 if let ClosestPoints::WithinMargin(p1, p2) = *self {
34 ClosestPoints::WithinMargin(p2, p1)
35 } else {
36 *self
37 }
38 }
39
40 #[must_use]
42 pub fn transform_by(self, pos1: &Isometry<Real>, pos2: &Isometry<Real>) -> Self {
43 if let ClosestPoints::WithinMargin(p1, p2) = self {
44 ClosestPoints::WithinMargin(pos1 * p1, pos2 * p2)
45 } else {
46 self
47 }
48 }
49}