1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use crate::math::{Isometry, Point, Real};
use crate::shape::FeatureId;
use na;
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PointProjection {
pub is_inside: bool,
pub point: Point<Real>,
}
impl PointProjection {
pub fn new(is_inside: bool, point: Point<Real>) -> Self {
PointProjection { is_inside, point }
}
pub fn transform_by(&self, pos: &Isometry<Real>) -> Self {
PointProjection {
is_inside: self.is_inside,
point: pos * self.point,
}
}
}
pub trait PointQuery {
fn project_local_point(&self, pt: &Point<Real>, solid: bool) -> PointProjection;
fn project_local_point_and_get_feature(&self, pt: &Point<Real>)
-> (PointProjection, FeatureId);
fn distance_to_local_point(&self, pt: &Point<Real>, solid: bool) -> Real {
let proj = self.project_local_point(pt, solid);
let dist = na::distance(pt, &proj.point);
if solid || !proj.is_inside {
dist
} else {
-dist
}
}
fn contains_local_point(&self, pt: &Point<Real>) -> bool {
self.project_local_point(pt, true).is_inside
}
fn project_point(&self, m: &Isometry<Real>, pt: &Point<Real>, solid: bool) -> PointProjection {
self.project_local_point(&m.inverse_transform_point(pt), solid)
.transform_by(m)
}
#[inline]
fn distance_to_point(&self, m: &Isometry<Real>, pt: &Point<Real>, solid: bool) -> Real {
self.distance_to_local_point(&m.inverse_transform_point(pt), solid)
}
fn project_point_and_get_feature(
&self,
m: &Isometry<Real>,
pt: &Point<Real>,
) -> (PointProjection, FeatureId) {
let res = self.project_local_point_and_get_feature(&m.inverse_transform_point(pt));
(res.0.transform_by(m), res.1)
}
#[inline]
fn contains_point(&self, m: &Isometry<Real>, pt: &Point<Real>) -> bool {
self.contains_local_point(&m.inverse_transform_point(pt))
}
}
pub trait PointQueryWithLocation {
type Location;
fn project_local_point_and_get_location(
&self,
pt: &Point<Real>,
solid: bool,
) -> (PointProjection, Self::Location);
fn project_point_and_get_location(
&self,
m: &Isometry<Real>,
pt: &Point<Real>,
solid: bool,
) -> (PointProjection, Self::Location) {
let res = self.project_local_point_and_get_location(&m.inverse_transform_point(pt), solid);
(res.0.transform_by(m), res.1)
}
}