oxiphysics-collision 0.1.1

Collision detection algorithms for the OxiPhysics engine
Documentation
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//! Auto-generated module
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)

#[allow(unused_imports)]
use super::functions::*;
#[allow(unused_imports)]
use super::types::*;
#[cfg(test)]
mod tests_gjk_extended {
    use super::*;
    use oxiphysics_core::Transform;
    use oxiphysics_core::Vec3;
    use oxiphysics_geometry::{BoxShape, Capsule, Sphere};
    #[test]
    fn test_gjk_distance_query_separated() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        let result = gjk_distance_query(&s1, &t1, &s2, &t2);
        assert!(
            result.distance > 0.0,
            "should be separated, got {}",
            result.distance
        );
        assert!(result.iterations > 0);
        assert!(result.closest_a.x.is_finite());
        assert!(result.closest_b.x.is_finite());
    }
    #[test]
    fn test_gjk_distance_query_intersecting() {
        let s1 = Sphere::new(1.5);
        let s2 = Sphere::new(1.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(1.0, 0.0, 0.0));
        let result = gjk_distance_query(&s1, &t1, &s2, &t2);
        assert!(
            result.distance <= 0.0,
            "overlapping shapes should have non-positive distance"
        );
    }
    #[test]
    fn test_gjk_distance_query_witness_direction() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        let result = gjk_distance_query(&s1, &t1, &s2, &t2);
        if result.distance > 0.0 {
            assert!(
                result.closest_a.x < result.closest_b.x,
                "closest_a.x={} should be < closest_b.x={}",
                result.closest_a.x,
                result.closest_b.x
            );
        }
    }
    #[test]
    fn test_gjk_distance_query_box_sphere() {
        let b = BoxShape::new(Vec3::new(1.0, 1.0, 1.0));
        let s = Sphere::new(0.5);
        let tb = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let ts = Transform::from_position(Vec3::new(3.0, 0.0, 0.0));
        let result = gjk_distance_query(&b, &tb, &s, &ts);
        assert!(result.distance > 0.0, "box and sphere should be separated");
    }
    #[test]
    fn test_gjk_distance_consistency_with_basic() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(3.0, 0.0, 0.0));
        let d1 = gjk_distance(&s1, &t1, &s2, &t2);
        let d2 = gjk_distance_query(&s1, &t1, &s2, &t2).distance;
        assert_eq!(
            d1 > 0.0,
            d2 > 0.0,
            "both distance functions should agree on sign"
        );
    }
    #[test]
    fn test_gjk_ray_cast_sphere_hit() {
        let s = Sphere::new(1.0);
        let t = Transform::from_position(Vec3::new(5.0, 0.0, 0.0));
        let origin = Vec3::new(0.0, 0.0, 0.0);
        let dir = Vec3::new(1.0, 0.0, 0.0);
        let result = gjk_ray_cast(&s, &t, origin, dir, 20.0);
        assert!(
            result.is_some(),
            "ray along +X toward sphere at x=5 should hit"
        );
        if let Some(hit) = result {
            assert!(hit.t > 0.0 && hit.t < 20.0, "hit.t={}", hit.t);
        }
    }
    #[test]
    fn test_gjk_ray_cast_sphere_miss() {
        let s = Sphere::new(0.5);
        let t = Transform::from_position(Vec3::new(5.0, 10.0, 0.0));
        let origin = Vec3::new(0.0, 0.0, 0.0);
        let dir = Vec3::new(1.0, 0.0, 0.0);
        let result = gjk_ray_cast(&s, &t, origin, dir, 20.0);
        let _ = result;
    }
    #[test]
    fn test_gjk_ray_cast_zero_direction_returns_none() {
        let s = Sphere::new(1.0);
        let t = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let result = gjk_ray_cast(&s, &t, Vec3::zeros(), Vec3::zeros(), 10.0);
        assert!(result.is_none(), "zero direction should return None");
    }
    #[test]
    fn test_gjk_ray_cast_max_t_respected() {
        let s = Sphere::new(1.0);
        let t = Transform::from_position(Vec3::new(100.0, 0.0, 0.0));
        let origin = Vec3::new(0.0, 0.0, 0.0);
        let dir = Vec3::new(1.0, 0.0, 0.0);
        let result = gjk_ray_cast(&s, &t, origin, dir, 5.0);
        let _ = result;
    }
    #[test]
    fn test_mpr_sphere_sphere_intersecting() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(1.0, 0.0, 0.0));
        let result = mpr_query(&s1, &t1, &s2, &t2);
        match result {
            MprResult::Intersecting { depth, .. } => {
                assert!(depth >= 0.0, "depth should be non-negative: {depth}");
            }
            MprResult::Separated => {}
        }
    }
    #[test]
    fn test_mpr_sphere_sphere_separated() {
        let s1 = Sphere::new(0.5);
        let s2 = Sphere::new(0.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(5.0, 0.0, 0.0));
        let result = mpr_query(&s1, &t1, &s2, &t2);
        match result {
            MprResult::Separated => {}
            MprResult::Intersecting { depth, .. } => {
                assert!(
                    depth < 1.0,
                    "clearly separated spheres should not have large depth: {depth}"
                );
            }
        }
    }
    #[test]
    fn test_mpr_coincident_returns_intersecting() {
        let s = Sphere::new(1.0);
        let t = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let result = mpr_query(&s, &t, &s, &t);
        assert!(matches!(result, MprResult::Intersecting { .. }));
    }
    #[test]
    fn test_mpr_box_box_intersecting() {
        let b1 = BoxShape::new(Vec3::new(1.0, 1.0, 1.0));
        let b2 = BoxShape::new(Vec3::new(1.0, 1.0, 1.0));
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(1.5, 0.0, 0.0));
        let result = mpr_query(&b1, &t1, &b2, &t2);
        let _ = result;
    }
    #[test]
    fn test_warm_start_gjk_consistent_separated() {
        let mut ws = WarmStartGjk::new();
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        let r1 = ws.query(&s1, &t1, &s2, &t2);
        let r2 = ws.query(&s1, &t1, &s2, &t2);
        assert!(matches!(r1, GjkResult::Separated { .. }));
        assert!(matches!(r2, GjkResult::Separated { .. }));
    }
    #[test]
    fn test_warm_start_gjk_consistent_intersecting() {
        let mut ws = WarmStartGjk::new();
        let s1 = Sphere::new(2.0);
        let s2 = Sphere::new(2.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(1.0, 0.0, 0.0));
        let r1 = ws.query(&s1, &t1, &s2, &t2);
        let _ = ws.query(&s1, &t1, &s2, &t2);
        assert!(matches!(r1, GjkResult::Intersecting(_)));
    }
    #[test]
    fn test_warm_start_gjk_records_stats() {
        let mut ws = WarmStartGjk::new();
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        for _ in 0..5 {
            ws.query(&s1, &t1, &s2, &t2);
        }
        assert_eq!(ws.query_count(), 5);
        assert!(ws.avg_iterations() > 0.0);
    }
    #[test]
    fn test_warm_start_gjk_reset_clears_state() {
        let mut ws = WarmStartGjk::new();
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        ws.query(&s1, &t, &s2, &t2);
        ws.reset();
        let result = ws.query(&s1, &t, &s2, &t2);
        assert!(matches!(result, GjkResult::Separated { .. }));
    }
    #[test]
    fn test_gjk_toi_bisection_approaching() {
        let s1 = Sphere::new(0.5);
        let s2 = Sphere::new(0.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        let v1 = Vec3::new(2.0, 0.0, 0.0);
        let v2 = Vec3::new(-2.0, 0.0, 0.0);
        let toi = gjk_toi_bisection(&s1, &t1, v1, &s2, &t2, v2, 5.0, 1e-4);
        assert!(toi.is_some(), "approaching spheres should produce TOI");
        let t = toi.unwrap();
        assert!(t > 0.0 && t <= 5.0, "TOI should be in (0, 5], got {t}");
    }
    #[test]
    fn test_gjk_toi_bisection_receding_returns_none() {
        let s1 = Sphere::new(0.5);
        let s2 = Sphere::new(0.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(4.0, 0.0, 0.0));
        let v1 = Vec3::new(-1.0, 0.0, 0.0);
        let v2 = Vec3::new(1.0, 0.0, 0.0);
        let toi = gjk_toi_bisection(&s1, &t1, v1, &s2, &t2, v2, 5.0, 1e-4);
        assert!(toi.is_none(), "receding spheres should have no TOI");
    }
    #[test]
    fn test_gjk_toi_bisection_already_overlapping() {
        let s1 = Sphere::new(2.0);
        let s2 = Sphere::new(2.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(1.0, 0.0, 0.0));
        let v = Vec3::new(0.0, 0.0, 0.0);
        let toi = gjk_toi_bisection(&s1, &t1, v, &s2, &t2, v, 5.0, 1e-4);
        assert!(toi.is_none(), "already overlapping should return None");
    }
    #[test]
    fn test_gjk_ccd_linear_hit() {
        let s1 = Sphere::new(0.5);
        let s2 = Sphere::new(0.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(2.0, 0.0, 0.0));
        let v1 = Vec3::new(1.5, 0.0, 0.0);
        let v2 = Vec3::new(0.0, 0.0, 0.0);
        let result = gjk_ccd_linear(&s1, &t1, v1, &s2, &t2, v2);
        assert!(result.is_some(), "should hit");
        let r = result.unwrap();
        assert!(r.toi >= 0.0 && r.toi <= 1.0, "toi={}", r.toi);
        assert!(
            r.normal.norm() > 0.5,
            "normal should be non-zero: {:?}",
            r.normal
        );
    }
    #[test]
    fn test_gjk_ccd_linear_no_hit() {
        let s1 = Sphere::new(0.1);
        let s2 = Sphere::new(0.1);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(100.0, 0.0, 0.0));
        let v1 = Vec3::new(0.0, 1.0, 0.0);
        let v2 = Vec3::new(0.0, 0.0, 0.0);
        let result = gjk_ccd_linear(&s1, &t1, v1, &s2, &t2, v2);
        assert!(result.is_none(), "should not hit far away sphere");
    }
    #[test]
    fn test_estimate_penetration_26_overlapping() {
        let s1 = Sphere::new(1.5);
        let s2 = Sphere::new(1.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(1.0, 0.0, 0.0));
        let (depth, axis) = estimate_penetration_depth_26(&s1, &t1, &s2, &t2);
        assert!(
            depth > 0.0,
            "overlapping spheres should have positive depth: {depth}"
        );
        assert!(axis.norm() > 0.9, "axis should be unit: {:?}", axis);
    }
    #[test]
    fn test_estimate_penetration_26_separated() {
        let s1 = Sphere::new(0.5);
        let s2 = Sphere::new(0.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(5.0, 0.0, 0.0));
        let (depth, _axis) = estimate_penetration_depth_26(&s1, &t1, &s2, &t2);
        let _ = depth;
    }
    #[test]
    fn test_gjk_speculative_contact_within_threshold() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(2.5, 0.0, 0.0));
        let result = gjk_speculative_contact(&s1, &t1, &s2, &t2, 1.0);
        assert!(
            result.is_some(),
            "should produce speculative contact within threshold"
        );
        let c = result.unwrap();
        assert!(
            c.gap >= 0.0,
            "gap should be non-negative for separated shapes: {}",
            c.gap
        );
    }
    #[test]
    fn test_gjk_speculative_contact_beyond_threshold() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(20.0, 0.0, 0.0));
        let result = gjk_speculative_contact(&s1, &t1, &s2, &t2, 0.1);
        assert!(
            result.is_none(),
            "should not produce contact when far beyond threshold"
        );
    }
    #[test]
    fn test_gjk_speculative_contact_normal_direction() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(2.5, 0.0, 0.0));
        if let Some(c) = gjk_speculative_contact(&s1, &t1, &s2, &t2, 1.0) {
            assert!(c.normal.norm() > 0.9, "normal should be approximately unit");
        }
    }
    #[test]
    fn test_gjk_hull_distance_separated() {
        let cube_a: Vec<[f64; 3]> = vec![
            [-1.0, -1.0, -1.0],
            [1.0, -1.0, -1.0],
            [1.0, 1.0, -1.0],
            [-1.0, 1.0, -1.0],
            [-1.0, -1.0, 1.0],
            [1.0, -1.0, 1.0],
            [1.0, 1.0, 1.0],
            [-1.0, 1.0, 1.0],
        ];
        let cube_b: Vec<[f64; 3]> = cube_a.iter().map(|v| [v[0] + 5.0, v[1], v[2]]).collect();
        let d = gjk_hull_distance(&cube_a, &cube_b);
        assert!(
            d > 0.0,
            "separated hulls should have positive distance: {d}"
        );
    }
    #[test]
    fn test_gjk_hull_distance_overlapping() {
        let cube: Vec<[f64; 3]> = vec![
            [-1.0, -1.0, -1.0],
            [1.0, -1.0, -1.0],
            [1.0, 1.0, -1.0],
            [-1.0, 1.0, -1.0],
            [-1.0, -1.0, 1.0],
            [1.0, -1.0, 1.0],
            [1.0, 1.0, 1.0],
            [-1.0, 1.0, 1.0],
        ];
        let d = gjk_hull_distance(&cube, &cube);
        assert_eq!(d, 0.0, "coincident hulls should have zero distance");
    }
    #[test]
    fn test_gjk_hull_distance_empty_returns_max() {
        let cube: Vec<[f64; 3]> = vec![[-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]];
        let d = gjk_hull_distance(&[], &cube);
        assert!(d > 1e10, "empty hull should return MAX distance: {d}");
    }
    #[test]
    fn test_gjk_point_inside_sphere() {
        let s = Sphere::new(2.0);
        let t = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let inside = gjk_point_inside_convex(Vec3::new(0.5, 0.0, 0.0), &s, &t);
        assert!(inside, "point at (0.5,0,0) should be inside sphere r=2");
    }
    #[test]
    fn test_gjk_point_outside_sphere() {
        let s = Sphere::new(0.5);
        let t = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let inside = gjk_point_inside_convex(Vec3::new(5.0, 0.0, 0.0), &s, &t);
        assert!(!inside, "point at (5,0,0) should be outside sphere r=0.5");
    }
    #[test]
    fn test_gjk_point_to_convex_distance() {
        let s = Sphere::new(1.0);
        let t = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let d = gjk_point_to_convex_distance(Vec3::new(5.0, 0.0, 0.0), &s, &t);
        assert!(d > 0.0, "distant point should have positive distance: {d}");
    }
    #[test]
    fn test_gjk_toi_angular_sweep_stationary_no_hit() {
        let s1 = Sphere::new(0.3);
        let s2 = Sphere::new(0.3);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(10.0, 0.0, 0.0));
        let zero = Vec3::new(0.0, 0.0, 0.0);
        let toi = gjk_toi_angular_sweep(&s1, &t1, zero, zero, &s2, &t2, zero, zero, 1.0, 4);
        assert!(
            toi.is_none(),
            "stationary separated spheres should have no TOI"
        );
    }
    #[test]
    fn test_gjk_toi_angular_sweep_linear_hit() {
        let s1 = Sphere::new(0.5);
        let s2 = Sphere::new(0.5);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(3.0, 0.0, 0.0));
        let v = Vec3::new(2.0, 0.0, 0.0);
        let zero = Vec3::new(0.0, 0.0, 0.0);
        let toi = gjk_toi_angular_sweep(&s1, &t1, v, zero, &s2, &t2, zero, zero, 2.0, 8);
        assert!(toi.is_some(), "approaching spheres should find TOI");
    }
    #[test]
    fn test_gjk_cast_ray_minkowski_hit() {
        let s1 = Sphere::new(1.0);
        let s2 = Sphere::new(1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(5.0, 0.0, 0.0));
        let origin = Vec3::new(0.0, 0.0, 0.0);
        let dir = Vec3::new(1.0, 0.0, 0.0);
        let result = gjk_cast_ray_minkowski(&s1, &t1, &s2, &t2, origin, dir, 20.0);
        let _ = result;
    }
    #[test]
    fn test_gjk_cast_ray_minkowski_no_hit() {
        let s1 = Sphere::new(0.1);
        let s2 = Sphere::new(0.1);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(100.0, 100.0, 0.0));
        let origin = Vec3::new(0.0, 0.0, 0.0);
        let dir = Vec3::new(1.0, 0.0, 0.0);
        let result = gjk_cast_ray_minkowski(&s1, &t1, &s2, &t2, origin, dir, 5.0);
        assert!(
            result.is_none(),
            "ray should not hit sphere far away at angle"
        );
    }
    #[test]
    fn test_gjk_distance_capsule_capsule_separated() {
        let c1 = Capsule::new(0.5, 1.0);
        let c2 = Capsule::new(0.5, 1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(6.0, 0.0, 0.0));
        let d = gjk_distance(&c1, &t1, &c2, &t2);
        assert!(
            d > 0.0,
            "separated capsules should have positive distance: {d}"
        );
    }
    #[test]
    fn test_gjk_distance_capsule_capsule_overlapping() {
        let c1 = Capsule::new(1.5, 1.0);
        let c2 = Capsule::new(1.5, 1.0);
        let t1 = Transform::from_position(Vec3::new(0.0, 0.0, 0.0));
        let t2 = Transform::from_position(Vec3::new(0.5, 0.0, 0.0));
        let d = gjk_distance(&c1, &t1, &c2, &t2);
        assert!(
            d <= 0.0,
            "overlapping capsules should have non-positive distance: {d}"
        );
    }
}