🐛 Ignore float noise and same-looking texts in the override scan

Run on the dashboard templates, the scan reported thousands of copies
that a sync would rewrite with the same geometry within a hundredth of a
pixel, the same path segments, or a text whose letters and styles show
the same in another spelling. It now compares geometry and path content
within a hundredth and text content by its override groups, so what it
reports is a difference a user can see.

The scan is a debugging tool outside sync; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-14 08:56:50 +01:00
parent 3a1b0e3d75
commit 5b725b68a6
2 changed files with 44 additions and 1 deletions

View File

@ -13,10 +13,14 @@
(:require
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as gsh]
[app.common.logic.libraries :as cll]
[app.common.math :as mth]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.shape.layout :as ctl]))
[app.common.types.shape.layout :as ctl]
[app.common.types.text :as txt]))
(defn- derived-geometry?
"Whether the geometry of `shape` is not the main's to give: the size of a
@ -27,6 +31,33 @@
(and (ctl/any-layout-immediate-child? objects shape)
(not (ctl/position-absolute? shape)))))
(defn- close-data?
"Whether `a` and `b` are equal but for numbers within a hundredth."
[a b]
(cond
(and (number? a) (number? b)) (mth/close? a b 0.01)
(and (map? a) (map? b)) (and (= (set (keys a)) (set (keys b)))
(every? #(close-data? (get a %) (get b %)) (keys a)))
(and (sequential? a) (sequential? b)) (and (= (count a) (count b))
(every? true? (map close-data? a b)))
:else (= a b)))
(defn- same-value?
"Whether `a` and `b`, values of `attr`, show the same: geometry within a
hundredth of a pixel, which sync writes back with float noise, the
segments of a path alike, and texts whose letters and styles show the
same (`txt/override-groups`)."
[attr a b]
(cond
(and (number? a) (number? b)) (mth/close? a b 0.01)
(#{:points :selrect} attr) (and (some? a) (some? b) (gsh/close-attrs? attr a b 0.01))
(and (gmt/matrix? a) (gmt/matrix? b)) (gmt/close? a b)
(and (= :content attr) (map? a) (map? b))
(empty? (txt/override-groups a b))
(and (= :content attr) (some? a) (some? b))
(close-data? (vec a) (vec b))
:else (= a b)))
(defn- change-findings
"The findings of a change of a sync of the file `data`: for a change of
attributes, the shape with the attributes and groups it writes; for a
@ -38,6 +69,7 @@
(let [shape (get objects id)
attrs (into #{}
(comp (filter #(= :set (:type %)))
(remove #(same-value? (:attr %) (get shape (:attr %)) (:val %)))
(map :attr)
(remove #{:position-data})
(filter #(some? (ctk/resolve-sync-group (:type shape) %)))

View File

@ -39,6 +39,17 @@
:attrs #{:fills}}]
(map #(select-keys % [:id :groups :attrs]) findings)))))
(t/deftest float-noise-is-not-a-difference
;; sync writes the geometry back within a hundredth of a pixel
(let [file (file-with-copy)
x (:x (ths/get-shape file :copy-child))
file (-> file
(ths/update-shape :copy-child :x (+ x 0.001))
(ths/update-shape :copy-child :touched nil))]
(t/is (empty? (clos/scan file {})))
(t/testing "a pixel is a difference"
(t/is (seq (clos/scan (ths/update-shape file :copy-child :x (+ x 1)) {}))))))
(t/deftest an-override-is-not-a-difference
(let [file (-> (file-with-copy)
(ths/update-shape :copy-child :fills (red-fills)))]