🐛 Keep an inherited turn out of update main

A nested copy inside a turned parent inherits that turn as placement. Update
main pushed it into the copy's main as if the copy had authored it, and the
copy then composed the turn twice: 45 degrees became 90.

When the copy root does not author its geometry, turn the copy subtree back
into the main's frame before pushing its values. A root rotation the user
authored is still pushed as before.

A fresh-seed JVM structure run found this. The shrunk program fails I9
before the fix and passes unchanged after it, with the main unturned and
the copy at its original 45 degrees. Goldens are unchanged.

Full suites ran once on the tree with this fix and the related fixes that
follow it. Common passes lint, JVM, JavaScript and formatting: JVM 2059
tests / 33770 assertions; JavaScript 1995 / 32377. All six component
properties pass 40 programs each at seed 712 in both runtimes. Full rebuilt
frontend passes 1798 / 15737. Backend passes 1838 / 9293; exporter passes
16 / 40; consumer lint and formatting pass.

Compare lower-quantile milliseconds with the saved baseline; keep that
baseline unchanged. The machine/JVM warning makes ratios rough. No world
is flagged.

World                      Baseline       Now    Ratio
Main into 10 copies           1.790     0.876     0.49
Main into 100 copies         15.415     8.403     0.55
Main into 1000 copies       153.086    85.661     0.56
Three nesting levels         35.215    17.327     0.49
Dependency chain             68.931    37.617     0.55
Library update               83.083    46.058     0.55
Many plain shapes             4.837     2.174     0.45
Variant switch               32.052    20.413     0.64

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-10-30 20:18:55 +01:00
parent 7b3ae5a3a5
commit 751068af95
2 changed files with 41 additions and 30 deletions

View File

@ -705,11 +705,6 @@
library (dm/get-in libraries [(:component-file shape-inst) :data])
component (ctkl/get-component library (:component-id shape-inst))
shape-main (when component
(ctf/find-remote-shape container libraries shape-inst))
initial-root? (:component-root shape-inst)
;; The component name is normalized (path separators with one space at
;; each side), so the name synced to the main instance root must be
;; normalized too. Otherwise the root would not match the component's
@ -723,9 +718,6 @@
(some? clean-name)
(assoc :name clean-name))
root-inst shape-inst
root-main (ctf/get-component-root library component)
;; When the synced shape is itself the component's main instance root,
;; `find-remote-shape` returns nil and the recursive sync never reaches
;; it, so it must be renamed explicitly to keep it matching the
@ -735,26 +727,8 @@
changes (cond-> changes
(some? clean-name)
(generate-rename-component (:component-id shape-inst) clean-name library))
(generate-rename-component (:component-id shape-inst) clean-name library)
changes (if component
(let [synced-ids (volatile! #{})]
(-> (update-main-recursive changes
{:container container
:main-container (ctf/get-component-container library component)
:component component
:libraries libraries
:root-inst root-inst
:root-main root-main
:remote-synced (when-not initial-root? true)
:synced-ids synced-ids}
shape-inst
shape-main)
(mark-local-changes @synced-ids)
(settle-updated-main-placement libraries (:component-file shape-inst) component)))
changes)
changes (cond-> changes
(and (some? clean-name)
main-root?
(not= clean-name original-name))
@ -768,7 +742,28 @@
:local-change? true
:operations [{:type :set :attr :name :val original-name}]}]))]
changes))
(if component
(let [synced-ids (volatile! #{})
root-main (ctf/get-component-root library component)]
(-> (update-main-recursive changes
{:container container
:main-container (ctf/get-component-container library component)
:component component
:libraries libraries
:root-inst shape-inst
:root-main root-main
;; An orientation the copy root inherits from its
;; parent places it; it is not pushed into the main.
:inherited-turn (when-not (ctk/touched-group? shape-inst :geometry-group)
(orient-like shape-inst root-main
(grc/rect->center (:selrect shape-inst))))
:remote-synced (when-not (:component-root shape-inst) true)
:synced-ids synced-ids}
shape-inst
(ctf/find-remote-shape container libraries shape-inst))
(mark-local-changes @synced-ids)
(settle-updated-main-placement libraries (:component-file shape-inst) component)))
changes)))
(defn split-local-changes
"`changes` of an update main (`generate-sync-shape-inverse`) as `[local
@ -787,9 +782,13 @@
"Push the copy shape `shape-inst` into `shape-main`, the main shape it
pairs with: the copy's values, overrides included, go into the main, and
its touched groups move there (the copy keeps a swap)."
[changes {:keys [container main-container root-inst root-main remote-synced]} shape-inst shape-main]
[changes {:keys [container main-container root-inst root-main remote-synced inherited-turn]} shape-inst shape-main]
(cond-> (-> changes
(update-attrs shape-main shape-inst root-main root-inst main-container false)
(update-attrs shape-main
(cond-> shape-inst (some? inherited-turn) inherited-turn)
root-main
(cond-> root-inst (some? inherited-turn) inherited-turn)
main-container false)
;; the copy keeps its swap, and the main takes the copy's overrides
(set-touched shape-inst container (when (ctk/swapped? shape-inst) #{:swap-group}))
;; A previous update is not a reset of the main's authored

View File

@ -5,6 +5,7 @@
[app.common.geom.shapes :as gsh]
[app.common.logic.shapes :as cls]
[app.common.logic.variants :as clv]
[app.common.math :as mth]
[app.common.schema.test :as smt]
[app.common.test-helpers.composable.comp.files :as cf]
[app.common.test-helpers.composable.comp.nodes :as n]
@ -671,6 +672,17 @@
:ops [[:rotate 0 0 0 0] [:edit 0 0 1 1] [:update-main 0] [:delete 0]
[:restore 0] [:nest 0 0 0 0] [:swap 0 0 0 0] [:switch 0 0 0 0]]}))))
(t/deftest updating-a-main-from-a-copy-turned-by-its-parent-keeps-the-main-unturned
(let [program {:world [2 2 {:text true :text-styles true :layout nil}]
:ops [[:rotate 6 0 0 0] [:nest 13 0 0 0] [:transform 0 0 0 13]
[:update-main 3 0 0 0] [:update-main 0 0 0 0]]}
situation (:situation (cg/run program))
rotation #(-> (tm/shape-by-id situation (thi/id %)) :rotation (or 0) (mod 360))]
;; The nested copy inherits 45 degrees from its updated parent; its main
;; stays unturned and the copy keeps the turn it had.
(t/is (mth/close? 0 (rotation :sync-random-0-outer-0) 0.01))
(t/is (mth/close? 45 (rotation :sync-random-0-innercopy-1) 0.01))))
(t/deftest detached-swapped-head-follows-its-own-component-without-position-overrides
(t/is (map? (cg/run {:world [2 1 {:library true :variants true}]
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]