Fix assumption that is no longer valid

This commit is contained in:
Hanno Braun 2025-03-21 21:35:21 +01:00
parent e74020f960
commit 769cad1e3e
2 changed files with 10 additions and 8 deletions

View File

@ -61,7 +61,12 @@ pub fn triangulate(
Handedness::LeftHanded => Winding::Cw,
Handedness::RightHanded => Winding::Ccw,
};
let actual_winding = triangle.winding();
let Some(actual_winding) = triangle.winding() else {
unreachable!(
"Just asserted that the triangle is valid. Therefore it must \
have a winding."
);
};
let triangle = if actual_winding == required_winding {
[v0, v1, v2]

View File

@ -69,7 +69,7 @@ impl<const D: usize> Triangle<D> {
impl Triangle<2> {
/// # Compute the winding of the triangle
pub fn winding(&self) -> Winding {
pub fn winding(&self) -> Option<Winding> {
let [pa, pb, pc] = self.points.map(|point| robust::Coord {
x: point.u,
y: point.v,
@ -77,16 +77,13 @@ impl Triangle<2> {
let orient2d = robust::orient2d(pa, pb, pc);
if orient2d < 0. {
return Winding::Cw;
return Some(Winding::Cw);
}
if orient2d > 0. {
return Winding::Ccw;
return Some(Winding::Ccw);
}
unreachable!(
"Points don't form a triangle, but this was verified in the \
constructor."
)
None
}
}