File tree 6 files changed +47
-176
lines changed
.clj-kondo/metosin/malli-types-cljs
6 files changed +47
-176
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 9
9
[renderer.element.handlers :as element.h]
10
10
[renderer.snap.db :refer [SnapOption NearestNeighbor]]
11
11
[renderer.snap.subs :as-alias snap.s]
12
- [renderer.utils.element :as utils.el]
12
+ [renderer.utils.bounds :as bounds]
13
+ [renderer.utils.element :as element]
13
14
[renderer.utils.math :refer [Vec2D]]))
14
15
15
16
(m/=> toggle-option [:-> App SnapOption App])
23
24
(defn base-points
24
25
[db]
25
26
(let [elements (vals (element.h/entities db))
26
- selected-visible (filter #(and (:visible %) (:selected %)) elements)]
27
+ selected (filter :selected elements)
28
+ selected-visible (filter :visible selected)
29
+ options (-> db :snap :options )]
27
30
(when (-> db :snap :active )
28
31
(cond
29
- (and (contains? #{:translate :clone } (:state db)) (seq selected-visible))
30
- (reduce (fn [points element]
31
- (apply conj points (utils.el/snapping-points element (-> db :snap :options ))))
32
- [] selected-visible)
32
+ (and (contains? #{:translate :clone } (:state db)) (seq selected))
33
+ (reduce (fn [points el] (into points (element/snapping-points el options)))
34
+ (if (seq (rest selected))
35
+ (bounds/->snapping-points (element.h/bounds db) options)
36
+ [])
37
+ selected-visible)
33
38
34
39
(contains? #{:edit :scale } (:state db))
35
40
[(mat/add [(-> db :clicked-element :x ) (-> db :clicked-element :y )]
Original file line number Diff line number Diff line change 32
32
:<- [::options ]
33
33
(fn [[non-selected-visible-elements active options] _]
34
34
(when active
35
- (reduce (fn [points element]
36
- (apply conj points (utils.el/snapping-points element options)))
35
+ (reduce (fn [points el] (into points (utils.el/snapping-points el options)))
37
36
[] non-selected-visible-elements))))
38
37
39
38
(rf/reg-sub
Original file line number Diff line number Diff line change 2
2
(:require
3
3
[clojure.core.matrix :as mat]
4
4
[malli.core :as m]
5
+ [renderer.snap.db :refer [SnapOptions]]
5
6
[renderer.utils.dom :refer [DomElement]]
6
7
[renderer.utils.math :refer [Vec2D]]))
7
8
73
74
(<= top y)
74
75
(>= right x)
75
76
(>= bottom y)))
77
+
78
+ (m/=> ->snapping-points [:-> Bounds SnapOptions [:* Vec2D]])
79
+ (defn ->snapping-points
80
+ [bounds options]
81
+ (let [[x1 y1 x2 y2] bounds
82
+ [cx cy] (center bounds)]
83
+ (cond-> []
84
+ (:corners options)
85
+ (into [[x1 y1]
86
+ [x1 y2]
87
+ [x2 y1]
88
+ [x2 y2]])
89
+
90
+ (:centers options)
91
+ (into [[cx cy]])
92
+
93
+ (:midpoints options)
94
+ (into [[x1 cy]
95
+ [x2 cy]
96
+ [cx y1]
97
+ [cx y2]]))))
Original file line number Diff line number Diff line change 57
57
(defn snapping-points
58
58
[el options]
59
59
(let [points (or (element.hierarchy/snapping-points el) [])]
60
- (if-let [bounds (:bounds el)]
61
- (let [[x1 y1 x2 y2] bounds
62
- [cx cy] (utils.bounds/center bounds)]
63
- (cond-> points
64
- (:corners options)
65
- (into [[x1 y1]
66
- [x1 y2]
67
- [x2 y1]
68
- [x2 y2]])
69
-
70
- (:centers options)
71
- (into [[cx cy]])
72
-
73
- (:midpoints options)
74
- (into [[x1 cy]
75
- [x2 cy]
76
- [cx y1]
77
- [cx y2]])))
78
- points)))
60
+ (cond-> points
61
+ (:bounds el)
62
+ (into (utils.bounds/->snapping-points (:bounds el) options)))))
79
63
80
64
(m/=> attributes [:-> Element Attrs])
81
65
(defn attributes
Original file line number Diff line number Diff line change 36
36
(deftest test-center
37
37
(testing " center of bounds"
38
38
(is (= (bounds/center [0 0 10 10 ]) [5 5 ]))))
39
+
40
+ (deftest test-->snapping-points
41
+ (testing " snapping points of bounds"
42
+ (is (= (bounds/->snapping-points [0 0 10 10 ] #{:corners :centers :midpoints })
43
+ [[0 0 ] [0 10 ] [10 0 ] [10 10 ] [5 5 ] [0 5 ] [10 5 ] [5 0 ] [5 10 ]]))
44
+
45
+ (is (= (bounds/->snapping-points [0 0 10 10 ] #{}) []))))
You can’t perform that action at this time.
0 commit comments