mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Keep a stale nested copy's size when its main is reflected
Reflecting a shape re-decomposes the flip flags of the copy heads under it by placing them through a sync proposal from their mains. Its docstring promises to stay within existing geometry, but the proposal also carries a pending size of the copy's library main. A dependent library main nesting a copy of an upstream main whose width changed took that width when the dependent main was flipped, before the update was accepted. Settle reflected heads only on the shapes whose footprint the proposal keeps. Untouched swapped heads after a parent turn still take the proposal whole, since their content may differ in size from their position. A fresh JVM library-dependency run (seed 20261101) found this: a 0.01 px nested frame became 160 px wide (I4). The program regression fails before the fix and passes after it. The source, oracle, expected-geometry, reset, sync, swap-group and composable namespaces pass at seed 712: 330 tests / 3729 assertions. 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.944 0.53 Main into 100 copies 15.415 9.742 0.63 Main into 1000 copies 153.086 91.886 0.60 Three nesting levels 35.215 18.344 0.52 Dependency chain 68.931 36.790 0.53 Library update 83.083 45.517 0.55 Many plain shapes 4.837 2.256 0.47 Variant switch 32.052 20.228 0.63 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
b14cec3c4f
commit
7f1edd5659
@ -418,34 +418,47 @@
|
||||
#{: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."
|
||||
[shape other]
|
||||
(let [corners (:points other)]
|
||||
(and (= (count (:points shape)) (count corners))
|
||||
(every? (fn [point] (some #(gpt/close? point %) corners)) (:points shape)))))
|
||||
|
||||
(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; 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 or structural changes."
|
||||
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."
|
||||
[changes file libraries page before ids]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
orientation (fn [shape]
|
||||
[(select-keys (or (:transform shape) (gmt/matrix)) [:a :b :c :d])
|
||||
(:rotation shape) (boolean (:flip-x shape)) (boolean (:flip-y shape))])
|
||||
roots (into (d/ordered-set)
|
||||
(keep (fn [id]
|
||||
(let [shape (get objects id)
|
||||
root (when (:component-id shape) (ctn/get-component-shape objects shape))
|
||||
old (get before id)
|
||||
reflected-head? (and (:component-id shape)
|
||||
(:shape-ref shape)
|
||||
(or (not= (boolean (:flip-x old)) (boolean (:flip-x shape)))
|
||||
(not= (boolean (:flip-y old)) (boolean (:flip-y shape)))))]
|
||||
(when (or reflected-head?
|
||||
(and (ctk/swapped? shape)
|
||||
(not (ctk/touched-group? shape :geometry-group))
|
||||
(not= (orientation old) (orientation shape))))
|
||||
(:id root)))))
|
||||
ids)]
|
||||
(reduce (fn [changes id]
|
||||
;; Each root to settle, and whether its settlement may resize shapes.
|
||||
roots (reduce (fn [roots [id resize?]] (update roots id #(or % resize?)))
|
||||
(d/ordered-map)
|
||||
(keep (fn [id]
|
||||
(let [shape (get objects id)
|
||||
root (when (:component-id shape) (ctn/get-component-shape objects shape))
|
||||
old (get before id)
|
||||
reflected-head? (and (:component-id shape)
|
||||
(:shape-ref shape)
|
||||
(or (not= (boolean (:flip-x old)) (boolean (:flip-x shape)))
|
||||
(not= (boolean (:flip-y old)) (boolean (:flip-y shape)))))]
|
||||
(cond
|
||||
(and (ctk/swapped? shape)
|
||||
(not (ctk/touched-group? shape :geometry-group))
|
||||
(not= (orientation old) (orientation shape)))
|
||||
[(:id root) true]
|
||||
|
||||
reflected-head?
|
||||
[(:id root) false])))
|
||||
ids))]
|
||||
(reduce (fn [changes [id resize?]]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
page (assoc page :objects objects)
|
||||
file (assoc-in file [:data :pages-index (:id page) :objects] objects)
|
||||
@ -460,7 +473,8 @@
|
||||
(let [expected (get placed (:id shape))
|
||||
attrs (cond-> placement-geometry-attrs
|
||||
(= :path (:type shape)) (conj :content))]
|
||||
(if (= (:type shape) (:type expected))
|
||||
(if (and (= (:type shape) (:type expected))
|
||||
(or resize? (same-footprint? shape expected)))
|
||||
(merge shape (select-keys expected attrs))
|
||||
shape)))
|
||||
{:ignore-touched true})))
|
||||
|
||||
@ -28,6 +28,13 @@
|
||||
[:library-sync]]}))
|
||||
(str edit))))
|
||||
|
||||
(t/deftest a-reflection-does-not-accept-a-pending-library-size
|
||||
;; The dependent main nests a copy of a source main whose width is pending.
|
||||
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
|
||||
:library-dependency true :library-text true}]
|
||||
:ops [[:library-transform 3 1 4 0] [: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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user