Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes d_abc and d_bc computation in project_local_point_and_get_location #195

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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