From e4f2dfaa11f9ad8e7a6ea1da57e570d15076332d Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Wed, 21 May 2025 21:29:40 +0200 Subject: [PATCH] :sparkles: Make precision closest point computation depend on zoom --- common/src/app/common/types/path/segment.cljc | 15 +++++++-------- .../app/main/ui/workspace/shapes/path/editor.cljs | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/common/src/app/common/types/path/segment.cljc b/common/src/app/common/types/path/segment.cljc index bf8184f03..773772afe 100644 --- a/common/src/app/common/types/path/segment.cljc +++ b/common/src/app/common/types/path/segment.cljc @@ -182,11 +182,11 @@ ;; FIXME: move to helpers?, this function need performance review, it ;; is executed so many times on path edition (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))))] (loop [t1 0.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) ;; store the segment info (with-meta {:t t1 :from-p start :to-p end})) @@ -214,7 +214,7 @@ (double t2))))))) (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] (let [e1 (gpt/to-vec from-p to-p) @@ -274,13 +274,12 @@ (defn closest-point - "Given a path and a position" - [content position] - + "Returns the closest point in the path to the position, at a given precision" + [content position precision] (let [point+distance (fn [[cur-segment 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]) (get-in cur-segment [:params :c1y])) h2 (gpt/point (get-in cur-segment [:params :c2x]) @@ -291,7 +290,7 @@ (line-closest-point position from-p to-p) :curve-to - (curve-closest-point position from-p to-p h1 h2) + (curve-closest-point position from-p to-p h1 h2 precision) nil)] (when point diff --git a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs index 1c8e91fcb..dede7d331 100644 --- a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs @@ -348,7 +348,7 @@ ms/mouse-position (mf/deps base-content zoom) (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))))) [:g.path-editor {:ref editor-ref}