fix(shapes): preserve transformed outline on unchanged live geometry edits (#3197)

* fix(shapes): preserve transformed outline on unchanged live geometry edit

A nonuniform scale stores an anisotropic outline but live rounded rectangles only store scalar corner radii. Avoid regenerating the path when all live values are unchanged, preserving transformed corners and PSD vector source. Cover no-op edits, real radius edits and undo at all depths.

* cargo fmt

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Brandon Thomas <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-11 05:23:55 -04:00
1 parent 073e1cc1d2
commit 8a9f4722d2
2 files changed
+36 -3

No files matched your search

+8 -3
View File
@@ -671,9 +671,14 @@ fn shape_edit(s: &mut Session, p: &Value) -> Result<Value> {
// Explicit radii on a plain rectangle keep it a (now rounded) rectangle.
let kind = if kind == "rect" && radii(p).is_some_and(|r| r.iter().any(|v| *v > 0.0)) { "roundedRect".to_string() } else { kind };
let l = live_from_params(CMD, &kind, p, sh.live.as_ref())?;
sh.path = vector::shapes::live_path(&l);
sh.live = Some(l);
sh.psd_raw = None;
// A transformed live shape's path may carry nonuniform corner scaling
// that its scalar radii cannot represent. Re-entering unchanged values
// must not regenerate the outline and silently discard that geometry.
if sh.live.as_ref() != Some(&l) {
sh.path = vector::shapes::live_path(&l);
sh.live = Some(l);
sh.psd_raw = None;
}
}
if let Some(m) = nums::<6>(p, "transform") {
transform_shape(sh, &Affine { m });
+28
View File
@@ -216,6 +216,34 @@ fn shape_edit_live_params_and_undo() {
assert!(s.execute("shape.edit", json!({"layer": bg, "fill": "#000000"})).is_err());
}
#[test]
fn reapplying_unchanged_live_rectangle_keeps_nonuniformly_scaled_corners() {
for depth in [8, 16, 32] {
let mut s = session(128, 128, depth);
let id = s.execute("shape.create", json!({"kind":"roundedRect","rect":[10,10,20,20],"radius":4})).unwrap()["layer"].as_u64().unwrap();
s.execute("shape.edit", json!({"layer":id,"transform":[2,0,0,1,0,0]})).unwrap();
let scaled = shape(&s, id);
assert_eq!(
scaled.live.as_ref().and_then(|l| match l {
LiveShape::Rect { rect, .. } => Some(*rect),
_ => None,
}),
Some([20.0, 10.0, 40.0, 20.0])
);
// The transformed path has an anisotropic top-left corner.
let path = scaled.path.clone();
s.execute("shape.edit", json!({"layer":id,"rect":[20,10,40,20]})).unwrap();
assert_eq!(shape(&s, id).path, path, "depth {depth}: no-op rectangle edit must preserve all control points");
s.execute("shape.edit", json!({"layer":id,"kind":"roundedRect","rect":[20,10,40,20],"radius":4})).unwrap();
assert_eq!(shape(&s, id).path, path, "depth {depth}: explicitly unchanged radius preserves scaled outline");
// A real radius edit must still rebuild the outline, and Undo must restore it.
s.execute("shape.edit", json!({"layer":id,"radii":[6,6,6,6]})).unwrap();
assert_ne!(shape(&s, id).path, path, "depth {depth}: changed radii must take effect");
s.execute("edit.undo", json!({})).unwrap();
assert_eq!(shape(&s, id).path, path);
}
}
#[test]
fn shape_add_to_with_path_ops() {
let mut s = session(100, 100, 8);