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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use crate::bounding_volume::{BoundingSphere, AABB};
use crate::math::{Isometry, Vector};
use na::{self, Real, Unit};
use crate::query::{PointQuery, RayCast};
use crate::shape::{CompositeShape, ConvexPolyhedron, DeformableShape, FeatureId, SupportMap};
use std::ops::Deref;
use std::sync::Arc;
use downcast_rs::Downcast;
pub trait ShapeClone<N: Real> {
fn clone_box(&self) -> Box<Shape<N>> {
unimplemented!()
}
}
impl<N: Real, T: 'static + Shape<N> + Clone> ShapeClone<N> for T {
fn clone_box(&self) -> Box<Shape<N>> {
Box::new(self.clone())
}
}
pub trait Shape<N: Real>: Send + Sync + Downcast + ShapeClone<N> {
#[inline]
fn aabb(&self, m: &Isometry<N>) -> AABB<N>;
#[inline]
fn bounding_sphere(&self, m: &Isometry<N>) -> BoundingSphere<N> {
let aabb = self.aabb(m);
BoundingSphere::new(aabb.center(), aabb.half_extents().norm_squared())
}
#[inline]
fn tangent_cone_contains_dir(
&self,
_feature: FeatureId,
_m: &Isometry<N>,
_deformations: Option<&[N]>,
_dir: &Unit<Vector<N>>,
) -> bool;
fn subshape_containing_feature(&self, _i: FeatureId) -> usize {
0
}
#[inline]
fn as_ray_cast(&self) -> Option<&RayCast<N>> {
None
}
#[inline]
fn as_point_query(&self) -> Option<&PointQuery<N>> {
None
}
#[inline]
fn as_convex_polyhedron(&self) -> Option<&ConvexPolyhedron<N>> {
None
}
#[inline]
fn as_support_map(&self) -> Option<&SupportMap<N>> {
None
}
#[inline]
fn as_composite_shape(&self) -> Option<&CompositeShape<N>> {
None
}
#[inline]
fn as_deformable_shape(&self) -> Option<&DeformableShape<N>> {
None
}
#[inline]
fn as_deformable_shape_mut(&mut self) -> Option<&mut DeformableShape<N>> {
None
}
#[inline]
fn is_convex_polyhedron(&self) -> bool {
self.as_convex_polyhedron().is_some()
}
#[inline]
fn is_support_map(&self) -> bool {
self.as_support_map().is_some()
}
#[inline]
fn is_composite_shape(&self) -> bool {
self.as_composite_shape().is_some()
}
#[inline]
fn is_deformable_shape(&self) -> bool {
self.as_deformable_shape().is_some()
}
}
impl_downcast!(Shape<N> where N: Real);
impl<N: Real> Shape<N> {
#[inline]
pub fn is_shape<T: Shape<N>>(&self) -> bool {
self.is::<T>()
}
#[inline]
pub fn as_shape<T: Shape<N>>(&self) -> Option<&T> {
self.downcast_ref()
}
}
impl<N: Real> Clone for Box<Shape<N>> {
fn clone(&self) -> Box<Shape<N>> {
self.clone_box()
}
}
#[derive(Clone)]
pub struct ShapeHandle<N: Real>(Arc<Box<Shape<N>>>);
impl<N: Real> ShapeHandle<N> {
#[inline]
pub fn new<S: Shape<N> + Clone>(shape: S) -> ShapeHandle<N> {
ShapeHandle(Arc::new(Box::new(shape)))
}
pub(crate) fn make_mut(&mut self) -> &mut Shape<N> {
&mut **Arc::make_mut(&mut self.0)
}
}
impl<N: Real> AsRef<Shape<N>> for ShapeHandle<N> {
#[inline]
fn as_ref(&self) -> &Shape<N> {
&*self.deref()
}
}
impl<N: Real> Deref for ShapeHandle<N> {
type Target = Shape<N>;
#[inline]
fn deref(&self) -> &Shape<N> {
&**self.0.deref()
}
}