PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(shapes): preserve transformed outline on unchanged live geometry edits (#3197)
Nigel Ihza Firdausy8a9f4722d2bc
diff --git a/crates/engine/src/vector_cmds.rs b/crates/engine/src/vector_cmds.rsindex bcf980469..54e93191d 100644--- a/crates/engine/src/vector_cmds.rs+++ b/crates/engine/src/vector_cmds.rs@@ -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 });diff --git a/crates/engine/src/vector_cmds/tests.rs b/crates/engine/src/vector_cmds/tests.rsindex 6f41eb03c..a073e4615 100644--- a/crates/engine/src/vector_cmds/tests.rs+++ b/crates/engine/src/vector_cmds/tests.rs@@ -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);