diff --git a/crates/three-d/src/mesh.rs b/crates/three-d/src/mesh.rs index d0ce362f1e..fbc5546d18 100644 --- a/crates/three-d/src/mesh.rs +++ b/crates/three-d/src/mesh.rs @@ -408,6 +408,11 @@ fn clip(ring: &[Corner], out: &mut Vec<[V3; 3]>, work: &mut usize, keep_straight ear = false; break; } + // A kept corner on the ear's new edge would be left off every triangle. + if keep_straight && touches((p.x, p.y), (pc.x, pc.y), (pa.x, pa.y)) { + ear = false; + break; + } k = next[k]; } } diff --git a/crates/three-d/src/mesh/tests.rs b/crates/three-d/src/mesh/tests.rs index a4db1d77fb..9980e900d1 100644 --- a/crates/three-d/src/mesh/tests.rs +++ b/crates/three-d/src/mesh/tests.rs @@ -191,6 +191,20 @@ fn flat_triangles_keep_corners_that_lie_along_an_edge() { assert!(work > 0); } +#[test] +fn flat_triangles_keep_corners_on_the_edge_an_ear_would_cut() { + // The first ear's new edge runs along the bottom, through its two middle corners. + let p = |x: f64, y: f64| Point::new(x, y); + let outline = vec![p(0.0, 3.0), p(0.0, 0.0), p(1.0, 0.0), p(2.0, 0.0), p(3.0, 0.0)]; + let mut work = 0; + let triangles = flat_triangles(std::slice::from_ref(&outline), &mut work, usize::MAX).unwrap(); + let area = |t: &[Point; 3]| ((t[1].x - t[0].x) * (t[2].y - t[0].y) - (t[1].y - t[0].y) * (t[2].x - t[0].x)) / 2.0; + assert!((triangles.iter().map(area).sum::() - 4.5).abs() < 1e-9); + for q in &outline { + assert!(triangles.iter().any(|t| t.contains(q)), "{q:?} is no triangle's corner"); + } +} + #[test] fn flat_triangles_stop_at_their_budget() { let p = |x: f64, y: f64| Point::new(x, y); diff --git a/docs/three-d.md b/docs/three-d.md index 45531ad4df..d01b6ab6de 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -508,7 +508,8 @@ These rules are VectorCraft's own: not drawn); it reads the right way round from behind, and Twist and Taper turn and shrink its graphics with it. The membrane is cut into triangles, and each one draws the part of the graphic that falls on it, shaded as that triangle is shaded and drawn only where the surface's outside faces the viewer; nearer triangles drawn - after it cover it. A cell of the membrane that cannot be cut into triangles takes no graphic. Every solid of + after it cover it. When a cell of the membrane cannot be cut into triangles, the object draws without its + graphics and commands refuse them, as when the triangles take more faces than a 3D effect draws. Every solid of the object (a fill's, and a stroke's outline) carries the graphics. The handle sits on the point of the puffed face above the graphic's center, and only where the viewer sees that face. The cutting into straight pieces, the seam strokes and the limits below are those of Revolve; when the triangles take more faces than a 3D