|
38 | 38 | (defmethod element.hierarchy/scale ::element.hierarchy/polyshape
|
39 | 39 | [el ratio pivot-point]
|
40 | 40 | (let [bounds-min (take 2 (element.hierarchy/bbox el))
|
41 |
| - pivot-point (matrix/sub pivot-point (matrix/mul pivot-point ratio))] |
| 41 | + offset (utils.element/scale-offset ratio pivot-point)] |
42 | 42 | (update-in el
|
43 | 43 | [:attrs :points]
|
44 | 44 | #(->> (utils.attribute/str->seq %)
|
45 | 45 | (transduce
|
46 | 46 | partition-to-px
|
47 | 47 | (fn [points point]
|
48 | 48 | (let [rel-point (matrix/sub bounds-min point)
|
49 |
| - offset (matrix/add pivot-point (matrix/sub rel-point (matrix/mul rel-point ratio)))] |
| 49 | + offset (->> ratio |
| 50 | + (matrix/mul rel-point) |
| 51 | + (matrix/sub rel-point) |
| 52 | + (matrix/add offset))] |
50 | 53 | (translate offset points point))) [])
|
51 | 54 | (string/join " ")
|
52 | 55 | (string/trim)))))
|
53 | 56 |
|
54 | 57 | (defmethod element.hierarchy/render-edit ::element.hierarchy/polyshape
|
55 | 58 | [el]
|
56 |
| - [:g (map-indexed (fn [index [x y]] |
57 |
| - (let [[x y] (mapv utils.length/unit->px [x y]) |
58 |
| - [x y] (matrix/add (utils.element/offset el) [x y])] |
| 59 | + [:g (map-indexed (fn [index point] |
| 60 | + (let [offset (utils.element/offset el) |
| 61 | + [x y] (->> point |
| 62 | + (mapv utils.length/unit->px) |
| 63 | + (matrix/add offset))] |
59 | 64 | ^{:key index}
|
60 | 65 | [tool.views/square-handle {:id (keyword (str index))
|
61 | 66 | :x x
|
|
87 | 92 | max-y (apply max (map #(utils.length/unit->px (second %)) points))]
|
88 | 93 | [min-x min-y max-x max-y]))
|
89 | 94 |
|
90 |
| -(defn calc-polygon-area |
91 |
| - [vertices] |
92 |
| - (let [count-v (count vertices)] |
| 95 | +(defn ->vertices |
| 96 | + [el] |
| 97 | + (-> el :attrs :points points->px)) |
| 98 | + |
| 99 | +(defmethod element.hierarchy/area ::element.hierarchy/polyshape |
| 100 | + [el] |
| 101 | + (let [vertices (->vertices el) |
| 102 | + count-v (count vertices)] |
93 | 103 | (/ (reduce-kv (fn [area index point]
|
94 | 104 | (let [point-b (if (= index (dec count-v))
|
95 | 105 | (first vertices)
|
|
100 | 110 | 0
|
101 | 111 | vertices) 2)))
|
102 | 112 |
|
103 |
| -(defmethod element.hierarchy/area ::element.hierarchy/polyshape |
104 |
| - [{{:keys [points]} :attrs}] |
105 |
| - (let [points-v (points->px points)] |
106 |
| - (calc-polygon-area points-v))) |
107 |
| - |
108 | 113 | (defmethod element.hierarchy/centroid ::element.hierarchy/polyshape
|
109 |
| - [{{:keys [points]} :attrs}] |
110 |
| - (let [points-v (points->px points)] |
111 |
| - (matrix/div (reduce matrix/add [0 0] points-v) |
112 |
| - (count points-v)))) |
| 114 | + [el] |
| 115 | + (let [vertices (->vertices el)] |
| 116 | + (-> (reduce matrix/add [0 0] vertices) |
| 117 | + (matrix/div (count vertices))))) |
113 | 118 |
|
114 | 119 | (defmethod element.hierarchy/snapping-points ::element.hierarchy/polyshape
|
115 |
| - [{{:keys [points]} :attrs}] |
116 |
| - (points->px points)) |
| 120 | + [el] |
| 121 | + (->vertices el)) |
0 commit comments