mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
✨ Generate group, mask, bool and path edits inside mains
The random histories never changed the structure of the shapes a main holds. The shape structure programs add a structure edit on a shape a main holds, and its next sibling: group, mask, unmask, combine into a bool of each type, or convert to a path, through the changes of app.common.logic.groups and app.common.logic.bool the workspace events commit, and the frontend's path conversion without the WASM renderer. Ungrouping, and grouping that takes every child out of a group, stay out until copies follow the removal of a shape their main holds. The oracle and the model learn the shapes these edits make: - bools and paths keep their bounds in their selrect only, which the geometry checks read when a shape has no box of its own; - path segments compare within the geometry tolerance, and the design snapshot leaves out a bool's segments, which it computes from its children in an order that depends on how it was computed; - children of groups and bools measure from, and anchor authored places to, the board around them, as a group's bounds come from its children; - differing flip flags count only when the ordered corners differ too; - undo and redo compare geometry within 1e-10, and bool and path geometry within 1e-4, as a group computes its geometry again from its children and a path stores its segments in single precision. Transforms of copy shapes inside groups and bools stay out until the oracle places them. Test: random-shape-structure-compositions. Focused only; the full common suite runs at the end of this series. Harness only; the benchmark is not run. Also in this commit: - Count differing flip flags unless they decompose the same corners. The shape structure gates ignored differing flip flags whenever the ordered corners matched, so a shape whose flags disagree with its own transform passed as well (both-flags-and-a-half-turn-equal-neither). Flags count now unless the corners match and the shape's flags and rotation decompose its transform, so they store the same transform otherwise. - Resize the groups around a shape the harness transforms. The frontend's transform resizes the groups around the shapes it changes (reg-objects, pcb/resize-parents); the harness transform did not, so a main's group kept the bounds of a child it moved while sync gave its copies' groups bounds from their children, and the oracle found them apart. The harness transform resizes the parents too. - Reflow layouts only after the structure edits whose events do. The structure node reflowed the layouts of the parents after every edit, but the workspace events update layouts only after grouping, masking and ungrouping; unmasking, creating a bool and converting to a path do not. The extra reflow left an undo that did not give back the place of the children of a mask unmasked in a flex main. The node reflows as the events do. - Compare the corners of a bool in any order. A bool computes its points from its segments, so their order follows the path, not the transform: a flipped main gave its copies' bools the same corners in another order, which the geometry check and the design snapshot read as another place. Both compare a bool's corners in a sorted order. - Check only the first corner of a place whose size a layout gives. The model checks an authored place by the corners of the shape placed in its parent, but leaves out the dimensions a layout gives it. A moved copy whose main came to hug its grid took the hugged width from its layout and kept its first corner, yet the corner check compared all four corners with the authored width. With a size the layout gives, only the first corner is checked, which a layout resize keeps. - Sort the corners of a bool by their rounded position. Sorting a bool's corners by their raw coordinates swapped two corners whose x differed only by noise, so two equal bools compared apart. The corners sort by position rounded to the hundredth of a pixel. - The harness changes that check the next commit, "Keep the layout's place and sizes out of a detach's kept geometry". AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
61b52860e5
commit
a64ea2121c
@ -19,7 +19,9 @@
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logic.bool :as clb]
|
||||
[app.common.logic.duplicate :as cld]
|
||||
[app.common.logic.groups :as clg]
|
||||
[app.common.logic.instances :as cli]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.placement :as clp]
|
||||
@ -41,6 +43,7 @@
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.path :as cpath]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.types.shape.radius :as ctsr]
|
||||
[app.common.types.text :as txt]
|
||||
@ -476,10 +479,12 @@
|
||||
(let [objects (:objects page)
|
||||
tree (gm/set-objects-modifiers {(:id shape) {:modifiers modifiers}} objects)
|
||||
transform (clp/modifiers-transform tree)
|
||||
changes (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) (keys tree) transform objects
|
||||
{:ignore-tree (clp/calculate-ignore-tree objects (keys tree) transform #{(:id shape)})
|
||||
:attrs clp/transform-attrs})]
|
||||
changes (-> (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) (keys tree) transform objects
|
||||
{:ignore-tree (clp/calculate-ignore-tree objects (keys tree) transform #{(:id shape)})
|
||||
:attrs clp/transform-attrs})
|
||||
;; as the frontend's transform, the groups around the shapes take their new bounds
|
||||
(pcb/resize-parents (keys tree)))]
|
||||
(cond-> changes
|
||||
file (cll/generate-sync-transformed-placement file libraries page objects (keys tree))))))
|
||||
|
||||
@ -2258,6 +2263,62 @@
|
||||
(tm/assign-id (->AddChild parent new-label shape-params)))
|
||||
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; edit-structure — group, ungroup, mask, unmask, combine or convert shapes
|
||||
;;
|
||||
;; The structure actions on the shapes labelled `targets`: `:group` and
|
||||
;; `:mask` put them in a new group, `:ungroup` and `:unmask` take apart or
|
||||
;; unmask the group `(first targets)`, `:bool` combines them by `:bool-type`
|
||||
;; of `params`, and `:path` converts them to paths, through the changes of
|
||||
;; `app.common.logic.groups` and `app.common.logic.bool` the workspace events
|
||||
;; commit, and the path conversion of the frontend without the WASM
|
||||
;; renderer. A group, mask or ungroup reflows the layouts of the parents it
|
||||
;; changes, as their events do.
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defrecord EditStructure [action targets params]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
(let [the-file (tm/file situation)
|
||||
page (thf/current-page the-file)
|
||||
objects (:objects page)
|
||||
ids (mapv #(tm/target-shape-id situation %) targets)
|
||||
parents (into #{} (keep #(:parent-id (get objects %))) ids)
|
||||
changes
|
||||
(case action
|
||||
:group (let [shapes (clg/shapes-for-group-or-mask objects ids)]
|
||||
(second (clg/prepare-create-group (pcb/empty-changes nil (:id page)) (uuid/next) objects
|
||||
(:id page) shapes "Group" false)))
|
||||
:mask (let [shapes (clg/shapes-for-group-or-mask objects ids)]
|
||||
(second (clg/generate-mask-changes nil (uuid/next) (:id page) objects shapes)))
|
||||
:ungroup (clg/generate-ungroup-changes nil (:id page) objects (clg/ungroup-ids objects ids))
|
||||
:unmask (clg/generate-unmask-changes nil (:id page) objects ids)
|
||||
:bool (second (clb/generate-create-bool nil (:id page) objects ids (:bool-type params) nil))
|
||||
:path (-> (pcb/empty-changes nil (:id page))
|
||||
(pcb/with-objects objects)
|
||||
(pcb/update-shapes ids cpath/convert-to-path {:with-objects? true})
|
||||
(pcb/remove-objects (into #{} (mapcat #(cfh/get-children-ids objects %)) ids))))
|
||||
;; the action's changes on the page, applied before the reflow reads them;
|
||||
;; as the workspace events, only a group, mask or ungroup updates the layouts
|
||||
changes (cond-> (-> (pcb/empty-changes nil (:id page))
|
||||
(pcb/with-objects objects)
|
||||
(pcb/concat-changes changes)
|
||||
(pcb/apply-changes-local))
|
||||
(#{:group :mask :ungroup} action) (with-layouts-reflow parents))
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:action action :targets targets :params params})))))
|
||||
|
||||
(defn edit-structure
|
||||
[action targets & {:as params}]
|
||||
(tm/assign-id (->EditStructure action targets params)))
|
||||
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; remove-child — delete a shape
|
||||
;;
|
||||
|
||||
@ -188,11 +188,18 @@
|
||||
|
||||
(and (map? expected) (map? actual) (= (set (keys expected)) (set (keys actual))))
|
||||
(every? (fn [key]
|
||||
(same-state? (get expected key) (get actual key) tolerance
|
||||
(same-state? (get expected key) (get actual key)
|
||||
;; a bool or path stores its segments in single precision, and
|
||||
;; a bool computes them again from its children
|
||||
(if (and (contains? expected :parent-id) (#{:bool :path} (:type expected)))
|
||||
(max tolerance 1e-4)
|
||||
tolerance)
|
||||
(or geometry?
|
||||
(and (contains? expected :parent-id)
|
||||
(contains? #{:x :y :width :height :rotation :points
|
||||
:selrect :transform :transform-inverse} key)))))
|
||||
(or (contains? #{:x :y :width :height :rotation :points
|
||||
:selrect :transform :transform-inverse} key)
|
||||
;; the segments of a bool or path are its geometry
|
||||
(and (= :content key) (#{:bool :path} (:type expected))))))))
|
||||
(keys expected))
|
||||
|
||||
(and (sequential? expected) (sequential? actual) (= (count expected) (count actual)))
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
Traces contain tree paths, never random UUIDs, and can be replayed."
|
||||
(:refer-clojure :exclude [flush])
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
@ -26,6 +27,7 @@
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.comp.runner :as r]
|
||||
[app.common.test-helpers.composable.comp.setups :as setup]
|
||||
[app.common.test-helpers.composable.comp.undo-check :as uc]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.composable.grid :as grid]
|
||||
[app.common.test-helpers.composable.oracle :as oracle]
|
||||
@ -41,6 +43,7 @@
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.string :as str]
|
||||
[clojure.test.check.generators :as gen]))
|
||||
@ -374,11 +377,17 @@
|
||||
1 (and (nil? (:shape-ref shape))
|
||||
(not (ctk/main-instance? shape))
|
||||
(some ctk/main-instance? (cfh/get-parents objects (:id shape))))
|
||||
2 (and (:shape-ref shape) (nil? (:component-id shape)))
|
||||
;; the model places the children of a group in a
|
||||
;; copy only as far as the group's board lets it
|
||||
2 (and (:shape-ref shape) (nil? (:component-id shape))
|
||||
(not (#{:group :bool} (:type (get objects (:parent-id shape))))))
|
||||
3 (and (copy-head shape) (not (top-copy shape)))
|
||||
4 (top-copy shape)))
|
||||
(:text :text-style) (= :text (:type shape))
|
||||
:add-child (ctk/main-instance? shape)
|
||||
;; a shape a main holds, other than its root
|
||||
:structure (and (nil? (:shape-ref shape)) (not (ctk/main-instance? shape))
|
||||
(some ctk/main-instance? (cfh/get-parents objects (:id shape))))
|
||||
:remove-child (and (= :rect (:type shape)) (nil? (:shape-ref shape))
|
||||
(some ctk/main-instance? (cfh/get-parents-with-self objects (:id shape))))
|
||||
:duplicate (and (top-copy shape) (< (count objects) (get situation :shape-budget 120))
|
||||
@ -593,6 +602,37 @@
|
||||
[{:align-self :end} {:justify-self :center} {:align-self :center :justify-self :end}
|
||||
{:align-self :auto :justify-self :auto}])
|
||||
|
||||
(def structure-edits
|
||||
"Structure actions: the action and, for a bool, its type."
|
||||
[[:group] [:mask] [:ungroup] [:unmask] [:bool :union] [:bool :difference]
|
||||
[:bool :intersection] [:bool :exclude] [:path]])
|
||||
|
||||
(defn- structure-edit
|
||||
"The structure edit `property` names on the shape of `entry`, and the
|
||||
shapes it takes: with an odd `value`, its next sibling too when that is
|
||||
one a main holds as well. Nil when the shape cannot take it."
|
||||
[objects entry eligible property value]
|
||||
(let [[action bool-type] (nth structure-edits (mod (or property 0) (count structure-edits)))
|
||||
shape (:shape entry)
|
||||
parent (get objects (:parent-id shape))
|
||||
sibling (let [shapes (:shapes parent)
|
||||
index (d/index-of (vec shapes) (:id shape))]
|
||||
(get shapes (inc index)))
|
||||
pair (cond-> [(:id shape)]
|
||||
(and (odd? (or value 0)) sibling (contains? eligible sibling)) (conj sibling))
|
||||
;; removing a shape a main holds leaves its copies referring to it
|
||||
;; until sync, so no edit removes one: no ungroup, and no grouping
|
||||
;; that takes every child out of a group
|
||||
empties? (and (#{:group :bool} (:type parent)) (= (set pair) (set (:shapes parent))))
|
||||
targets (case action
|
||||
(:group :mask) (when-not empties? pair)
|
||||
:bool (when (not-any? #(= :text (:type (get objects %))) pair) pair)
|
||||
:ungroup nil
|
||||
:unmask (when (:masked-group shape) [(:id shape)])
|
||||
:path (when (#{:rect :circle} (:type shape)) [(:id shape)]))]
|
||||
(when targets
|
||||
{:action action :targets targets :bool-type bool-type})))
|
||||
|
||||
(def grid-track-edits
|
||||
"Track editor actions: the action and the kind of track it edits."
|
||||
[[:add :row] [:add :column] [:remove :row] [:remove :column] [:resize :row] [:resize :column]
|
||||
@ -662,6 +702,14 @@
|
||||
(when-let [edit (grid-track-edit shape property value scope)]
|
||||
(when (or (nil? (:shape-ref shape)) (= :resize (:action edit)))
|
||||
(assoc entry :grid-track edit)))))
|
||||
(= :structure kind)
|
||||
((fn [items]
|
||||
(let [objects (:objects (thf/current-page (tm/file situation)))
|
||||
eligible (into #{} (map (comp :id :shape)) items)]
|
||||
(keep (fn [entry]
|
||||
(when-let [edit (structure-edit objects entry eligible property value)]
|
||||
(assoc entry :structure edit)))
|
||||
items))))
|
||||
(= :grid-cell kind)
|
||||
(filter #(seq (get-in % [:shape :layout-grid-cells])))
|
||||
(= kind :style)
|
||||
@ -723,6 +771,8 @@
|
||||
(case kind
|
||||
(:edit :style) (n/change-property target property value)
|
||||
:grid-direction (n/edit-grid target :direction (nth [:row :column] (mod (or (nth tuple 3 nil) 0) 2)))
|
||||
:structure (let [{:keys [action targets bool-type]} (:structure selected)]
|
||||
(n/edit-structure action (mapv constantly targets) :bool-type bool-type))
|
||||
:grid-track (n/edit-grid-track target (get-in selected [:grid-track :action])
|
||||
(get-in selected [:grid-track :value]))
|
||||
:grid-cell (let [cells (grid/get-cells (:shape selected))
|
||||
@ -825,9 +875,10 @@
|
||||
[before after journal]
|
||||
(let [undone (r/step (restore-references after (:reference-before journal)) (n/undo))
|
||||
redone (r/step (restore-references undone (:reference-after journal)) (n/redo))]
|
||||
(when-not (= before (oracle/history-snapshot undone))
|
||||
;; geometry a group derives from its children may differ in its last bits
|
||||
(when-not (uc/same-state? before (oracle/history-snapshot undone))
|
||||
(oracle/fail :I7 {:phase :undo :diff (thn/diff before (oracle/history-snapshot undone))}))
|
||||
(when-not (= (oracle/history-snapshot after) (oracle/history-snapshot redone))
|
||||
(when-not (uc/same-state? (oracle/history-snapshot after) (oracle/history-snapshot redone))
|
||||
(oracle/fail :I7 {:phase :redo}))))
|
||||
|
||||
(defn- synchronizable-components
|
||||
@ -1004,8 +1055,14 @@
|
||||
placed? (not (contains? (oracle/derived-attributes objects shape) :x))
|
||||
;; a copy parent makes the shape's place an override
|
||||
position? (and (:shape-ref parent) placed?)
|
||||
;; a parent board's later resizes move and size the shape through its constraints
|
||||
origin (when (and parent (not (cfh/root? parent)) placed?) parent)
|
||||
;; a parent board's later resizes move and size the shape through its
|
||||
;; constraints; a group or bool takes its bounds from its children, so its
|
||||
;; children follow the board around it
|
||||
board (if (#{:group :bool} (:type parent))
|
||||
(let [frame (get objects (:frame-id shape))]
|
||||
(when-not (ctl/any-layout? frame) frame))
|
||||
parent)
|
||||
origin (when (and board (not (cfh/root? board)) placed?) board)
|
||||
changed? (or (not (shadow/same-value? shape-after group (shadow/values shape group)))
|
||||
;; a stored turn may read the same under one flip while the transform turns
|
||||
(not (gmt/close? (or (:transform shape) (gmt/matrix)) (or (:transform shape-after) (gmt/matrix))))
|
||||
@ -1208,11 +1265,11 @@
|
||||
(when-not (= depth (count undo))
|
||||
(oracle/fail :I7 {:phase :history-depth :runner depth :model (count undo)}))
|
||||
(when-not (if (:accepted-libraries situation)
|
||||
(= (get baseline (:id (tm/file situation)))
|
||||
(get (oracle/history-snapshot undone) (:id (tm/file situation))))
|
||||
(= baseline (oracle/history-snapshot undone)))
|
||||
(uc/same-state? (get baseline (:id (tm/file situation)))
|
||||
(get (oracle/history-snapshot undone) (:id (tm/file situation))))
|
||||
(uc/same-state? baseline (oracle/history-snapshot undone)))
|
||||
(oracle/fail :I7 {:phase :sequence-undo}))
|
||||
(when-not (= (oracle/history-snapshot situation) (oracle/history-snapshot redone))
|
||||
(when-not (uc/same-state? (oracle/history-snapshot situation) (oracle/history-snapshot redone))
|
||||
(oracle/fail :I7 {:phase :sequence-redo}))))
|
||||
|
||||
(defn- check-source-sequences
|
||||
@ -1353,6 +1410,10 @@
|
||||
(conj [1 (gen/fmap (fn [index]
|
||||
[[:library-delete index] [:library-sync]
|
||||
[:library-restore index] [:library-sync]]) gen/nat)])
|
||||
(every? (set kinds) [:structure :add-child])
|
||||
(conj [6 (gen/fmap (fn [[parent index edit value]]
|
||||
[[:add-child parent] [:structure index edit value]])
|
||||
(gen/tuple gen/nat gen/nat (gen/choose 0 (dec (count structure-edits))) gen/nat))])
|
||||
(contains? (set kinds) :grid-track)
|
||||
(conj [6 (gen/fmap (fn [[index edit value scope]] [[:grid-track index edit value scope]])
|
||||
(gen/tuple gen/nat (gen/choose 0 (dec (count grid-track-edits))) gen/nat gen/nat))])
|
||||
@ -1475,6 +1536,24 @@
|
||||
:grid-square (= grid :square) :grid-empty (= grid :empty)}]
|
||||
:ops ops}))
|
||||
|
||||
(def shape-structure-kinds (into swap-kinds [:structure]))
|
||||
|
||||
(def shape-structure-coverage-kinds
|
||||
"The kinds the shape structure programs must cover: the structure edits,
|
||||
the children they act on and the steps that carry them into copies."
|
||||
[:structure :add-child :edit :update-main :sync :undo :redo])
|
||||
|
||||
(def shape-structure-program-gen
|
||||
"Histories that group, mask, combine and convert the shapes mains hold."
|
||||
(gen/let [components (gen/choose 2 3)
|
||||
depth (gen/choose 0 2)
|
||||
layout (gen/elements [nil :flex :grid])
|
||||
layout-children gen/boolean
|
||||
ops (operation-gen shape-structure-kinds)]
|
||||
{:world [components depth {:variants true :rich-variants true :text true :layout layout
|
||||
:layout-copies true :layout-children layout-children}]
|
||||
:ops ops}))
|
||||
|
||||
(def grid-kinds (into swap-kinds [:grid-track]))
|
||||
|
||||
(def grid-coverage-kinds
|
||||
|
||||
@ -112,18 +112,28 @@
|
||||
mirror? #(not= (boolean (:flip-x %)) (boolean (:flip-y %)))]
|
||||
(mod (if (and (mirror? flips') (or (= sign -1) (not (mirror? values)))) (- turn) turn) 360)))
|
||||
|
||||
(defn boxed
|
||||
"`shape` with the box of its selrect when it has none of its own, as a bool
|
||||
or a path keeps its geometry in its selrect and points only."
|
||||
[shape]
|
||||
(if (and (map? shape) (nil? (:width shape)) (:selrect shape))
|
||||
(merge shape (select-keys (:selrect shape) [:x :y :width :height]))
|
||||
shape))
|
||||
|
||||
(defn child-placement
|
||||
"Place a main child against its expected copy parent. Only lower-level
|
||||
constraint and matrix math is shared with production, not sync code."
|
||||
[main main-parent parent objects]
|
||||
(let [resized (if (and (mth/close? (:width main-parent) (:width parent) 0.01)
|
||||
(mth/close? (:height main-parent) (:height parent) 0.01))
|
||||
(let [main-box (boxed main-parent)
|
||||
box (boxed parent)
|
||||
resized (if (and (mth/close? (:width main-box) (:width box) 0.01)
|
||||
(mth/close? (:height main-box) (:height box) 0.01))
|
||||
objects
|
||||
;; a layout owns a filling or hugging parent's size and would drop
|
||||
;; the resize, so the parent takes it as a fixed size
|
||||
(let [tree (gm/set-objects-modifiers
|
||||
{(:id main-parent)
|
||||
{:modifiers (ctm/change-size main-parent (:width parent) (:height parent))}}
|
||||
{:modifiers (ctm/change-size main-parent (:width box) (:height box))}}
|
||||
(update objects (:id main-parent) assoc
|
||||
:layout-item-h-sizing :fix :layout-item-v-sizing :fix))]
|
||||
(reduce-kv (fn [objects id {:keys [modifiers]}]
|
||||
|
||||
@ -118,7 +118,9 @@
|
||||
"Matrix coefficients have no pixel unit. Compare their effect over the
|
||||
shape's local bounds. Keep the inputs for paired derived-axis comparison."
|
||||
[shape matrix derived]
|
||||
(let [bounds (select-keys shape [:width :height])
|
||||
(let [;; a bool or path has its size in its selrect only
|
||||
bounds {:width (or (:width shape) (get-in shape [:selrect :width]) 0)
|
||||
:height (or (:height shape) (get-in shape [:selrect :height]) 0)}
|
||||
half-width (/ (:width bounds) 2)
|
||||
half-height (/ (:height bounds) 2)]
|
||||
(with-meta
|
||||
@ -153,6 +155,11 @@
|
||||
node))
|
||||
content))
|
||||
|
||||
;; the order of a bool's corners: by position, to the hundredth of a pixel,
|
||||
;; so noise in one coordinate does not swap two corners
|
||||
(def ^:private corner-order
|
||||
(juxt #(Math/round (* 100.0 (:x %))) #(Math/round (* 100.0 (:y %)))))
|
||||
|
||||
(defn design-snapshot
|
||||
"Design inputs without derived placement, dimensions and bookkeeping.
|
||||
Geometry remains unrounded; equivalent? applies its tolerance directly."
|
||||
@ -172,6 +179,13 @@
|
||||
:flip-y false)
|
||||
(update :fixed-scroll boolean))
|
||||
(= :text (:type value)) (update :content (comp thtx/view canonical-variants))
|
||||
;; path segments as plain data, so geometry tolerance reaches their points
|
||||
(and (= :path (:type value)) (some? (:content value))) (update :content #(into [] %))
|
||||
;; a bool computes its segments from its children, which the design
|
||||
;; holds, in an order that depends on how it was computed
|
||||
(= :bool (:type value)) (-> (dissoc :content)
|
||||
;; and its corners in their order
|
||||
(update :points #(some->> % (sort-by corner-order) vec)))
|
||||
;; the transform carries the turn, whichever rotation the shape
|
||||
;; stores for it
|
||||
:always (dissoc :rotation))
|
||||
@ -185,8 +199,14 @@
|
||||
[id (-> (gsh/move shape
|
||||
(gpt/negate
|
||||
(or (get origins id)
|
||||
(gpt/point (get-in objects [(:parent-id shape) :x] 0)
|
||||
(get-in objects [(:parent-id shape) :y] 0)))))
|
||||
;; a group or bool takes its bounds from its
|
||||
;; children, so they measure from its board
|
||||
(let [parent (get objects (:parent-id shape))
|
||||
parent (if (#{:group :bool} (:type parent))
|
||||
(get objects (:frame-id shape))
|
||||
parent)]
|
||||
(gpt/point (or (:x parent) (get-in parent [:selrect :x]) 0)
|
||||
(or (:y parent) (get-in parent [:selrect :y]) 0))))))
|
||||
(as-> moved (let [derived (derived-attributes objects shape)]
|
||||
(assoc moved
|
||||
:transform (matrix-effect shape (:transform moved) derived)
|
||||
@ -311,7 +331,9 @@
|
||||
on the copy (`centred?`) assumed the main's size, so a derived resize keeps
|
||||
the shape's first corner, as a layout resize does."
|
||||
[objects shape expected centred?]
|
||||
(let [derived (cond-> (derived-attributes objects shape)
|
||||
(let [shape (geom/boxed shape)
|
||||
expected (geom/boxed expected)
|
||||
derived (cond-> (derived-attributes objects shape)
|
||||
centred? (into (constraint-derived-attributes shape)))
|
||||
width (if (contains? derived :width) (:width shape) (:width expected))
|
||||
height (if (contains? derived :height) (:height shape) (:height expected))
|
||||
@ -470,7 +492,9 @@
|
||||
(defn- geometry-differences
|
||||
([objects shape expected] (geometry-differences objects shape expected shape))
|
||||
([objects shape expected ownership]
|
||||
(let [rotation (or (:rotation shape) 0)
|
||||
(let [shape (geom/boxed shape)
|
||||
expected (geom/boxed expected)
|
||||
rotation (or (:rotation shape) 0)
|
||||
exp-rotation (or (:rotation expected) 0)
|
||||
;; Under one flip, either order of turn and flip stores the opposite turn.
|
||||
mirrored (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))
|
||||
@ -482,6 +506,7 @@
|
||||
width-owned (contains? derived :width)
|
||||
height-owned (contains? derived :height)
|
||||
;; Both flags and a half turn decompose the transform neither does.
|
||||
same-corners? (gsh/close-attrs? :points (:points shape) (:points expected) 0.01)
|
||||
both-flipped (and (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))
|
||||
(not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))
|
||||
(geom/decomposes? shape))]
|
||||
@ -493,15 +518,23 @@
|
||||
(and mirrored (same-turn? rotation (- exp-rotation)))
|
||||
(geom/decomposes? shape)
|
||||
(gsh/close-attrs? :points (:points shape) (:points expected) 0.01))) (conj :rotation)
|
||||
(and (not both-flipped) (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))) (conj :flip-x)
|
||||
(and (not both-flipped) (not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))) (conj :flip-y)
|
||||
;; ordered corners that match fix the transform, so flags that decompose
|
||||
;; it store the same transform otherwise
|
||||
(and (not both-flipped) (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))
|
||||
(not (and same-corners? (geom/decomposes? shape)))) (conj :flip-x)
|
||||
(and (not both-flipped) (not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))
|
||||
(not (and same-corners? (geom/decomposes? shape)))) (conj :flip-y)
|
||||
(and (not width-owned) (not (mth/close? (:width shape) (:width expected) 0.01))) (conj :width)
|
||||
(and (not height-owned) (not (mth/close? (:height shape) (:height expected) 0.01))) (conj :height)
|
||||
(and (not layout-child) auto-height
|
||||
(not (gsh/close-attrs? :points [(first (:points shape))]
|
||||
[(first (:points expected))] 0.01))) (conj :position)
|
||||
(and (not layout-child) (not auto-width) (not auto-height)
|
||||
(not (gsh/close-attrs? :points (:points shape) (:points expected) 0.01))) (conj :points)))))
|
||||
;; a bool computes its corners from its segments, in their order
|
||||
(not (if (= :bool (:type shape))
|
||||
(gsh/close-attrs? :points (sort-by corner-order (:points shape))
|
||||
(sort-by corner-order (:points expected)) 0.01)
|
||||
(gsh/close-attrs? :points (:points shape) (:points expected) 0.01)))) (conj :points)))))
|
||||
|
||||
(defn check-requested-geometry
|
||||
[objects actual expected]
|
||||
|
||||
@ -178,8 +178,14 @@
|
||||
(not (contains? (thtx/override-units (:content expected) (:content shape)) unit))
|
||||
(if (= group :geometry-group)
|
||||
(let [sized (if objects (layout-sized shape objects) #{})
|
||||
parent (get objects (:parent-id shape))
|
||||
;; a group or bool takes its bounds from its children, which follow its board
|
||||
parent (if (#{:group :bool} (:type parent))
|
||||
(let [frame (get objects (:frame-id shape))]
|
||||
(when-not (ctl/any-layout? frame) frame))
|
||||
parent)
|
||||
placed (when (and objects (not (:sized? (::position (meta expected)))))
|
||||
(authored-placement expected (get objects (:parent-id shape)) shape))
|
||||
(authored-placement expected parent shape))
|
||||
;; an unskewed transform carries the turn and the mirror: an
|
||||
;; expected rotation and flips match when they decompose it,
|
||||
;; whichever rotation and flips the shape stores for it
|
||||
@ -199,7 +205,10 @@
|
||||
(update :rotation + 180))
|
||||
expected)]
|
||||
(and (if placed
|
||||
(gsh/close-attrs? :points (:points shape) (:points placed) 0.01)
|
||||
;; a size the layout gives keeps the first corner
|
||||
(if (seq sized)
|
||||
(gsh/close-attrs? :points [(first (:points shape))] [(first (:points placed))] 0.01)
|
||||
(gsh/close-attrs? :points (:points shape) (:points placed) 0.01))
|
||||
true)
|
||||
(if (some? oriented) oriented true)
|
||||
(every? (fn [[key value]]
|
||||
@ -343,7 +352,10 @@
|
||||
(or (contains? groups :geometry-group) (contains? groups :swap-group) (nil? main))
|
||||
groups
|
||||
|
||||
(nil? (:shape-ref parent))
|
||||
;; a layout places the shape, so only its size and orientation can be its own
|
||||
(or (nil? (:shape-ref parent))
|
||||
(and (ctl/any-layout-immediate-child? after shape)
|
||||
(not (ctl/position-absolute? shape))))
|
||||
(kept-orientation groups shape)
|
||||
|
||||
(or (nil? main-parent)
|
||||
@ -369,9 +381,12 @@
|
||||
parent (in-orientation main-parent parent))]
|
||||
(cond-> groups
|
||||
(and main
|
||||
(nil? (:shape-ref parent))
|
||||
(or (nil? (:shape-ref parent))
|
||||
;; a layout places the shape and gives it the sizes it owns
|
||||
(and (ctl/any-layout-immediate-child? after shape)
|
||||
(not (ctl/position-absolute? shape))))
|
||||
(not (contains? groups :geometry-group))
|
||||
(not (same-value? shape :geometry-group expected)))
|
||||
(not (same-value? shape :geometry-group expected after)))
|
||||
(assoc :geometry-group (author-geometry shape nil)))))
|
||||
(visit [result id]
|
||||
(let [shape (get after id)
|
||||
@ -579,8 +594,9 @@
|
||||
topmost resized ancestor of the head: a sync resizes only a copy shape
|
||||
without authored geometry."
|
||||
[model before after]
|
||||
(let [sized-alike? #(and (mth/close? (:width %1) (:width %2))
|
||||
(mth/close? (:height %1) (:height %2)))
|
||||
(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))))
|
||||
;; whether `id` keeps its parent and has another size in `after`
|
||||
resized? (fn [id]
|
||||
(let [old (get before id) shape (get after id)]
|
||||
|
||||
@ -2353,6 +2353,34 @@
|
||||
(t/is (empty? (cg/coverage-errors @coverage cg/variant-coverage-kinds))
|
||||
(pr-str (cg/coverage-errors @coverage cg/variant-coverage-kinds)))))
|
||||
|
||||
(t/deftest unmasking-in-a-flex-main-leaves-its-layout-as-the-unmask-event-does
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants false :rich-variants false :text true :layout :flex
|
||||
:layout-copies false :layout-children true}]
|
||||
:ops [[:structure 11 1 13] [:structure 0 3]]}))))
|
||||
|
||||
(t/deftest a-moved-copy-that-hugs-its-grid-keeps-its-first-corner
|
||||
(t/is (map? (cg/run {:world [1 1 {:variants false :text-styles false :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square true :rich-variants false
|
||||
:layout-children false :grid-empty false :layout-copies false :text false}]
|
||||
:ops [[:transform 0 0 0 13] [:style 0 29 14]]}))))
|
||||
|
||||
(t/deftest turning-a-copy-whose-main-holds-a-bool-keeps-its-corners
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :layout nil
|
||||
:layout-copies true :layout-children false}]
|
||||
:ops [[:delete 0] [:restore 0] [:add-child 0] [:structure 0 4 0] [:rotate 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest random-shape-structure-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
(smt/check!
|
||||
(smt/for [program cg/shape-structure-program-gen]
|
||||
(cg/check-program program coverage failure))
|
||||
:max-size 30
|
||||
:default-num coverage-programs)
|
||||
(println "Shape structure operation coverage:" (pr-str @coverage))
|
||||
(t/is (empty? (cg/coverage-errors @coverage cg/shape-structure-coverage-kinds))
|
||||
(pr-str (cg/coverage-errors @coverage cg/shape-structure-coverage-kinds)))))
|
||||
|
||||
(t/deftest random-grid-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user