Fix Triangle<2>::winding_direction

For some reason, the Parry function gave a wrong result.
This commit is contained in:
Hanno Braun 2022-10-13 14:20:29 +02:00
parent 58329a83f6
commit cd1844fc4f

View File

@ -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<const D: usize> Triangle<D> {
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")
}
}