🐛 Keep inherited placement untouched during a plain swap

Compare retained orientation with the position source in copy-parent
coordinates, including cached deleted mains. A rotation inherited from
that source does not author a geometry override (F154).

The focused regression fails before the change. Swap and variant suites
pass 100 tests and 510 assertions; common lint and format pass. Benchmark
ratios: mains 0.47/0.53/0.55; levels 0.51; chain 0.64; library 0.64;
many shapes 0.96; switch 0.68, with no regression flags.

AI-assisted-by: GPT-6
This commit is contained in:
alonso.torres 2026-10-23 20:46:32 +02:00
parent d65f8ded0f
commit bce5a2c5b8
2 changed files with 20 additions and 5 deletions

View File

@ -364,16 +364,20 @@
(defn- keep-orientation-override
"Retained orientation that differs from the new component's expected
placement needs a geometry override to survive later sync."
[changes shape baseline page ldata component-id]
[changes shape baseline page ldata component-id position]
(let [parent (get-in page [:objects (:parent-id shape)])
main (ctf/get-component-root ldata (ctkl/get-component ldata component-id))
main-parent (get-in (ctf/get-component-container ldata (ctkl/get-component ldata component-id))
[:objects (:parent-id main)])
parent-delta (if (:shape-ref parent) 0
baseline (or position baseline)
main-parent (if position
(get-in (meta position) [:container :objects (:parent-id position)])
main-parent)
parent-delta (if (and (:shape-ref parent) (nil? position)) 0
(- (or (:rotation parent) 0) (or (:rotation main-parent) 0)))
rotation (mod (+ (or (:rotation baseline) 0) parent-delta) 360)
flip (fn [key]
(if (:shape-ref parent)
(if (and (:shape-ref parent) (nil? position))
(boolean (get baseline key))
(odd? (count (filter identity [(get baseline key) (get parent key)
(get main-parent key)])))))
@ -466,7 +470,7 @@
(ctk/touched-group? % :geometry-group)) orig-touched)
(keep-orientation-override original-shape new-shape page
(or (get-in libraries [(:component-file new-shape) :data]) ldata)
(:component-id new-shape)))]
(:component-id new-shape) nil))]
[changes (mapv (comp :parent-id :new) pairs)]))
(defn- shape-index
@ -500,7 +504,10 @@
[changes parents-of-swapped]
(if keep-touched?
(generate-keep-touched changes new-shape shape orig-shapes page libraries ldata)
[(keep-orientation-override changes shape new-shape page ldata component-id) []])
[(keep-orientation-override changes shape new-shape page ldata component-id
(when (:shape-ref parent)
(ctf/find-ref-shape nil page libraries shape
:include-deleted? true :with-context? true))) []])
;; Replacement keeps the head id and its cell. Cleanup during the
;; temporary deletion must not change the parent's placement data.

View File

@ -797,3 +797,11 @@
(t/is (= (:shapes main) (mapv #(get-in objects [% :shape-ref]) (:shapes head))))
(t/is (= (thn/normalize-file (tm/file initial))
(thn/normalize-file (tm/file (r/step detached (n/undo))))))))
(t/deftest plain-swap-does-not-author-the-positions-inherited-orientation
(let [rotated (-> (tm/make-situation (setup-sized))
(r/step (n/rotate :card-star 45)) r/settle)
swapped (-> rotated (r/step (n/swap-shape :copy-star :heart)) r/settle)
head (tm/resolve-shape swapped :copy-star)]
(t/is (mth/close? 45 (:rotation head) 0.001))
(t/is (= #{:swap-group} (:touched head)))))