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:
parent
48af73792e
commit
c3cbd10d69
1 changed files with 5 additions and 9 deletions
|
@ -11,23 +11,19 @@
|
||||||
[uxbox.worker.core :as wrk]
|
[uxbox.worker.core :as wrk]
|
||||||
[uxbox.util.geom.point :as gpt]))
|
[uxbox.util.geom.point :as gpt]))
|
||||||
|
|
||||||
(defonce state (volatile! nil))
|
(defonce tree (kd/create))
|
||||||
|
|
||||||
(defmethod wrk/handler :grid/init
|
(defmethod wrk/handler :grid/init
|
||||||
[{:keys [sender width height x-axis y-axis] :as opts}]
|
[{:keys [sender width height x-axis y-axis] :as opts}]
|
||||||
(time
|
(time
|
||||||
(let [points (into-array
|
(let [value (kd/generate width height (or x-axis 10) (or y-axis 10))]
|
||||||
(for [x (range 0 width (or x-axis 10))
|
(set! tree value)))
|
||||||
y (range 0 height (or y-axis 10))]
|
(wrk/reply! sender nil))
|
||||||
#js [x y]))
|
|
||||||
tree (kd/create2d points)]
|
|
||||||
(vreset! state tree)
|
|
||||||
(wrk/reply! sender nil))))
|
|
||||||
|
|
||||||
(defmethod wrk/handler :grid/align
|
(defmethod wrk/handler :grid/align
|
||||||
[{:keys [sender point] :as message}]
|
[{:keys [sender point] :as message}]
|
||||||
(let [point #js [(:x point) (:y point)]
|
(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)
|
[[x y] d] (first results)
|
||||||
result (gpt/point x y)]
|
result (gpt/point x y)]
|
||||||
(wrk/reply! sender {:point (gpt/point x y)})))
|
(wrk/reply! sender {:point (gpt/point x y)})))
|
||||||
|
|
Loading…
Reference in a new issue