Skip to content

Commit

Permalink
Add tests to ensure project_local_point_and_get_feature works from ou…
Browse files Browse the repository at this point in the history
…tside
  • Loading branch information
wlinna committed May 1, 2024
1 parent ea29ba5 commit edeca5e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions crates/parry2d/tests/query/point_composite_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,46 @@ fn project_local_point_and_get_feature_gets_the_enclosing_triangle() {
assert_eq!(proj.is_inside, is_inside_correct);
assert_eq!(feat.unwrap_face(), correct_tri_idx);
}

#[test]
fn project_local_point_and_get_feature_projects_correctly_from_outside() {
let vertices = vec![
Point2::new(0.0, 1.0),
Point2::new(0.0, 0.0),
Point2::new(1.0, 0.0),
Point2::new(1.0, 1.0),
];

let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]);

{
let query_pt = Point2::new(-1.0, 0.0); // Inside the top-right triangle (index 1)

let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt);

let correct_tri_idx = 0;
let correct_tri = mesh.triangle(correct_tri_idx);

let is_inside_correct = correct_tri.contains_local_point(&query_pt);

assert_eq!(is_inside_correct, false);
assert_eq!(proj.is_inside, is_inside_correct);
assert_eq!(proj.point, Point2::origin());
assert_eq!(feat.unwrap_face(), correct_tri_idx);
}
{
let query_pt = Point2::new(0.5, 2.0); // Inside the top-right triangle (index 1)

let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt);

let correct_tri_idx = 1;
let correct_tri = mesh.triangle(correct_tri_idx);

let is_inside_correct = correct_tri.contains_local_point(&query_pt);

assert_eq!(is_inside_correct, false);
assert_eq!(proj.is_inside, is_inside_correct);
assert_eq!(proj.point, Point2::new(0.5, 1.0));
assert_eq!(feat.unwrap_face(), correct_tri_idx);
}
}

0 comments on commit edeca5e

Please sign in to comment.