parry3d/query/contact/
contact.rs1use crate::math::{Isometry, Point, Real, Vector};
2use core::mem;
3use na::{self, Unit};
4
5#[cfg(feature = "rkyv")]
6use rkyv::{bytecheck, CheckBytes};
7
8#[derive(Debug, PartialEq, Copy, Clone)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[cfg_attr(
12 feature = "rkyv",
13 derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, CheckBytes),
14 archive(as = "Self")
15)]
16pub struct Contact {
17 pub point1: Point<Real>,
19
20 pub point2: Point<Real>,
22
23 pub normal1: Unit<Vector<Real>>,
25
26 pub normal2: Unit<Vector<Real>>,
30
31 pub dist: Real,
35}
36
37impl Contact {
38 #[inline]
40 pub fn new(
41 point1: Point<Real>,
42 point2: Point<Real>,
43 normal1: Unit<Vector<Real>>,
44 normal2: Unit<Vector<Real>>,
45 dist: Real,
46 ) -> Self {
47 Contact {
48 point1,
49 point2,
50 normal1,
51 normal2,
52 dist,
53 }
54 }
55}
56
57impl Contact {
58 #[inline]
60 pub fn flip(&mut self) {
61 mem::swap(&mut self.point1, &mut self.point2);
62 mem::swap(&mut self.normal1, &mut self.normal2);
63 }
64
65 #[inline]
67 pub fn flipped(mut self) -> Self {
68 self.flip();
69 self
70 }
71
72 #[inline]
75 pub fn transform_by_mut(&mut self, pos1: &Isometry<Real>, pos2: &Isometry<Real>) {
76 self.point1 = pos1 * self.point1;
77 self.point2 = pos2 * self.point2;
78 self.normal1 = pos1 * self.normal1;
79 self.normal2 = pos2 * self.normal2;
80 }
81
82 pub fn transform1_by_mut(&mut self, pos: &Isometry<Real>) {
84 self.point1 = pos * self.point1;
85 self.normal1 = pos * self.normal1;
86 }
87}