From eb7f64d5b3311f5995f4ccebb288b6a0f7b2e244 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 18:25:27 -0800 Subject: [PATCH] Transform: a shape turn past the coordinate limit is an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - object.setLiveShape checks every shape named in `ids` against the coordinate limit (±4,000,000 pt) after the edit, so a rectangle, ellipse or polygon that is not selected can no longer be turned out of range; the call is an error and changes nothing. - LiveShape::set_shape_angle brings the angle into [0, 360) before it works out the turn, so a very large angle reaches the same final angle from any starting angle. - The params text and docs/mcp.md say that `null` counts as an omitted key, that a pixel-aligned shape goes back on the pixel grid after the turn, and that a turn out of range is an error. - The panel test reads the Rotate and Angle fields by name, and checks that the Angle field is empty for mixed angles. --- crates/doc/src/node/live_shape.rs | 2 ++ crates/doc/src/node/tests.rs | 14 ++++++++ crates/engine/src/cmd/object/commands.rs | 2 +- crates/engine/src/cmd/object/shape.rs | 5 +++ crates/engine/src/tests/livecorners.rs | 22 +++++++++++++ crates/ui-egui/src/panels/transform/tests.rs | 34 +++++++++++++++----- docs/mcp.md | 11 ++++--- 7 files changed, 77 insertions(+), 13 deletions(-) diff --git a/crates/doc/src/node/live_shape.rs b/crates/doc/src/node/live_shape.rs index 42544be99b..0a17301331 100644 --- a/crates/doc/src/node/live_shape.rs +++ b/crates/doc/src/node/live_shape.rs @@ -164,6 +164,8 @@ impl LiveShape { if !angle.is_finite() { return; } + // Brought into [0, 360) first: `now - angle` loses `now` for a very large angle. + let angle = angle.rem_euclid(360.0); let (xf, local) = match self { LiveShape::Rectangle { w, h, xf, .. } | LiveShape::Ellipse { w, h, xf, .. } => (xf, Point::new(*w / 2.0, *h / 2.0)), LiveShape::Polygon { xf, .. } => (xf, Point::ZERO), diff --git a/crates/doc/src/node/tests.rs b/crates/doc/src/node/tests.rs index 789e0f66b2..cdcbf2cf85 100644 --- a/crates/doc/src/node/tests.rs +++ b/crates/doc/src/node/tests.rs @@ -184,6 +184,20 @@ fn a_polygon_reports_and_takes_its_radius_angle_and_equal_sides() { assert_eq!((e.polygon_radius(), e.polygon_angle()), (None, None)); } +/// A very large angle turns a rectangle to that angle modulo 360, whatever angle it had before. +#[test] +fn a_shape_takes_a_very_large_angle() { + let close = |a: f64, b: f64| (a - b).abs() < 1e-6; + let want = 1e20f64.rem_euclid(360.0); + for turned in [0.0, 90.0] { + let xf = Affine::translate((50.0, 50.0)) * Affine::rotate(-f64::to_radians(turned)); + let mut r = LiveShape::Rectangle { w: 100.0, h: 50.0, radii: [0.0; 4], kinds: Default::default(), radii_relative: false, xf }; + assert!(close(r.shape_angle().unwrap(), turned), "{:?}", r.shape_angle()); + r.set_shape_angle(1e20); + assert!(close(r.shape_angle().unwrap(), want), "from {turned}°: {:?}, not {want}", r.shape_angle()); + } +} + /// A node holding a live rectangle (`w` × `h`, all radii `r`, placed by `xf`) and its path. fn live_rect(w: f64, h: f64, r: f64, xf: Affine) -> Node { let live = LiveShape::Rectangle { w, h, radii: [r; 4], kinds: Default::default(), radii_relative: false, xf }; diff --git a/crates/engine/src/cmd/object/commands.rs b/crates/engine/src/cmd/object/commands.rs index d0ab36bfd0..39e9d3eab5 100644 --- a/crates/engine/src/cmd/object/commands.rs +++ b/crates/engine/src/cmd/object/commands.rs @@ -305,7 +305,7 @@ pub fn specs() -> Vec { "Live Shape Properties", [], None, - "{id?, ids?, radius?: pt (or % of each corner's maximum when `relativeRadii` is true), kind?: \"round\"|\"invertedRound\"|\"chamfer\", relativeRadii?: bool (Relative rounding, as in the reference app: store radii as fractions of each corner's maximum so they scale with the shape), corners?: [i…], items?: [{id, corners?: [i…]}] (several objects, each with its own corners, in place of ids and corners: the canvas's corner widgets across a selection), sides?: n, polygonAngle?: degrees (counter-clockwise from its first vertex straight up), polygonRadius?: pt (centre to vertex), sideLength?: pt (sets the radius), makeSidesEqual?: true (a polygon scaled unevenly: drops the uneven scale and shear, keeping its centre, angle and mean radius), pieStart?, pieEnd?: degrees (an ellipse's pie, counter-clockwise from 3 o'clock; 0 to 360 is the whole ellipse), invertPie?: true (swaps them: the other part of the ellipse), constrainPie?: bool (Constrain Pie Angle: with one of pieStart and pieEnd, not both and not with invertPie, the other angle moves by as much, so each ellipse keeps its span), lineLength?: pt (a live line's length, above 0; its first end stays), lineAngle?: degrees (a live line's angle, counter-clockwise from 3 o'clock, from its first end to its second; it turns about its midpoint), rectangleAngle?: degrees (a live rectangle's, counterclockwise from level), ellipseAngle?: degrees (a live ellipse's, counterclockwise from level; its pie turns with it)} (rectangleAngle, ellipseAngle and polygonAngle turn each shape of that kind about its own center and leave other objects as they are; an angle that is not a number is an error; Live Corners on any path: radius and kind set its corners (anchors that aren't smooth, where two sides, straight or curved (#1144), meet at an angle): `corners` (anchor indices of the path with its corners uncut, counting every subpath's anchors in order: a rectangle's 0 top-left, 1 top-right, 2 bottom-right, 3 bottom-left; a polygon's from the first vertex clockwise), else the corners with a Direct-Selected anchor, else every corner; each radius is drawn no larger than half the corner's shorter side allows; a path that isn't a live shape keeps its uncut outline so its corners stay editable, and is plain again once none is cut; sides: a polygon's, which keep the radius they shared; the polygon params apply in that order: sides, makeSidesEqual, polygonAngle, then sideLength or else polygonRadius; a line's lineLength applies before its lineAngle)", + "{id?, ids?, radius?: pt (or % of each corner's maximum when `relativeRadii` is true), kind?: \"round\"|\"invertedRound\"|\"chamfer\", relativeRadii?: bool (Relative rounding, as in the reference app: store radii as fractions of each corner's maximum so they scale with the shape), corners?: [i…], items?: [{id, corners?: [i…]}] (several objects, each with its own corners, in place of ids and corners: the canvas's corner widgets across a selection), sides?: n, polygonAngle?: degrees (counter-clockwise from its first vertex straight up), polygonRadius?: pt (centre to vertex), sideLength?: pt (sets the radius), makeSidesEqual?: true (a polygon scaled unevenly: drops the uneven scale and shear, keeping its centre, angle and mean radius), pieStart?, pieEnd?: degrees (an ellipse's pie, counter-clockwise from 3 o'clock; 0 to 360 is the whole ellipse), invertPie?: true (swaps them: the other part of the ellipse), constrainPie?: bool (Constrain Pie Angle: with one of pieStart and pieEnd, not both and not with invertPie, the other angle moves by as much, so each ellipse keeps its span), lineLength?: pt (a live line's length, above 0; its first end stays), lineAngle?: degrees (a live line's angle, counter-clockwise from 3 o'clock, from its first end to its second; it turns about its midpoint), rectangleAngle?: degrees (a live rectangle's, counterclockwise from level), ellipseAngle?: degrees (a live ellipse's, counterclockwise from level; its pie turns with it)} (rectangleAngle, ellipseAngle and polygonAngle turn each shape of that kind about its own center and leave other objects as they are; a pixel-aligned shape then goes back on the pixel grid, as after other edits, which can move its center or change its size; an angle that is not a number is an error, and `null` counts as an omitted key; a shape that a turn would take past the coordinate limit (±4,000,000 pt) is an error that changes nothing; Live Corners on any path: radius and kind set its corners (anchors that aren't smooth, where two sides, straight or curved (#1144), meet at an angle): `corners` (anchor indices of the path with its corners uncut, counting every subpath's anchors in order: a rectangle's 0 top-left, 1 top-right, 2 bottom-right, 3 bottom-left; a polygon's from the first vertex clockwise), else the corners with a Direct-Selected anchor, else every corner; each radius is drawn no larger than half the corner's shorter side allows; a path that isn't a live shape keeps its uncut outline so its corners stay editable, and is plain again once none is cut; sides: a polygon's, which keep the radius they shared; the polygon params apply in that order: sides, makeSidesEqual, polygonAngle, then sideLength or else polygonRadius; a line's lineLength applies before its lineAngle)", has_selection, set_live_shape ), diff --git a/crates/engine/src/cmd/object/shape.rs b/crates/engine/src/cmd/object/shape.rs index dcefca2501..b2e69cc279 100644 --- a/crates/engine/src/cmd/object/shape.rs +++ b/crates/engine/src/cmd/object/shape.rs @@ -361,6 +361,11 @@ pub(super) fn set_live_shape(s: &mut Session, p: &Value) -> Result { for id in &ids { super::pixelgrid::resnap(d, *id); } + // A shape named in `ids` and not selected is not checked after the edit: one that a turn or + // a new radius would take past the coordinate limit is an error here, and nothing changes. + if !crate::sanity::objects_in_range(d, &ids) { + return Err(bad("object.setLiveShape", format!("coordinate out of range (limit ±{MAX_COORD} pt)"))); + } Ok(()) })?; ok() diff --git a/crates/engine/src/tests/livecorners.rs b/crates/engine/src/tests/livecorners.rs index 89958d66f1..1ea6e5091f 100644 --- a/crates/engine/src/tests/livecorners.rs +++ b/crates/engine/src/tests/livecorners.rs @@ -663,6 +663,28 @@ fn a_rectangle_and_an_ellipse_take_their_angle() { assert!(close(angle(&s, rect), 20.0) && close(before.x, after.x) && close(before.y, after.y), "{before:?} → {after:?}"); } +/// A shape named in `ids` that a turn would take past the coordinate limit (±4,000,000 pt) is an +/// error that changes nothing, whether or not it is selected. +#[test] +fn a_turn_past_the_coordinate_limit_is_an_error() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap(); + let mut add = |cmd: &str, p: Value| s.execute(cmd, &p).unwrap()["id"].as_u64().unwrap(); + // Each reaches within 10 pt of the limit and past it when turned. + let rect = add("shape.rectangle", json!({"x": 3_999_890, "y": 100, "width": 100, "height": 100})); + let ellipse = add("shape.ellipse", json!({"x": 3_999_950, "y": 100, "width": 40, "height": 100})); + let polygon = add("shape.polygon", json!({"cx": 3_999_955, "cy": 200, "radius": 50, "sides": 6})); + for (id, key, angle) in [(rect, "rectangleAngle", 45), (ellipse, "ellipseAngle", 90), (polygon, "polygonAngle", 90)] { + for selected in [false, true] { + s.execute("select.set", &json!({"ids": if selected { vec![id] } else { vec![] }})).unwrap(); + let (doc, steps) = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len()); + let e = s.execute("object.setLiveShape", &json!({"ids": [id], key: angle})).unwrap_err(); + assert!(e.to_string().contains("out of range"), "{key}, selected {selected}: {e}"); + assert!(*s.doc().unwrap().doc == *doc && s.doc().unwrap().history.undo.len() == steps, "{key}, selected {selected}: changed"); + } + } +} + /// A live line's Line Properties: Line Length keeps its first end in place, Line Angle (degrees /// counterclockwise, any finite value brought into 0 to 360) turns it about its midpoint, the /// length applies before the angle, every selected line takes them in one undo step, and a value diff --git a/crates/ui-egui/src/panels/transform/tests.rs b/crates/ui-egui/src/panels/transform/tests.rs index 0e86ac39fe..dfd6ed66b3 100644 --- a/crates/ui-egui/src/panels/transform/tests.rs +++ b/crates/ui-egui/src/panels/transform/tests.rs @@ -171,21 +171,39 @@ fn a_rectangle_and_an_ellipse_show_their_angle() { ids.push(id); } app.run("select.set", json!({"ids": [ids[0]]})).unwrap(); - for draw in [show as fn(&mut VectorcraftApp, &mut Ui), crate::panels::properties::transform_section] { - let shown = texts(&mut app, draw); - for t in ["Angle:", "0°", "30°"] { - assert!(shown.iter().any(|s| s == t), "{t} in {shown:?}"); - } + for (draw, rotate) in [(show as fn(&mut VectorcraftApp, &mut Ui), "Rotate"), (crate::panels::properties::transform_section, "Rotation")] { + assert_eq!(field_text(&mut app, draw, rotate), "0°", "{shape}: {rotate}"); + assert_eq!(field_text(&mut app, draw, "Angle:"), "30°", "{shape}: {rotate}"); } assert!(texts(&mut app, show).iter().any(|s| s == heading), "{heading}"); app.run("select.set", json!({"ids": ids})).unwrap(); - let shown = texts(&mut app, show); - assert!(shown.iter().any(|s| s == "Angle:") && !shown.iter().any(|s| s == "30°" || s == "60°"), "{shape}: {shown:?}"); + assert_eq!(field_text(&mut app, show, "Angle:"), "", "{shape}: mixed angles"); app.run("select.set", json!({"ids": [ids[1]]})).unwrap(); - assert!(texts(&mut app, show).iter().any(|s| s == "60°"), "{shape}"); + assert_eq!(field_text(&mut app, show, "Angle:"), "60°", "{shape}"); } } +/// The text in `draw`'s input named `label`, read from the accessibility tree of a headless frame. +fn field_text(app: &mut VectorcraftApp, draw: fn(&mut VectorcraftApp, &mut Ui), label: &str) -> String { + use egui_kittest::kittest::Queryable; + let state = std::mem::replace(app, VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default())); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(320.0, 900.0)).with_accessibility_check(false).build_ui_state( + move |ui, app: &mut VectorcraftApp| { + if !std::mem::replace(&mut fonts, true) { + crate::theme::install_fonts(ui.ctx()); + return; + } + draw(app, ui); + }, + state, + ); + h.run_steps(3); + let text = h.get_by_role_and_label(egui::accesskit::Role::TextInput, label).value().unwrap_or_default(); + *app = h.into_state(); + text +} + /// Ellipse Properties' Constrain Pie Angle link, in the Transform panel and the Properties panel's /// Transform section: off at first, a click or Space with the keyboard on it toggles it, and while /// it is on a typed Pie Start or End Angle moves the other angle by as much, keeping the span, in diff --git a/docs/mcp.md b/docs/mcp.md index 071a5f21f3..16b212f64f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7061,11 +7061,14 @@ A live rectangle's Rectangle Angle and a live ellipse's Ellipse Angle are `recta (https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/live-shape-properties.html) lists both as the shape's rotation on the canvas from 0° to 360°. The rest are VectorCraft's own rules: each selected shape of that kind turns about its own center, keeping its size, corners and pie (an ellipse's pie turns with it), and other -objects stay as they are. The Transform and Properties panels show the angle in each shape's Properties section, blank -when the selected shapes of that kind differ. It is the shape's own angle: after Reset Bounding Box +objects stay as they are. A pixel-aligned shape then goes back on the pixel grid, as after other edits, which can move +its center or change its size. The Transform and Properties panels show the angle in each shape's Properties section, +blank when the selected shapes of that kind differ. It is the shape's own angle: after Reset Bounding Box (`object.resetBoundingBox`) the Rotate field reads 0° while the shape angle keeps the turn. An angle that is not a -number is an error and changes nothing, and the angle the shape already has records no undo step; the same holds for -`polygonAngle`, and the Polygon Properties angle is blank, too, when the selected polygons differ. +number is an error and changes nothing (`null` counts as an omitted key), a shape that the turn would take past the +coordinate limit (±4,000,000 pt) is an error that changes nothing, whether or not it is selected, and the angle the +shape already has records no undo step; the same holds for `polygonAngle`, and the Polygon Properties angle is blank, +too, when the selected polygons differ. ```json {"name":"run_command","arguments":{"command":"object.setLiveShape","params":{"rectangleAngle":30}}}