3D: no Inflate graphic handle where a nearer piece of its own face covers it

Where two pieces of an Inflate face overlap on the page, a graphic's center
mapped through the farther piece had a handle at a point the nearer piece
covers, and that point read back as a different offset. Every other piece
now counts as a cover, of either face. A piece drawn last is chosen over the
others by draw order, as the cover check orders them, so two overlapping
pieces drawn last map through the later one.
This commit is contained in:
dotCooCoo
2026-11-16 01:05:46 -08:00
parent 8f47eaa23f
commit 227b6b9984
2 changed files with 30 additions and 4 deletions
+12 -4
View File
@@ -1097,8 +1097,8 @@ impl MembraneFrame {
/// Point `p` of `face` in the art's plane mapped onto the page, or with `from_page` a page point
/// mapped into the art's plane, through the piece of that face that holds it and is nearest at
/// that point of the page. `None` when no piece the viewer sees holds it, or when a nearer piece
/// of the other face or a nearer cover hides that point of the page.
/// that point of the page. `None` when no piece the viewer sees holds it, or when another nearer
/// piece, of either face, or a nearer cover hides that point of the page.
fn map(&self, face: PlanarFace, p: Point, from_page: bool) -> Option<Point> {
let inside = |t: &[Point; 3], q: Point| {
let side = |a: Point, b: Point| (b - a).cross(q - a);
@@ -1113,7 +1113,15 @@ impl MembraneFrame {
}
let Some(q) = triangle_map(from, to).map(|m| m * p).filter(|q| q.is_finite()) else { continue };
let depth = piece.depth_at(if from_page { p } else { q });
if best.is_none_or(|(_, nearest, _)| depth > nearest) {
// A piece drawn last is drawn over every other one, and the later of two drawn last is
// drawn over the other, whatever their planes' depths.
let over = |(_, nearest, other): (Point, f64, &MembranePiece)| match (piece.depth == f64::MAX, other.depth == f64::MAX) {
(true, true) => piece.index > other.index,
(true, false) => true,
(false, true) => false,
(false, false) => depth > nearest,
};
if best.is_none_or(over) {
best = Some((q, depth, piece));
}
}
@@ -1131,7 +1139,7 @@ impl MembraneFrame {
let covered = self
.pieces
.iter()
.filter(|piece| piece.face != face)
.filter(|piece| !std::ptr::eq(*piece, shown))
.any(|piece| inside(&piece.page, at) && hides(piece.depth, piece.depth_at(at), piece.index))
|| self.covers.iter().any(|c| c.holds(at) && hides(c.depth, c.plane.and_then(|plane| plane.depth_at(at)).unwrap_or(c.depth), c.index));
(!covered).then_some(q)
@@ -1056,6 +1056,24 @@ fn overlapping_inflate_pieces_map_a_point_through_the_one_nearer_there() {
// Near the tilted piece's left corner it is the nearer one.
let (x, _) = frame.offset_at(PlanarFace::Front, Point::new(2.0, 0.5)).unwrap();
assert!((x - 2.0).abs() < 1e-6, "{x}");
// A graphic's center has a handle only where its own piece is the nearer one, and the handle
// maps back to the same offset.
let mark = |x: f64, y: f64| MappedGraphic::from_value(&json!({"symbol": "Mark", "face": "front", "x": x, "y": y})).unwrap();
assert!(frame.handle(&mark(10.0, 5.0)).is_none());
for (x, y) in [(2.0, 0.5), (110.0, 5.0)] {
let (at, _) = frame.handle(&mark(x, y)).unwrap();
let (bx, by) = frame.offset_at(PlanarFace::Front, at).unwrap();
assert!((bx - x).abs() < 1e-6 && (by - y).abs() < 1e-6, "{x} {y}: {bx} {by}");
}
// Of two overlapping pieces drawn last, the later one is drawn over the other, though the
// earlier one's plane is nearer.
let last = |shift: f64, offset: f64, index: usize| MembranePiece { index, ..piece(shift, f64::MAX, [0.0, 0.0, 1.0], offset) };
let pieces = vec![last(0.0, 10.0, 0), last(100.0, 0.0, 1)];
let frame = GraphicFrame::inflated(Rect::new(0.0, 0.0, 20.0, 20.0), MembraneFrame { pieces, covers: vec![] });
let (x, _) = frame.offset_at(PlanarFace::Front, Point::new(10.0, 5.0)).unwrap();
assert!((x - 110.0).abs() < 1e-6, "{x}");
assert!(frame.handle(&mark(10.0, 5.0)).is_none());
assert!(frame.handle(&mark(110.0, 5.0)).is_some());
}
/// A graphic on Inflate's back has no handle where a nearer piece of the front covers its center