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
use crate::math::{Real, Vect};
use rapier::parry::shape::HeightField;
pub use rapier::parry::shape::HeightFieldCellStatus;
pub struct HeightFieldView<'a> {
pub raw: &'a HeightField,
}
macro_rules! impl_ref_methods(
($View: ident) => {
#[cfg(feature = "dim2")]
impl<'a> $View<'a> {
pub fn num_cells(&self) -> usize {
self.raw.num_cells()
}
pub fn heights(&self) -> &[Real] {
self.raw.heights().as_slice()
}
pub fn scale(&self) -> Vect {
(*self.raw.scale()).into()
}
pub fn cell_width(&self) -> Real {
self.raw.cell_width()
}
pub fn unit_cell_width(&self) -> Real {
self.raw.unit_cell_width()
}
pub fn cell_at_point(&self, pt: Vect) -> Option<usize> {
self.raw.cell_at_point(&pt.into())
}
pub fn segments(&self) -> impl Iterator<Item = (Vect, Vect)> + '_ {
self.raw.segments().map(|seg| (seg.a.into(), seg.b.into()))
}
pub fn segment_at(&self, i: usize) -> Option<(Vect, Vect)> {
self.raw
.segment_at(i)
.map(|seg| (seg.a.into(), seg.b.into()))
}
pub fn is_segment_removed(&self, i: usize) -> bool {
self.raw.is_segment_removed(i)
}
}
#[cfg(feature = "dim3")]
impl<'a> $View<'a> {
pub fn nrows(&self) -> usize {
self.raw.nrows()
}
pub fn ncols(&self) -> usize {
self.raw.ncols()
}
pub fn heights(&self) -> &[Real] {
self.raw.heights().as_slice()
}
pub fn scale(&self) -> Vect {
(*self.raw.scale()).into()
}
pub fn cell_width(&self) -> Real {
self.raw.cell_width()
}
pub fn cell_height(&self) -> Real {
self.raw.cell_height()
}
pub fn unit_cell_width(&self) -> Real {
self.raw.unit_cell_width()
}
pub fn unit_cell_height(&self) -> Real {
self.raw.unit_cell_height()
}
pub fn cell_at_point(&self, pt: Vect) -> Option<(usize, usize)> {
self.raw.cell_at_point(&pt.into())
}
pub fn triangles(&self) -> impl Iterator<Item = (Vect, Vect, Vect)> + '_ {
self.raw
.triangles()
.map(|tri| (tri.a.into(), tri.b.into(), tri.c.into()))
}
pub fn triangles_at(
&self,
i: usize,
j: usize,
) -> (Option<(Vect, Vect, Vect)>, Option<(Vect, Vect, Vect)>) {
let (tri1, tri2) = self.raw.triangles_at(i, j);
(
tri1.map(|tri| (tri.a.into(), tri.b.into(), tri.c.into())),
tri2.map(|tri| (tri.a.into(), tri.b.into(), tri.c.into())),
)
}
pub fn cell_status(&self, i: usize, j: usize) -> HeightFieldCellStatus {
self.raw.cell_status(i, j)
}
pub fn cells_statuses(&self) -> &[HeightFieldCellStatus] {
self.raw.cells_statuses().as_slice()
}
}
}
);
impl_ref_methods!(HeightFieldView);
pub struct HeightFieldViewMut<'a> {
pub raw: &'a mut HeightField,
}
impl_ref_methods!(HeightFieldViewMut);
#[cfg(feature = "dim2")]
impl<'a> HeightFieldViewMut<'a> {
pub fn set_segment_removed(&mut self, i: usize, removed: bool) {
self.raw.set_segment_removed(i, removed)
}
}
#[cfg(feature = "dim3")]
impl<'a> HeightFieldViewMut<'a> {
pub fn set_cell_status(&mut self, i: usize, j: usize, status: HeightFieldCellStatus) {
self.raw.set_cell_status(i, j, status)
}
pub fn cells_statuses_mut(&mut self) -> &mut [HeightFieldCellStatus] {
self.raw.cells_statuses_mut().as_mut_slice()
}
}