From 0aa4b2f2fca445ea39afa67cd0168e20fb29e98a Mon Sep 17 00:00:00 2001 From: Livio Sidler <94077193+LS254@users.noreply.github.com> Date: Sun, 29 Nov 2026 12:41:31 +0100 Subject: [PATCH] M8, #2738: a chamfered or concave corner counts as cut off square where a clip or a box is tested against a view clip_covers and in_box tested such a corner as the arc of a round one, which cuts off less: a clipping frame's children showed in the corner the chamfer cuts off. --- crates/render/src/clip_cover_tests.rs | 20 ++++++++++++++++++++ crates/render/src/draw.rs | 12 +++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/crates/render/src/clip_cover_tests.rs b/crates/render/src/clip_cover_tests.rs index 8e4deebe1..d13f25c9a 100644 --- a/crates/render/src/clip_cover_tests.rs +++ b/crates/render/src/clip_cover_tests.rs @@ -117,3 +117,23 @@ fn a_view_inside_clipping_frames_holds_no_layer_for_them() { NO_COVER_SHORTCUTS.with(|f| f.set(false)); assert!(before >= u64::from(v.width) * u64::from(v.height) * 4, "as it was: {before} bytes held"); } + +/// A chamfered or concave corner cuts off more than a round one of the same radius: a view +/// between the two is outside the frame, and the frame's children don't show there. +#[test] +fn a_view_in_a_corner_a_chamfer_cuts_off_shows_nothing_of_the_frame() { + for style in [figcraft_geom::CornerStyle::Chamfer, figcraft_geom::CornerStyle::Concave] { + let mut d = Document::new("corner styles"); + let page = d.first_page().unwrap(); + let f = d.create(page, NodeKind::Frame, "Frame", 0.0, 0.0, 1000.0, 1000.0).unwrap(); + let n = d.get_mut(f).unwrap(); + (n.corners.radii, n.corners.style, n.clip) = ([100.0; 4], style, true); + let c = d.create(f, NodeKind::Rectangle, "Child", 0.0, 0.0, 1000.0, 1000.0).unwrap(); + d.get_mut(c).unwrap().fills = vec![Paint::solid(Color::from_hex("E03030").unwrap())]; + // Inside the arc a round corner would have, outside the chamfer and the concave corner. + let v = View { origin: (30.0, 30.0), scale: 1.0, width: 10, height: 10 }; + let (new, old) = both(&d, page, &v); + assert_eq!(new.data(), old.data(), "{style:?}"); + assert_eq!(new.data().get(..4), Some(&[255u8, 255, 255, 255][..]), "{style:?}: the page shows"); + } +} diff --git a/crates/render/src/draw.rs b/crates/render/src/draw.rs index 340d25500..9ea8ae11e 100644 --- a/crates/render/src/draw.rs +++ b/crates/render/src/draw.rs @@ -1330,8 +1330,8 @@ fn on_whole_pixels(r: Rect, size: (u32, u32)) -> bool { } /// Whether the box of frame `n` (its rounded corners cut off), drawn at `xf`, takes in every -/// pixel of a `size` pixmap: its clip then cuts nothing there. Errs towards `false`: smoothed -/// corners count as cut off square. +/// pixel of a `size` pixmap: its clip then cuts nothing there. Errs towards `false`: smoothed, +/// chamfered and concave corners count as cut off square. pub(crate) fn clip_covers(n: &Node, xf: Affine, size: (u32, u32)) -> bool { #[cfg(test)] if NO_COVER_SHORTCUTS.with(std::cell::Cell::get) { @@ -1343,7 +1343,8 @@ pub(crate) fn clip_covers(n: &Node, xf: Affine, size: (u32, u32)) -> bool { return false; } let max_r = w.min(h) / 2.0; - let smooth = if n.corners.smoothing > 0.0 || !n.corners.smoothing.is_finite() { 1.0 } else { 0.0 }; + // Only a plain round corner is tested as its arc: every other kind cuts off more. + let smooth = if n.corners.smoothing > 0.0 || !n.corners.smoothing.is_finite() || !n.corners.style.is_round() { 1.0 } else { 0.0 }; // Top-left, top-right, bottom-right, bottom-left: the corner and its radius. let r = n.corners.radii.map(|r| if r.is_finite() { r.clamp(0.0, max_r) } else { max_r }); let corners = [(0.0, 0.0, r[0]), (w, 0.0, r[1]), (w, h, r[2]), (0.0, h, r[3])]; @@ -1364,14 +1365,15 @@ pub(crate) fn clip_covers(n: &Node, xf: Affine, size: (u32, u32)) -> bool { } /// Whether point `p` (local) lies in the box of `n`, its rounded corners cut off. Errs towards -/// `false`: smoothed corners count as cut off square. +/// `false`: smoothed, chamfered and concave corners count as cut off square. pub(crate) fn in_box(n: &Node, p: figcraft_geom::Point) -> bool { let (w, h) = (n.width, n.height); if !(w.is_finite() && h.is_finite() && w > 0.0 && h > 0.0 && p.x >= 0.0 && p.y >= 0.0 && p.x <= w && p.y <= h) { return false; } let max_r = w.min(h) / 2.0; - let smooth = if n.corners.smoothing > 0.0 || !n.corners.smoothing.is_finite() { 1.0 } else { 0.0 }; + // Only a plain round corner is tested as its arc: every other kind cuts off more. + let smooth = if n.corners.smoothing > 0.0 || !n.corners.smoothing.is_finite() || !n.corners.style.is_round() { 1.0 } else { 0.0 }; // Top-left, top-right, bottom-right, bottom-left: the corner and its radius. let r = n.corners.radii.map(|r| if r.is_finite() { r.clamp(0.0, max_r) } else { max_r }); [(0.0, 0.0, r[0]), (w, 0.0, r[1]), (w, h, r[2]), (0.0, h, r[3])].iter().all(|(cx, cy, r)| {