Alonso Torres 217284b1e1
✨ Improve path operations and edition (#10807)
* ✨ Improve path operations and edition

* 🐛 Fix floating-point equality issues in path editing

Replace exact equality checks with tolerance-based comparisons
in path editing functions to handle floating-point rounding
differences after transforms, rotations, or curve fitting.

Changes:
- distribute-content: Round coordinates to 0.1 precision before
  grouping to ensure coincident nodes move together
- separate-node: Use gpt/close? instead of exact equality to
  find nodes with floating-point imprecision
- collision-step: Use mth/close? for tolerance-based comparison
  to detect paste collisions correctly
- resolve-edit-fills: Add cycle detection to prevent infinite
  loops with corrupted parent chains

Made collision-step, available-offset-step, and resolve-edit-fills
public for better testability.

Added comprehensive tests for all fixes covering both exact and
floating-point coordinate scenarios.

AI-assisted-by: qwen3.7-plus

* 🐛 Fix path editor code review findings

Fix issues identified during code review of path editor enhancements:

- Fix unused binding lint warning in distribute-content that blocked CI
- Fix collision-step floor comparison to use round instead of floor,
  correctly detecting collisions when coordinates drift slightly below
  integer boundaries
- Fix resolve-edit-fills to recurse through empty parent groups when
  searching for inherited fills in nested group hierarchies
- Fix expand-coincident-node-indices to use fuzzy comparison (gpt/close?)
  instead of exact equality, handling floating-point divergence after
  transforms or rotations
- Remove unreachable dead code in path-point* on-pointer-down handler
- Add tests for collision-step boundary cases, nested group fill
  inheritance, and coincident node alignment/flipping

AI-assisted-by: mimo-v2.5-pro

---------

Co-authored-by: Andrey Antukh <niwi@niwi.nz>
2026-08-27 10:51:10 +02:00

81 lines
2.5 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns app.main.data.workspace.edition
(:require
[app.main.data.helpers :as dsh]
[app.main.data.workspace.path.common :as dwpc]
[app.main.data.workspace.path.state :as path.state]
[app.main.features :as features]
[app.render-wasm.api :as wasm.api]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
(defn interrupt?
[e]
(= e :interrupt))
(declare clear-edition-mode)
(defn start-edition-mode
"Mark a shape in edition mode"
[id]
(assert (uuid? id) "expected valid uuid for `id`")
(ptk/reify ::start-edition-mode
ptk/UpdateEvent
(update [_ state]
(let [objects (dsh/lookup-page-objects state)]
;; Can only edit objects that exist
(if (contains? objects id)
(-> state
(update :workspace-local assoc :edition id)
(dissoc :workspace-grid-edition))
state)))
ptk/WatchEvent
(watch [_ _ stream]
(->> stream
(rx/filter interrupt?)
(rx/take 1)
(rx/map clear-edition-mode)))))
;; IMPORTANT: If this event is moved from this namespace to other,
;; update namespace reference in the
;; app/main/data/workspace/path/undo.cljs file.
(defn clear-edition-mode
[]
(let [path-id (volatile! nil)]
(ptk/reify ::clear-edition-mode
ptk/UpdateEvent
(update [_ state]
(let [edition-id (get-in state [:workspace-local :edition])
path-editing? (path.state/editing? state)]
(vreset! path-id (when path-editing? edition-id))
(-> state
(update :workspace-local dissoc :edition)
(cond-> (not path-editing?)
(update :workspace-local dissoc :edit-path)
(not path-editing?)
(update :workspace-drawing dissoc :object :lock))
(dissoc :workspace-grid-edition)
(dissoc :workspace-wasm-editor-styles))))
ptk/WatchEvent
(watch [_ _ _]
(if (some? @path-id)
(rx/of (dwpc/finish-path))
(rx/empty)))
ptk/EffectEvent
(effect [_ state _]
(when (features/active-feature? state "text-editor-wasm/v1")
;; NOTE: the WASM text editor is disposed by the v3 editor component on
;; unmount, *after* it finalizes its content.
(wasm.api/request-render "clear-edition-mode"))))))