From 894f977e875f4f3adfd51395f444c33e9f8c0f6e Mon Sep 17 00:00:00 2001 From: William Linna Date: Wed, 1 May 2024 13:41:06 +0300 Subject: [PATCH 1/3] Fixes d_abc and d_bc computation in project_local_point_and_get_location Fixes https://github.com/dimforge/parry/issues/194 --- crates/parry2d/tests/lib.rs | 1 + crates/parry2d/tests/query/mod.rs | 1 + crates/parry2d/tests/query/point_triangle.rs | 16 ++++++++++++++++ src/query/point/point_triangle.rs | 4 ++-- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 crates/parry2d/tests/query/mod.rs create mode 100644 crates/parry2d/tests/query/point_triangle.rs 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; From 37eae5726eabf16da3ada18cb2bdcaf583de9c86 Mon Sep 17 00:00:00 2001 From: William Linna Date: Wed, 1 May 2024 13:46:42 +0300 Subject: [PATCH 2/3] Fix formatting --- crates/parry2d/tests/query/point_triangle.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/parry2d/tests/query/point_triangle.rs b/crates/parry2d/tests/query/point_triangle.rs index 9a6eec6e..75fde225 100644 --- a/crates/parry2d/tests/query/point_triangle.rs +++ b/crates/parry2d/tests/query/point_triangle.rs @@ -2,7 +2,11 @@ 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 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]); From 0daae365c19194a56c85c9fb1c9a6881e50c99be Mon Sep 17 00:00:00 2001 From: William Linna Date: Wed, 1 May 2024 13:49:29 +0300 Subject: [PATCH 3/3] Fix formatting --- crates/parry2d/tests/query/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/parry2d/tests/query/mod.rs b/crates/parry2d/tests/query/mod.rs index b2193c08..b06213c4 100644 --- a/crates/parry2d/tests/query/mod.rs +++ b/crates/parry2d/tests/query/mod.rs @@ -1 +1 @@ -mod point_triangle; \ No newline at end of file +mod point_triangle;