mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-15 21:00:20 +00:00
Merge pull request #1217 from hannobraun/winding
Fix `Triangle::winding`
This commit is contained in:
commit
e668c05afc
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1026,6 +1026,7 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
"parry2d-f64",
|
"parry2d-f64",
|
||||||
"parry3d-f64",
|
"parry3d-f64",
|
||||||
|
"robust-predicates",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -22,7 +22,7 @@ pub fn triangulate(
|
|||||||
v2.point_surface,
|
v2.point_surface,
|
||||||
])
|
])
|
||||||
.expect("invalid triangle")
|
.expect("invalid triangle")
|
||||||
.winding_direction();
|
.winding();
|
||||||
|
|
||||||
let required_winding = match coord_handedness {
|
let required_winding = match coord_handedness {
|
||||||
Handedness::LeftHanded => Winding::Cw,
|
Handedness::LeftHanded => Winding::Cw,
|
||||||
|
@ -17,3 +17,4 @@ nalgebra = "0.31.2"
|
|||||||
num-traits = "0.2.15"
|
num-traits = "0.2.15"
|
||||||
parry2d-f64 = "0.10.0"
|
parry2d-f64 = "0.10.0"
|
||||||
parry3d-f64 = "0.10.0"
|
parry3d-f64 = "0.10.0"
|
||||||
|
robust-predicates = "0.1.3"
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use parry2d_f64::utils::point_in_triangle::{corner_direction, Orientation};
|
|
||||||
use parry3d_f64::query::{Ray, RayCast as _};
|
use parry3d_f64::query::{Ray, RayCast as _};
|
||||||
|
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
@ -58,9 +57,21 @@ impl<const D: usize> Triangle<D> {
|
|||||||
|
|
||||||
impl Triangle<2> {
|
impl Triangle<2> {
|
||||||
/// Returns the direction of the line through the points of the triangle.
|
/// Returns the direction of the line through the points of the triangle.
|
||||||
pub fn winding_direction(&self) -> Winding {
|
pub fn winding(&self) -> Winding {
|
||||||
let [v0, v1, v2] = self.points.map(|point| point.to_na());
|
let [pa, pb, pc] = self.points.map(|point| point.into());
|
||||||
corner_direction(&v0, &v1, &v2).into()
|
let orient2d = robust_predicates::orient2d(&pa, &pb, &pc);
|
||||||
|
|
||||||
|
if orient2d < 0. {
|
||||||
|
return Winding::Cw;
|
||||||
|
}
|
||||||
|
if orient2d > 0. {
|
||||||
|
return Winding::Ccw;
|
||||||
|
}
|
||||||
|
|
||||||
|
unreachable!(
|
||||||
|
"Points don't form a triangle, but this was verified in the \
|
||||||
|
constructor."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,16 +133,6 @@ pub enum Winding {
|
|||||||
Cw,
|
Cw,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Orientation> for Winding {
|
|
||||||
fn from(o: Orientation) -> Self {
|
|
||||||
match o {
|
|
||||||
Orientation::Ccw => Winding::Ccw,
|
|
||||||
Orientation::Cw => Winding::Cw,
|
|
||||||
Orientation::None => unreachable!("not a triangle"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{Point, Vector};
|
use crate::{Point, Vector};
|
||||||
|
Loading…
Reference in New Issue
Block a user