diff --git a/crates/parry2d/tests/lib.rs b/crates/parry2d/tests/lib.rs index 206d0874..4557202e 100644 --- a/crates/parry2d/tests/lib.rs +++ b/crates/parry2d/tests/lib.rs @@ -4,3 +4,4 @@ extern crate nalgebra as na; extern crate parry2d; mod geometry; +mod query; diff --git a/crates/parry2d/tests/query/mod.rs b/crates/parry2d/tests/query/mod.rs new file mode 100644 index 00000000..b2193c08 --- /dev/null +++ b/crates/parry2d/tests/query/mod.rs @@ -0,0 +1 @@ +mod point_triangle; \ No newline at end of file diff --git a/crates/parry2d/tests/query/point_triangle.rs b/crates/parry2d/tests/query/point_triangle.rs new file mode 100644 index 00000000..9a6eec6e --- /dev/null +++ b/crates/parry2d/tests/query/point_triangle.rs @@ -0,0 +1,16 @@ +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); +} diff --git a/src/query/point/point_triangle.rs b/src/query/point/point_triangle.rs index a37a0c8f..09895198 100644 --- a/src/query/point/point_triangle.rs +++ b/src/query/point/point_triangle.rs @@ -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;