Skip to content

Commit

Permalink
fix incorrect non-solid point projection called by project_local_poin…
Browse files Browse the repository at this point in the history
…t_and_get_location (#195)

* Fix d_abc and d_bc computation in project_local_point_and_get_location
* Fix #194
  • Loading branch information
wlinna committed May 1, 2024
1 parent 5af969b commit 75ade55
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/parry2d/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ extern crate nalgebra as na;
extern crate parry2d;

mod geometry;
mod query;
1 change: 1 addition & 0 deletions crates/parry2d/tests/query/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod point_triangle;
20 changes: 20 additions & 0 deletions crates/parry2d/tests/query/point_triangle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use parry2d::{math::Point, query::PointQuery, shape::Triangle};

#[test]
fn project_local_point_point_on_ab() {
let verts = [
Point::new(2.0, 1.0),
Point::new(0.0, 1.0),
Point::new(1.0, 0.0),
];
let tri1 = Triangle::new(verts[0], verts[1], verts[2]);
let tri2 = Triangle::new(verts[2], verts[0], verts[1]);

let query_pt = Point::new(1.4, 1.0);

let proj1 = tri1.project_local_point(&query_pt, false); // Used to fail on 0.14 and earlier
let proj2 = tri2.project_local_point(&query_pt, false);

assert_eq!(proj1.point, proj2.point);
assert_eq!(proj1.point, query_pt);
}
4 changes: 2 additions & 2 deletions src/query/point/point_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ impl PointQueryWithLocation for Triangle {

let bc = c - b;
let d_ab = ap.norm_squared() - (ab.norm_squared() * v * v);
let d_ac = ap.norm_squared() - (ac.norm_squared() * u * u);
let d_bc = bp.norm_squared() - (bc.norm_squared() * w * w);
let d_ac = ap.norm_squared() - (ac.norm_squared() * w * w);
let d_bc = bp.norm_squared() - (bc.norm_squared() * u * u);

let proj;
let loc;
Expand Down

0 comments on commit 75ade55

Please sign in to comment.