3D: Inflate graphics keep membrane corners on an ear's new edge

With corners kept along a cell's edges, ear clipping could still take an ear whose new edge ran through kept corners, leaving them off every triangle and the triangles beside them flat. Such an ear is now passed over. docs/three-d.md now says that a membrane cell that cannot be cut into triangles makes the object draw without its graphics, and commands refuse them.
This commit is contained in:
dotCooCoo
2026-11-16 00:13:32 -08:00
parent f4d7260c62
commit f2376b05f7
3 changed files with 21 additions and 1 deletions
+5
View File
@@ -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];
}
}
+14
View File
@@ -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::<f64>() - 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);
+2 -1
View File
@@ -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