mirror of
https://github.com/penpot/penpot.git
synced 2025-05-30 18:56:10 +02:00
✨ Make precision closest point computation depend on zoom
This commit is contained in:
parent
a2ac2bc6c6
commit
e4f2dfaa11
2 changed files with 8 additions and 9 deletions
|
@ -182,11 +182,11 @@
|
||||||
;; FIXME: move to helpers?, this function need performance review, it
|
;; FIXME: move to helpers?, this function need performance review, it
|
||||||
;; is executed so many times on path edition
|
;; is executed so many times on path edition
|
||||||
(defn- curve-closest-point
|
(defn- curve-closest-point
|
||||||
[position start end h1 h2]
|
[position start end h1 h2 precision]
|
||||||
(let [d (memoize (fn [t] (gpt/distance position (helpers/curve-values start end h1 h2 t))))]
|
(let [d (memoize (fn [t] (gpt/distance position (helpers/curve-values start end h1 h2 t))))]
|
||||||
(loop [t1 0.0
|
(loop [t1 0.0
|
||||||
t2 1.0]
|
t2 1.0]
|
||||||
(if (<= (mth/abs (- t1 t2)) path-closest-point-accuracy)
|
(if (<= (mth/abs (- t1 t2)) precision)
|
||||||
(-> (helpers/curve-values start end h1 h2 t1)
|
(-> (helpers/curve-values start end h1 h2 t1)
|
||||||
;; store the segment info
|
;; store the segment info
|
||||||
(with-meta {:t t1 :from-p start :to-p end}))
|
(with-meta {:t t1 :from-p start :to-p end}))
|
||||||
|
@ -214,7 +214,7 @@
|
||||||
(double t2)))))))
|
(double t2)))))))
|
||||||
|
|
||||||
(defn- line-closest-point
|
(defn- line-closest-point
|
||||||
"Point on line"
|
"Finds the closest point in the line segment defined by from-p and to-p"
|
||||||
[position from-p to-p]
|
[position from-p to-p]
|
||||||
|
|
||||||
(let [e1 (gpt/to-vec from-p to-p)
|
(let [e1 (gpt/to-vec from-p to-p)
|
||||||
|
@ -274,13 +274,12 @@
|
||||||
|
|
||||||
|
|
||||||
(defn closest-point
|
(defn closest-point
|
||||||
"Given a path and a position"
|
"Returns the closest point in the path to the position, at a given precision"
|
||||||
[content position]
|
[content position precision]
|
||||||
|
|
||||||
(let [point+distance
|
(let [point+distance
|
||||||
(fn [[cur-segment prev-segment]]
|
(fn [[cur-segment prev-segment]]
|
||||||
(let [from-p (helpers/segment->point prev-segment)
|
(let [from-p (helpers/segment->point prev-segment)
|
||||||
to-p (helpers/segment->point cur-segment)
|
to-p (helpers/segment->point cur-segment)
|
||||||
h1 (gpt/point (get-in cur-segment [:params :c1x])
|
h1 (gpt/point (get-in cur-segment [:params :c1x])
|
||||||
(get-in cur-segment [:params :c1y]))
|
(get-in cur-segment [:params :c1y]))
|
||||||
h2 (gpt/point (get-in cur-segment [:params :c2x])
|
h2 (gpt/point (get-in cur-segment [:params :c2x])
|
||||||
|
@ -291,7 +290,7 @@
|
||||||
(line-closest-point position from-p to-p)
|
(line-closest-point position from-p to-p)
|
||||||
|
|
||||||
:curve-to
|
:curve-to
|
||||||
(curve-closest-point position from-p to-p h1 h2)
|
(curve-closest-point position from-p to-p h1 h2 precision)
|
||||||
|
|
||||||
nil)]
|
nil)]
|
||||||
(when point
|
(when point
|
||||||
|
|
|
@ -348,7 +348,7 @@
|
||||||
ms/mouse-position
|
ms/mouse-position
|
||||||
(mf/deps base-content zoom)
|
(mf/deps base-content zoom)
|
||||||
(fn [position]
|
(fn [position]
|
||||||
(when-let [point (path.segment/closest-point base-content position)]
|
(when-let [point (path.segment/closest-point base-content position (/ 0.01 zoom))]
|
||||||
(reset! hover-point (when (< (gpt/distance position point) (/ 10 zoom)) point)))))
|
(reset! hover-point (when (< (gpt/distance position point) (/ 10 zoom)) point)))))
|
||||||
|
|
||||||
[:g.path-editor {:ref editor-ref}
|
[:g.path-editor {:ref editor-ref}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue