0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Adapt align worker to use new faster generation of kd trees.

This commit is contained in:
Andrey Antukh 2016-06-11 19:52:27 +03:00
parent 48af73792e
commit c3cbd10d69
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -11,23 +11,19 @@
[uxbox.worker.core :as wrk]
[uxbox.util.geom.point :as gpt]))
(defonce state (volatile! nil))
(defonce tree (kd/create))
(defmethod wrk/handler :grid/init
[{:keys [sender width height x-axis y-axis] :as opts}]
(time
(let [points (into-array
(for [x (range 0 width (or x-axis 10))
y (range 0 height (or y-axis 10))]
#js [x y]))
tree (kd/create2d points)]
(vreset! state tree)
(wrk/reply! sender nil))))
(let [value (kd/generate width height (or x-axis 10) (or y-axis 10))]
(set! tree value)))
(wrk/reply! sender nil))
(defmethod wrk/handler :grid/align
[{:keys [sender point] :as message}]
(let [point #js [(:x point) (:y point)]
results (js->clj (.nearest @state point 1))
results (js->clj (kd/nearest tree point 1))
[[x y] d] (first results)
result (gpt/point x y)]
(wrk/reply! sender {:point (gpt/point x y)})))