From cd1844fc4f735e51ea5477dd6b94fd0b9cb3a9ae Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 14:20:29 +0200 Subject: [PATCH] Fix `Triangle<2>::winding_direction` For some reason, the Parry function gave a wrong result. --- crates/fj-math/src/triangle.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/fj-math/src/triangle.rs b/crates/fj-math/src/triangle.rs index cbafd436e..2c3cffb32 100644 --- a/crates/fj-math/src/triangle.rs +++ b/crates/fj-math/src/triangle.rs @@ -1,4 +1,4 @@ -use parry2d_f64::utils::point_in_triangle::{corner_direction, Orientation}; +use parry2d_f64::utils::point_in_triangle::Orientation; use parry3d_f64::query::{Ray, RayCast as _}; use crate::Vector; @@ -59,8 +59,17 @@ impl Triangle { impl Triangle<2> { /// Returns the direction of the line through the points of the triangle. pub fn winding_direction(&self) -> Winding { - let [v0, v1, v2] = self.points.map(|point| point.to_na()); - corner_direction(&v0, &v1, &v2).into() + let [pa, pb, pc] = self.points.map(|point| point.into()); + let orient2d = robust_predicates::orient2d(&pa, &pb, &pc); + + if orient2d < 0. { + return Winding::Cw; + } + if orient2d > 0. { + return Winding::Ccw; + } + + unreachable!("not a triangle") } }