distance_query3d/
distance_query3d.rs

1#[macro_use]
2extern crate approx; // for relative_eq!
3
4use parry3d::math::{Pose, Vector};
5use parry3d::query;
6use parry3d::shape::{Ball, Cuboid};
7
8fn main() {
9    let cuboid = Cuboid::new(Vector::new(1.0, 1.0, 1.0));
10    let ball = Ball::new(1.0);
11
12    let cuboid_pos = Pose::identity();
13    let ball_pos_intersecting = Pose::translation(0.0, 1.0, 0.0);
14    let ball_pos_disjoint = Pose::translation(0.0, 3.0, 0.0);
15
16    let dist_intersecting =
17        query::distance(&ball_pos_intersecting, &ball, &cuboid_pos, &cuboid).unwrap();
18    let dist_disjoint = query::distance(&ball_pos_disjoint, &ball, &cuboid_pos, &cuboid).unwrap();
19
20    assert_eq!(dist_intersecting, 0.0);
21    assert!(relative_eq!(dist_disjoint, 1.0, epsilon = 1.0e-7));
22}