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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
use super::*;
impl World {
/// Overlap test for all shapes in an AABB. Returns matching shape ids.
///
/// Example
/// ```no_run
/// use boxdd::{World, WorldDef, BodyBuilder, ShapeDef, shapes, Vec2, Aabb, QueryFilter};
/// let mut world = World::new(WorldDef::builder().gravity([0.0,-9.8]).build()).unwrap();
/// let b = world.create_body_id(BodyBuilder::new().position([0.0, 2.0]).build());
/// let sdef = ShapeDef::builder().density(1.0).build();
/// world.create_polygon_shape_for(b, &sdef, &shapes::box_polygon(0.5, 0.5));
/// let hits = world.overlap_aabb(Aabb { lower: Vec2::new(-1.0, -1.0), upper: Vec2::new(1.0, 3.0) }, QueryFilter::default());
/// assert!(!hits.is_empty());
/// ```
pub fn overlap_aabb(&self, aabb: Aabb, filter: QueryFilter) -> Vec<ShapeId> {
overlap_aabb_checked_impl(self.raw(), aabb, filter)
}
/// Overlap test for all shapes in an AABB and write matching shape ids into `out`.
///
/// `out` is cleared before new hits are appended so its allocation can be reused across frames.
pub fn overlap_aabb_into(&self, aabb: Aabb, filter: QueryFilter, out: &mut Vec<ShapeId>) {
overlap_aabb_into_checked_impl(self.raw(), aabb, filter, out);
}
/// Visit matching shape ids in an AABB without allocating a result container.
///
/// Return `true` from the visitor to continue, or `false` to stop early.
/// Returns `true` if all hits were visited, or `false` if the visitor stopped early.
pub fn visit_overlap_aabb<F>(&self, aabb: Aabb, filter: QueryFilter, mut visit: F) -> bool
where
F: FnMut(ShapeId) -> bool,
{
visit_overlap_aabb_checked_impl(self.raw(), aabb, filter, &mut visit)
}
pub fn try_overlap_aabb(&self, aabb: Aabb, filter: QueryFilter) -> ApiResult<Vec<ShapeId>> {
try_overlap_aabb_impl(self.raw(), aabb, filter)
}
pub fn try_overlap_aabb_into(
&self,
aabb: Aabb,
filter: QueryFilter,
out: &mut Vec<ShapeId>,
) -> ApiResult<()> {
try_overlap_aabb_into_impl(self.raw(), aabb, filter, out)
}
pub fn try_visit_overlap_aabb<F>(
&self,
aabb: Aabb,
filter: QueryFilter,
mut visit: F,
) -> ApiResult<bool>
where
F: FnMut(ShapeId) -> bool,
{
try_visit_overlap_aabb_impl(self.raw(), aabb, filter, &mut visit)
}
/// Overlap polygon points (creates a temporary shape proxy from given points + radius) and collect all shape ids.
///
/// Example
/// ```no_run
/// use boxdd::{World, WorldDef, QueryFilter, Vec2};
/// let mut world = World::new(WorldDef::builder().gravity([0.0,-9.8]).build()).unwrap();
/// let square = [Vec2::new(-0.5, -0.5), Vec2::new(0.5, -0.5), Vec2::new(0.5, 0.5), Vec2::new(-0.5, 0.5)];
/// let hits = world.overlap_polygon_points(square, 0.0, QueryFilter::default());
/// let _ = hits;
/// ```
pub fn overlap_polygon_points<I, P>(
&self,
points: I,
radius: f32,
filter: QueryFilter,
) -> Vec<ShapeId>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
{
overlap_polygon_points_checked_impl(self.raw(), points, radius, filter)
}
/// Overlap a temporary polygon proxy and write matching shape ids into `out`.
pub fn overlap_polygon_points_into<I, P>(
&self,
points: I,
radius: f32,
filter: QueryFilter,
out: &mut Vec<ShapeId>,
) where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
{
overlap_polygon_points_into_checked_impl(self.raw(), points, radius, filter, out);
}
/// Visit matching shape ids for a temporary polygon proxy without allocating a result container.
///
/// Return `true` from the visitor to continue, or `false` to stop early.
/// Returns `true` if all hits were visited, or `false` if the visitor stopped early.
pub fn visit_overlap_polygon_points<I, P, F>(
&self,
points: I,
radius: f32,
filter: QueryFilter,
mut visit: F,
) -> bool
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
F: FnMut(ShapeId) -> bool,
{
visit_overlap_polygon_points_checked_impl(self.raw(), points, radius, filter, &mut visit)
}
pub fn try_overlap_polygon_points<I, P>(
&self,
points: I,
radius: f32,
filter: QueryFilter,
) -> ApiResult<Vec<ShapeId>>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
{
try_overlap_polygon_points_impl(self.raw(), points, radius, filter)
}
pub fn try_overlap_polygon_points_into<I, P>(
&self,
points: I,
radius: f32,
filter: QueryFilter,
out: &mut Vec<ShapeId>,
) -> ApiResult<()>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
{
try_overlap_polygon_points_into_impl(self.raw(), points, radius, filter, out)
}
pub fn try_visit_overlap_polygon_points<I, P, F>(
&self,
points: I,
radius: f32,
filter: QueryFilter,
mut visit: F,
) -> ApiResult<bool>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
F: FnMut(ShapeId) -> bool,
{
try_visit_overlap_polygon_points_impl(self.raw(), points, radius, filter, &mut visit)
}
/// Overlap polygon points with an offset transform.
///
/// Example
/// ```no_run
/// use boxdd::{World, WorldDef, QueryFilter, Vec2};
/// let mut world = World::new(WorldDef::builder().gravity([0.0,-9.8]).build()).unwrap();
/// let rect = [Vec2::new(-0.5, -0.25), Vec2::new(0.5, -0.25), Vec2::new(0.5, 0.25), Vec2::new(-0.5, 0.25)];
/// let hits = world.overlap_polygon_points_with_offset(rect, 0.0, Vec2::new(0.0, 2.0), 0.0_f32, QueryFilter::default());
/// let _ = hits;
/// ```
pub fn overlap_polygon_points_with_offset<I, P, V, A>(
&self,
points: I,
radius: f32,
position: V,
angle_radians: A,
filter: QueryFilter,
) -> Vec<ShapeId>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
V: Into<Vec2>,
A: Into<f32>,
{
overlap_polygon_points_with_offset_checked_impl(
self.raw(),
points,
radius,
position,
angle_radians,
filter,
)
}
/// Overlap an offset polygon proxy and write matching shape ids into `out`.
pub fn overlap_polygon_points_with_offset_into<I, P, V, A>(
&self,
points: I,
radius: f32,
position: V,
angle_radians: A,
filter: QueryFilter,
out: &mut Vec<ShapeId>,
) where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
V: Into<Vec2>,
A: Into<f32>,
{
overlap_polygon_points_with_offset_into_checked_impl(
self.raw(),
points,
radius,
position,
angle_radians,
filter,
out,
);
}
/// Visit matching shape ids for an offset temporary polygon proxy without allocating a result container.
///
/// Return `true` from the visitor to continue, or `false` to stop early.
/// Returns `true` if all hits were visited, or `false` if the visitor stopped early.
pub fn visit_overlap_polygon_points_with_offset<I, P, V, A, F>(
&self,
points: I,
radius: f32,
position: V,
angle_radians: A,
filter: QueryFilter,
mut visit: F,
) -> bool
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
V: Into<Vec2>,
A: Into<f32>,
F: FnMut(ShapeId) -> bool,
{
visit_overlap_polygon_points_with_offset_checked_impl(
self.raw(),
points,
radius,
position,
angle_radians,
filter,
&mut visit,
)
}
pub fn try_overlap_polygon_points_with_offset<I, P, V, A>(
&self,
points: I,
radius: f32,
position: V,
angle_radians: A,
filter: QueryFilter,
) -> ApiResult<Vec<ShapeId>>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
V: Into<Vec2>,
A: Into<f32>,
{
try_overlap_polygon_points_with_offset_impl(
self.raw(),
points,
radius,
position,
angle_radians,
filter,
)
}
pub fn try_overlap_polygon_points_with_offset_into<I, P, V, A>(
&self,
points: I,
radius: f32,
position: V,
angle_radians: A,
filter: QueryFilter,
out: &mut Vec<ShapeId>,
) -> ApiResult<()>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
V: Into<Vec2>,
A: Into<f32>,
{
try_overlap_polygon_points_with_offset_into_impl(
self.raw(),
points,
radius,
position,
angle_radians,
filter,
out,
)
}
pub fn try_visit_overlap_polygon_points_with_offset<I, P, V, A, F>(
&self,
points: I,
radius: f32,
position: V,
angle_radians: A,
filter: QueryFilter,
mut visit: F,
) -> ApiResult<bool>
where
I: IntoIterator<Item = P>,
P: Into<Vec2>,
V: Into<Vec2>,
A: Into<f32>,
F: FnMut(ShapeId) -> bool,
{
try_visit_overlap_polygon_points_with_offset_impl(
self.raw(),
points,
radius,
position,
angle_radians,
filter,
&mut visit,
)
}
}