Skip to content

Commit 72e1d34

Browse files
committed
performance enhancements
1 parent 189bd7a commit 72e1d34

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/renderer/element/handlers.cljs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@
2323
[renderer.utils.path :as utils.path :refer [PathManipulation PathBooleanOperation]]
2424
[renderer.utils.vec :as utils.vec]))
2525

26-
(m/=> path [:-> App [:* [:or keyword? uuid?]] vector?])
26+
(m/=> path [:function
27+
[:-> App vector?]
28+
[:-> App uuid? vector?]
29+
[:-> App uuid? keyword? vector?]
30+
[:-> App uuid? keyword? [:* any?] vector?]])
2731
(defn path
28-
[db & more]
29-
(apply conj [:documents (:active-document db) :elements] more))
32+
([db]
33+
[:documents (:active-document db) :elements])
34+
([db id]
35+
(conj (path db) id))
36+
([db id prop]
37+
(conj (path db) id prop))
38+
([db id prop & more]
39+
(apply conj (path db) id prop more)))
3040

3141
(m/=> entities [:function
3242
[:-> App [:maybe [:map-of uuid? Element]]]

src/renderer/snap/handlers.cljs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,27 @@
2828
(m/=> update-nearest-neighbors [:-> App App])
2929
(defn update-nearest-neighbors
3030
[db]
31-
(let [zoom (get-in db [:documents (:active-document db) :zoom])
32-
threshold (-> db :snap :threshold)
33-
threshold (Math/pow (/ threshold zoom) 2)
34-
nneighbors (nearest-neighbors db)
35-
nneighbors (filter #(< (:dist-squared %) threshold) nneighbors)]
36-
(assoc db
37-
:nearest-neighbors nneighbors
38-
:nearest-neighbor (apply min-key :dist-squared nneighbors))))
31+
(if-not (-> db :snap :active)
32+
db
33+
(let [zoom (get-in db [:documents (:active-document db) :zoom])
34+
threshold (-> db :snap :threshold)
35+
threshold (Math/pow (/ threshold zoom) 2)
36+
nneighbors (nearest-neighbors db)
37+
nneighbors (filter #(< (:dist-squared %) threshold) nneighbors)]
38+
(assoc db
39+
:nearest-neighbors nneighbors
40+
:nearest-neighbor (apply min-key :dist-squared nneighbors)))))
3941

4042
(m/=> update-viewport-tree [:-> App App])
4143
(defn update-viewport-tree
4244
[db]
43-
(let [[x y width height] (frame.handlers/viewbox db)
44-
boundaries [[x (+ x width)] [y (+ y height)]]]
45-
(assoc db :viewbox-kdtree (-> (:kdtree db)
46-
(kdtree/interval-search boundaries)
47-
(kdtree/build-tree)))))
45+
(if-not (-> db :snap :active)
46+
db
47+
(let [[x y width height] (frame.handlers/viewbox db)
48+
boundaries [[x (+ x width)] [y (+ y height)]]]
49+
(assoc db :viewbox-kdtree (-> (:kdtree db)
50+
(kdtree/interval-search boundaries)
51+
(kdtree/build-tree))))))
4852

4953
(m/=> rebuild-tree [:-> App App])
5054
(defn rebuild-tree

src/renderer/tool/impl/base/transform.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@
390390

391391
(defmethod tool.hierarchy/snapping-points :transform
392392
[db]
393-
(let [elements (vals (element.handlers/entities db))
394-
selected (filter :selected elements)
393+
(let [selected (element.handlers/selected db)
395394
options (-> db :snap :options)]
396395
(cond
397396
(= (:state db) :scale)
@@ -461,7 +460,8 @@
461460
[:<>
462461
[tool.views/wrapping-bbox bbox]
463462
[tool.views/bounding-corners bbox]
464-
(when (= state :scale) [size-label bbox])])
463+
(when (= state :scale)
464+
[size-label bbox])])
465465

466466
(when pivot-point
467467
[utils.svg/times pivot-point])

0 commit comments

Comments
 (0)