mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Treat a hundredth of a pixel as float noise when keeping copy places
After a turn and a fill resize, nested copies sit a few thousandths of a pixel from where their mains place them. A detach that advanced them, and a resize that scaled a swapped head by that much, made their geometry an override for the noise alone: they stopped following their mains' geometry (F593). `turned-like-parent?`, the place check of `generate-keep-advanced-placement` (`close-geometry?` now takes a precision) and the resize check of `author-resized-swapped-heads` compare sizes and corners to a hundredth of a pixel, as the rest of sync compares them. The composable model's `sync-scaled-heads` does the same. Found by a fresh gate round (seed 20261117, variant property). Test: generated `generated-a-detach-authors-no-geometry-for-float-noise`. Benchmark (bench-components, alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 21.107 | 21.817 | 0.6 | | edit-through-a-chain-of-dependents | 68.931 | 46.08 | 47.003 | 0.67 | | library-update-into-copies | 83.083 | 56.955 | 57.969 | 0.69 | | main-edit-among-many-shapes | 4.837 | 2.37 | 2.545 | 0.49 | | main-edit-into-10-copies | 1.79 | 1.068 | 1.11 | 0.6 | | main-edit-into-100-copies | 15.415 | 10.438 | 10.941 | 0.68 | | main-edit-into-1000-copies | 153.086 | 103.384 | 109.082 | 0.68 | | variant-switch-into-copies | 32.052 | 24.999 | 25.423 | 0.78 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
7aa788c6e5
commit
ba147e63e4
@ -522,9 +522,10 @@
|
||||
(let [objects (pcb/get-objects changes)
|
||||
resized? (fn [id]
|
||||
(let [old (get before id) shape (get objects id)]
|
||||
;; sizes are pixels: a hundredth of one is float noise
|
||||
(and old shape
|
||||
(not (and (mth/close? (-> old :selrect :width) (-> shape :selrect :width))
|
||||
(mth/close? (-> old :selrect :height) (-> shape :selrect :height)))))))
|
||||
(not (and (mth/close? (-> old :selrect :width) (-> shape :selrect :width) 0.01)
|
||||
(mth/close? (-> old :selrect :height) (-> shape :selrect :height) 0.01))))))
|
||||
heads (into []
|
||||
(comp (filter #(and (:shape-ref (get objects %)) (resized? %)))
|
||||
(mapcat #(cfh/get-children-ids objects %))
|
||||
@ -636,14 +637,16 @@
|
||||
(declare flips)
|
||||
|
||||
(defn- close-geometry?
|
||||
"Whether `shape` and `other` have the same geometry: a bool keeps its
|
||||
corners in one order whatever its flips, so they count too."
|
||||
[shape other]
|
||||
(and (gsh/close-attrs? :selrect (:selrect shape) (:selrect other))
|
||||
(gsh/close-attrs? :points (:points shape) (:points other))
|
||||
(mth/close? (:content-scale shape 1) (:content-scale other 1))
|
||||
(or (not (#{:group :bool} (:type shape)))
|
||||
(= (flips shape) (flips other)))))
|
||||
"Whether `shape` and `other` have the same geometry, within `precision`:
|
||||
a bool keeps its corners in one order whatever its flips, so they count
|
||||
too."
|
||||
([shape other] (close-geometry? shape other mth/float-equal-precision))
|
||||
([shape other precision]
|
||||
(and (gsh/close-attrs? :selrect (:selrect shape) (:selrect other) precision)
|
||||
(gsh/close-attrs? :points (:points shape) (:points other) precision)
|
||||
(mth/close? (:content-scale shape 1) (:content-scale other 1))
|
||||
(or (not (#{:group :bool} (:type shape)))
|
||||
(= (flips shape) (flips other))))))
|
||||
|
||||
(defn- authored-constraints
|
||||
"The constraints that the copy shapes `ids` author, by the id of the main
|
||||
@ -2267,8 +2270,9 @@
|
||||
([shape main main-parent parent sized]
|
||||
(let [main-parent (when-not (cfh/root? main-parent) main-parent)
|
||||
flip? (fn [key] (odd? (count (filter key [main main-parent parent]))))]
|
||||
(and (or (contains? sized :width) (mth/close? (-> shape :selrect :width) (-> main :selrect :width)))
|
||||
(or (contains? sized :height) (mth/close? (-> shape :selrect :height) (-> main :selrect :height)))
|
||||
;; sizes are pixels: a hundredth of one is float noise
|
||||
(and (or (contains? sized :width) (mth/close? (-> shape :selrect :width) (-> main :selrect :width) 0.01))
|
||||
(or (contains? sized :height) (mth/close? (-> shape :selrect :height) (-> main :selrect :height) 0.01))
|
||||
(gmt/close? (axes-matrix shape)
|
||||
(gmt/multiply (axes-matrix parent)
|
||||
(gmt/inverse (axes-matrix main-parent))
|
||||
@ -2324,9 +2328,11 @@
|
||||
(not (#{:group :bool} (:type shape)))
|
||||
(if (and (some? (:shape-ref parent)) (not layout-placed?))
|
||||
(and (some? main-parent)
|
||||
;; a place a hundredth of a pixel away is float noise
|
||||
(not (close-geometry? shape (get (placed-like main-objects main-parent parent
|
||||
(authored-constraints objects [id]))
|
||||
(:id main)))))
|
||||
(:id main))
|
||||
0.01)))
|
||||
(not (turned-like-parent? shape main main-parent parent
|
||||
(if layout-placed? (layout-sized objects shape) #{})))))
|
||||
(pcb/update-shapes changes [id] #(update % :touched ctk/set-touched-group :geometry-group)
|
||||
|
||||
@ -705,9 +705,10 @@
|
||||
size authors that size, placed in its parent. The resize starts at the
|
||||
topmost resized ancestor of the head."
|
||||
[model before after]
|
||||
(let [sized-alike? #(let [a (geom/boxed %1) b (geom/boxed %2)]
|
||||
(and (mth/close? (:width a) (:width b))
|
||||
(mth/close? (:height a) (:height b))))
|
||||
(let [;; sizes are pixels: a hundredth of one is float noise
|
||||
sized-alike? #(let [a (geom/boxed %1) b (geom/boxed %2)]
|
||||
(and (mth/close? (:width a) (:width b) 0.01)
|
||||
(mth/close? (:height a) (:height b) 0.01)))
|
||||
;; whether `id` keeps its parent and has another size in `after`
|
||||
resized? (fn [id]
|
||||
(let [old (get before id) shape (get after id)]
|
||||
|
||||
@ -4542,3 +4542,8 @@
|
||||
:ops [[:style 1 1 1 0] [:add-child 0] [:structure 0 0 0] [:add-child 0]
|
||||
[:structure 1 4 0] [:transform 1 1 0 1]]}))))
|
||||
|
||||
(t/deftest generated-a-detach-authors-no-geometry-for-float-noise
|
||||
;; after a turn and a fill resize, the nested copies a detach advances sit
|
||||
;; a few thousandths of a pixel from their new mains' places: no override
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :layout :grid :rich-variants true :grid-empty true :layout-copies true :text true}] :ops [[:nest 7 2 4 2] [:rotate 6 2 4 1] [:duplicate 1 3 1 0] [:make-variant 2] [:duplicate 8 2 8 6] [:style 2 29 1] [:detach 8 6 8 2]]}))))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user