-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathproximity_query2d.rs
26 lines (21 loc) · 1.03 KB
/
proximity_query2d.rs
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
extern crate nalgebra as na;
use na::{Isometry2, Vector2};
use ncollide2d::query::{self, Proximity};
use ncollide2d::shape::{Ball, Cuboid};
fn main() {
let cuboid = Cuboid::new(Vector2::new(1.0, 1.0));
let ball = Ball::new(1.0);
let margin = 1.0;
let cuboid_pos = na::one();
let ball_pos_intersecting = Isometry2::new(Vector2::new(1.0, 1.0), na::zero());
let ball_pos_within_margin = Isometry2::new(Vector2::new(2.0, 2.0), na::zero());
let ball_pos_disjoint = Isometry2::new(Vector2::new(3.0, 3.0), na::zero());
let prox_intersecting =
query::proximity(&ball_pos_intersecting, &ball, &cuboid_pos, &cuboid, margin);
let prox_within_margin =
query::proximity(&ball_pos_within_margin, &ball, &cuboid_pos, &cuboid, margin);
let prox_disjoint = query::proximity(&ball_pos_disjoint, &ball, &cuboid_pos, &cuboid, margin);
assert_eq!(prox_intersecting, Proximity::Intersecting);
assert_eq!(prox_within_margin, Proximity::WithinMargin);
assert_eq!(prox_disjoint, Proximity::Disjoint);
}