mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 08:26:11 +02:00
Code cleaning and debug message for path simplification on free drawing mode.
This commit is contained in:
parent
53621ceeeb
commit
6b5888a6c2
1 changed files with 7 additions and 23 deletions
|
@ -242,28 +242,12 @@
|
||||||
(rx/filter #(= % :mouse/up))
|
(rx/filter #(= % :mouse/up))
|
||||||
(rx/take 1))
|
(rx/take 1))
|
||||||
stream (rx/take-until stoper mouse)]
|
stream (rx/take-until stoper mouse)]
|
||||||
(letfn [(normalize-shape [{:keys [points] :as shape}]
|
(letfn [(simplify-shape [{:keys [points] :as shape}]
|
||||||
(let [minx (apply min (map :x points))
|
(let [prevnum (count points)
|
||||||
miny (apply min (map :y points))
|
points (path/simplify points 0.2)]
|
||||||
maxx (apply max (map :x points))
|
(println "path simplification: previous=" prevnum
|
||||||
maxy (apply max (map :y points))
|
" current=" (count points))
|
||||||
|
(assoc shape :points points)))
|
||||||
;; dx (- 0 minx)
|
|
||||||
;; dy (- 0 miny)
|
|
||||||
;; _ (println "Initial number of points:" (count points))
|
|
||||||
;; points (mapv #(gpt/add % [dx dy]) points)
|
|
||||||
points (path/simplify points 0.1)
|
|
||||||
;; _ (println "Final number of points:" (count points))
|
|
||||||
width (- maxx minx)
|
|
||||||
height (- maxy miny)]
|
|
||||||
|
|
||||||
(assoc shape
|
|
||||||
:x1 minx
|
|
||||||
:y1 miny
|
|
||||||
:x2 maxx
|
|
||||||
:y2 maxy
|
|
||||||
:view-box [0 0 width height]
|
|
||||||
:points points)))
|
|
||||||
|
|
||||||
(on-draw [point]
|
(on-draw [point]
|
||||||
(let [point (gpt/point point)
|
(let [point (gpt/point point)
|
||||||
|
@ -272,7 +256,7 @@
|
||||||
(reset! drawing-shape shape)))
|
(reset! drawing-shape shape)))
|
||||||
|
|
||||||
(on-end []
|
(on-end []
|
||||||
(let [shape (normalize-shape @drawing-shape)]
|
(let [shape (simplify-shape @drawing-shape)]
|
||||||
(rs/emit! (uds/add-shape shape)
|
(rs/emit! (uds/add-shape shape)
|
||||||
(udw/select-for-drawing nil)
|
(udw/select-for-drawing nil)
|
||||||
(uds/select-first-shape))
|
(uds/select-first-shape))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue