From cee4f8d276fcee3ad2b22c24ed8d296b6b0af7ef Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 02:04:01 -0800 Subject: [PATCH] Parametric Shape: measure the box the same way before and after a W or H edit With `reference`, `addon.pathtools.shape.set` measured the shape's box before the edit with Use Preview Bounds and fell back to the geometric box when the preview gave none, and it chose again after the edit. When the preview gave a box before the edit and none after it, or the reverse, the shape moved by the difference between two different boxes. The measure used before the edit is now used after it. The params text and docs/mcp.md now say that snapping to the pixel grid and an attachment to a path apply after the reference point is kept, as they do for the Transform panel's W and H. The docs line in docs/target-app-parity.md changes only the lines it needs. --- .../engine/src/cmd/addons/pathtools/shape.rs | 21 +++++++++++-------- docs/mcp.md | 5 +++-- docs/target-app-parity.md | 6 +++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/addons/pathtools/shape.rs b/crates/engine/src/cmd/addons/pathtools/shape.rs index 551d5c7dba..6c16893aba 100644 --- a/crates/engine/src/cmd/addons/pathtools/shape.rs +++ b/crates/engine/src/cmd/addons/pathtools/shape.rs @@ -33,7 +33,7 @@ pub fn specs() -> Vec { "Edit Parametric Shape", [], None, - "{id, kind?, center?, width?, height?, rotation?: degrees clockwise (0: upright), count?, a?, b?, radius?, reference?: 0..8 (a point on the 9-point grid of the bounding box as object.setBounds measures it, rotated with rotated objects)} change a parametric shape's numbers (as addon.pathtools.shape.create takes them; a new kind takes its own defaults for the values not given), as one undo step; with `reference` and no `center`, that point of the bounding box keeps its place (as the Transform panel's W and H do), otherwise the center stays; with none, or the same ones, nothing changes → {id, shape (its numbers now; null when snapping to the pixel grid left a plain path)}", + "{id, kind?, center?, width?, height?, rotation?: degrees clockwise (0: upright), count?, a?, b?, radius?, reference?: 0..8 (a point on the 9-point grid of the bounding box as object.setBounds measures it, rotated with rotated objects)} change a parametric shape's numbers (as addon.pathtools.shape.create takes them; a new kind takes its own defaults for the values not given), as one undo step; with `reference` and no `center`, that point of the bounding box keeps its place (as the Transform panel's W and H do; snapping to the pixel grid and an attachment to a path apply afterwards), otherwise the center stays; with none, or the same ones, nothing changes → {id, shape (its numbers now; null when snapping to the pixel grid left a plain path)}", has_doc, set ), @@ -108,21 +108,24 @@ fn set(s: &mut Session, p: &Value) -> Result { if shape != old { // Without a center, the reference point of the bounding box (as the Transform panel and // `object.setBounds` measure it; the geometric box where the preview leaves none) keeps - // its place: the new outline moves onto it. + // its place: the new outline moves onto it. The box after the edit is measured the same way + // as the box before it. let how = s.bounds_measure(); - let boxed = move |d: &Document| { - effects::preview::oriented_bounds_with(d, &[id], how) - .or_else(|| effects::preview::oriented_bounds_with(d, &[id], effects::preview::Measure { preview: false, ..how })) - }; + let geometric = effects::preview::Measure { preview: false, ..how }; + let boxed = |d: &Document, m: effects::preview::Measure| effects::preview::oriented_bounds_with(d, &[id], m).map(|b| (m, b)); let keep = match reference.filter(|_| p.get("center").is_none_or(Value::is_null)) { - Some(i) => Some((i, boxed(&s.doc()?.doc).ok_or_else(|| EngineError::Other("no bounds".into()))?.reference_point(i))), + Some(i) => { + let d = &s.doc()?.doc; + let (m, b) = boxed(d, how).or_else(|| boxed(d, geometric)).ok_or_else(|| EngineError::Other("no bounds".into()))?; + Some((i, m, b.reference_point(i))) + } None => None, }; let path = outline(&shape, C)?; s.edit(EDIT, |d, sel| { shape_node(d.node_mut(id).ok_or(EngineError::NoNode(id))?, &shape, path); - if let Some((i, was)) = keep - && let Some(now) = boxed(d).map(|b| b.reference_point(i)) + if let Some((i, m, was)) = keep + && let Some(now) = boxed(d, m).map(|(_, b)| b.reference_point(i)) && now != was { let mut moved = shape; diff --git a/docs/mcp.md b/docs/mcp.md index bafdc73f8f..4ddf7b463c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14751,8 +14751,9 @@ Commands: - `addon.pathtools.shape.set {id, …}` changes a parametric shape's numbers (the same keys; a new `kind` takes its own defaults for the values not given) and redraws it in place. With `reference` (0 to 8 on the 9-point grid of the bounding box as `object.setBounds` measures it, rotated with rotated objects) and no `center`, that point of the box - keeps its place, as with the Transform panel's W and H; otherwise the shape's center stays. A `reference` outside 0 - to 8 is an error. With no change it makes no step. → `{id, shape}` (its numbers now, so `{id}` alone reads them; + keeps its place, as with the Transform panel's W and H; otherwise the shape's center stays. Snapping to the pixel + grid and an attachment to a path apply after that, as they do for the Transform panel's W and H, and can move the + point. A `reference` outside 0 to 8 is an error. With no change it makes no step. → `{id, shape}` (its numbers now, so `{id}` alone reads them; `null` when snapping to the pixel grid left a plain path). - `addon.pathtools.shape.convert {ids?}` makes the selected plain closed paths that are rectangles, ellipses or polygons with equal sides and corners (stretched along their own axes at most) parametric shapes with the same diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 6e2efc2feb..b49b61dfa4 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2821,9 +2821,9 @@ ellipse, polygon and star with 3 to 1,000 sides or points, ring, arrow, cross, h limited to the middle of a side): a drag from the centre sizes and turns one, the arrow keys change its count and values while dragging, handles edit a selected one, a double-click places one with the last settings, and its panel edits the numbers (its W and H keep the point chosen in the shared reference point locator in place). A shape is a plain path -whose numbers and outline fingerprint sit in one object-data entry that SVG export leaves out; moving, rotating or -scaling it keeps it editable, editing its anchors makes it a plain path. Convert to Parametric Shape recognises plain -rectangles, ellipses and regular polygons. Geometry in +whose numbers and outline fingerprint sit in one object-data entry that SVG export +leaves out; moving, rotating or scaling it keeps it editable, editing its anchors makes it a plain path. Convert to +Parametric Shape recognises plain rectangles, ellipses and regular polygons. Geometry in `vectorcraft_pathops::addons::pathtools::shapes`. Tests: `shapes` in `vectorcraft-pathops` (each kind, ranges, recovery after transforms, recognition), `addons::parametric_shape` in `vectorcraft-tools` (drag, keys, handles, stored data), `cmd::addons::pathtools::tests` in `vectorcraft-engine` (each command one undo step, bad params refused,