🐛 Keep a reflected copy's transform when settling its decomposition

After a reflection, copy descendants are settled through a sync proposal
from their mains so their flip flags take the decomposition sync gives.
The proposal reads the loaded main. A dependent library main nesting a copy
whose child the upstream library flipped, not yet accepted there, was
flipped; mirrored twice, the pending flip gave the child the same corners,
so the footprint check accepted it and the child lost its reflection.

Accept a proposal only where it keeps the shape's corners and transform, so
it can change only how rotation and flips decompose that transform.

A third re-run of the seed-20261101 library dependency property found this;
it also fails on earlier commits. The program regression fails before the
fix and passes after it. Full common passes lint, JVM, JavaScript and
formatting: JVM 2079 tests / 33875 assertions; JavaScript 2015 / 32526. All
six component properties pass 40 programs each at seed 712 in both runtimes.

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     1.007     0.56
Main into 100 copies         15.415     8.691     0.56
Main into 1000 copies       153.086    87.750     0.57
Three nesting levels         35.215    19.121     0.54
Dependency chain             68.931    36.243     0.53
Library update               83.083    46.041     0.55
Many plain shapes             4.837     2.219     0.46
Variant switch               32.052    20.574     0.64

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-10-31 15:09:23 +01:00
parent 9056fc9128
commit c3356b5325
2 changed files with 26 additions and 9 deletions

View File

@ -418,21 +418,26 @@
#{:x :y :width :height :selrect :points :transform :transform-inverse
:rotation :flip-x :flip-y :content-scale})
(defn- same-footprint?
"Whether two shapes cover the same corners, in any order."
(defn- same-placement?
"Whether two shapes cover the same corners with the same transform, so
they differ at most in how rotation and flips decompose it."
[shape other]
(let [corners (:points other)]
(let [corners (:points other)
transform (or (:transform shape) (gmt/matrix))
other-tf (or (:transform other) (gmt/matrix))]
(and (= (count (:points shape)) (count corners))
(every? (fn [point] (some #(gpt/close? point %) corners)) (:points shape)))))
(every? (fn [point] (some #(gpt/close? point %) corners)) (:points shape))
(every? #(mth/close? (get transform %) (get other-tf %)) [:a :b :c :d]))))
(defn generate-sync-transformed-placement
"Settle copy descendants after a reflection and untouched swapped heads
after a parent turn, in the transform's change group. Reflection can
leave descendant flip flags in another decomposition, so it only
re-decomposes shapes that keep their footprint; swapped content can have
a different size from its position frame. Keep this correction within
existing geometry: transforming a stale library copy must not accept
pending content, style, size or structural changes."
re-decomposes shapes whose corners and transform it keeps; swapped
content can have a different size from its position frame. Keep this
correction within existing geometry: transforming a stale library copy
must not accept pending content, style, size, flip or structural
changes."
[changes file libraries page before ids]
(let [objects (pcb/get-objects changes)
orientation (fn [shape]
@ -474,7 +479,7 @@
attrs (cond-> placement-geometry-attrs
(= :path (:type shape)) (conj :content))]
(if (and (= (:type shape) (:type expected))
(or resize? (same-footprint? shape expected)))
(or resize? (same-placement? shape expected)))
(merge shape (select-keys expected attrs))
shape)))
{:ignore-touched true})))

View File

@ -6,11 +6,15 @@
(ns common-tests.logic.source-gen-test
(:require
[app.common.test-helpers.composable.comp.files :as cf]
[app.common.test-helpers.composable.comp.runner :as r]
[app.common.test-helpers.composable.core :as tm]
[app.common.test-helpers.composable.gen :as cg]
[app.common.test-helpers.composable.oracle :as oracle]
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths]
[app.common.test-helpers.texts :as thtx]
[clojure.test :as t]))
(t/use-fixtures :each thi/test-fixture)
@ -35,6 +39,14 @@
:ops [[:library-transform 3 1 4 0] [:library-transform 0 4 4 0]
[:library-undo] [:library-redo]]}))))
(t/deftest a-reflection-does-not-accept-a-pending-library-flip
;; The dependent main nests a copy whose child the source flipped; the
;; dependent library has not accepted that flip.
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
:library-dependency true :library-text true}]
:ops [[:library-remove-child 0 0 0 0] [:library-transform 0 4 4 1]
[:library-transform 0 4 4 0] [:library-undo] [:library-redo]]}))))
(t/deftest source-transforms-keep-consumers-stale-until-acceptance
(doseq [action (range 6) scope [0 1]]
(let [initial (cg/initial-state source-world)