From 7bf24041dbaf6c0d0b95f9ee07c2ac4f08da5edd Mon Sep 17 00:00:00 2001 From: "Ayberk A." <105879357+AyberkA0@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:18:36 +0300 Subject: [PATCH] fix(engine): box a turned outline by its own points Review: the outline bounds turned the unturned box's corners, so a turned or skewed shape was measured bigger than it is. The points are now carried into stage space first, then boxed. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/selection.rs | 4 +++- crates/engine/src/tests.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/selection.rs b/crates/engine/src/selection.rs index b7bd3d4a..8e84b7ee 100644 --- a/crates/engine/src/selection.rs +++ b/crates/engine/src/selection.rs @@ -242,7 +242,9 @@ impl Session { pub fn element_outline_bounds_on(&self, layer: LayerId, id: ElementId) -> Rect { let mut r = Rect::EMPTY; for item in self.display_list().items.iter().filter(|i| i.element == id && i.layer == layer) { - r = r.union(&item.path.bounds().transformed(&item.transform)); + // The points carried into stage space, then boxed: a turned or skewed outline's box + // is no bigger than the outline. + r = r.union(&item.path.transformed(&item.transform).bounds()); } r } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cc8a4451..e317beee 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -392,6 +392,15 @@ fn align_lines_up_outlines_not_stroke_edges() { assert!(o.min.x.abs() < 0.01 && o.min.y.abs() < 0.01, "the outline's corner is on the stage's (object: {object}): {o:?}"); assert!(c.min.x < o.min.x && c.min.y < o.min.y, "the stroke hangs over the edge (object: {object})"); } + // A turned outline is measured by its own points, not by its unturned box turned with it. + let mut s = Session::default(); + run(&mut s, "draw.ellipse", json!({"x": 100, "y": 100, "w": 200, "h": 40, "stroke": null, "object": true})); + run(&mut s, "edit.select_all", json!({})); + run(&mut s, "element.set_transform", json!({"rotation": 45})); + let (l, e) = s.selected_elements()[0].clone(); + let outline = s.element_outline_bounds_on(l, e.id); + let boxed = s.display_list().items.iter().filter(|i| i.element == e.id).fold(Rect::EMPTY, |r, i| r.union(&i.path.bounds().transformed(&i.transform))); + assert!(outline.width() < boxed.width() - 1.0, "{outline:?} inside {boxed:?}"); } #[test]