diff --git a/CHANGELOG.md b/CHANGELOG.md index b1d56e7c..976c9929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,14 @@ ## Unreleased +### Fix + +- Fix `utils::point_in_poly2d` for self-intersecting polygons. + ### Added -- `TriMesh` now implements `Shape::feature_normal_at_point` to retrieve the normal of a face, when passing a `FeatureId::Face`. +- `TriMesh` now implements `Shape::feature_normal_at_point` to retrieve the normal of a face, when passing a + `FeatureId::Face`. ## v0.17.1 @@ -283,7 +288,8 @@ This version was yanked. See the release notes for 0.13.3 instead. for most shapes. - Add the `parallel` feature that enables methods for the parallel traversal of Qbvh trees: `Qbvh::traverse_bvtt_parallel`, - `Qbvh::traverse_bvtt_node_parallel`, `Qbvh::traverse_depth_first_parallel`, `Qbvh::traverse_depth_first_node_parallel`. + `Qbvh::traverse_bvtt_node_parallel`, `Qbvh::traverse_depth_first_parallel`, + `Qbvh::traverse_depth_first_node_parallel`. ### Fixed diff --git a/src/utils/point_in_poly2d.rs b/src/utils/point_in_poly2d.rs index c57f77e4..84b91d8f 100644 --- a/src/utils/point_in_poly2d.rs +++ b/src/utils/point_in_poly2d.rs @@ -48,14 +48,15 @@ pub fn point_in_poly2d(pt: &Point2, poly: &[Point2]) -> bool { let seg_dir = b - a; let dpt = pt - a; let perp = dpt.perp(&seg_dir); + winding += match (dpt.y >= 0.0, b.y > pt.y) { (true, true) if perp < 0.0 => 1, - (false, false) if perp > 0.0 => -1, + (false, false) if perp > 0.0 => 1, _ => 0, }; } - winding != 0 + winding % 2 == 1 } #[cfg(test)]