From 1bd3a792dad3a9b9176be75e18e8309cadce6eb3 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Sep 2021 11:30:06 +0200 Subject: [PATCH] :sparkles: Improved intersection edge cases --- common/src/app/common/geom/shapes/path.cljc | 20 ++++++++++++------- .../src/app/common/pages/changes_builder.cljc | 15 ++++++-------- .../src/app/common/path/shapes_to_path.cljc | 8 ++++---- frontend/src/app/main/ui/shapes/bool.cljs | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/common/src/app/common/geom/shapes/path.cljc b/common/src/app/common/geom/shapes/path.cljc index dea5a3e50..4569a2cb9 100644 --- a/common/src/app/common/geom/shapes/path.cljc +++ b/common/src/app/common/geom/shapes/path.cljc @@ -63,10 +63,9 @@ cy (:y p) ay (:y to-p) by (:y from-p)] - (cond - (> (- cy ay) 0) 1 - (< (- cy ay) 0) -1 + (and (> (- cy ay) 0) (not (s= cy ay))) 1 + (and (< (- cy ay) 0) (not (s= cy ay))) -1 (< (- cy by) 0) 1 (> (- cy by) 0) -1 :else 0))) @@ -558,8 +557,14 @@ (defn- get-line-tval [[{x1 :x y1 :y} {x2 :x y2 :y}] {:keys [x y]}] - (if (mth/almost-zero? (- x2 x1)) + (cond + (and (s= x1 x2) (s= y1 y2)) + ##Inf + + (s= x1 x2) (/ (- y y1) (- y2 y1)) + + :else (/ (- x x1) (- x2 x1)))) (defn- curve-range->rect @@ -578,15 +583,16 @@ {x2 :x y2 :y} to-p {px :x py :y} point - m (/ (- y2 y1) (- x2 x1)) - vy (+ (* m px) (* (- m) x1) y1) + m (when-not (s= x1 x2) (/ (- y2 y1) (- x2 x1))) + vy (when (some? m) (+ (* m px) (* (- m) x1) y1)) t (get-line-tval line point)] + ;; If x1 = x2 there is no slope, to see if the point is in the line ;; only needs to check the x is the same (and (or (and (s= x1 x2) (s= px x1)) - (s= py vy)) + (and (some? vy) (s= py vy))) ;; This will check if is between both segments (or (> t 0) (s= t 0)) (or (< t 1) (s= t 1))))) diff --git a/common/src/app/common/pages/changes_builder.cljc b/common/src/app/common/pages/changes_builder.cljc index a591913ff..d9567242c 100644 --- a/common/src/app/common/pages/changes_builder.cljc +++ b/common/src/app/common/pages/changes_builder.cljc @@ -13,17 +13,14 @@ ;; Auxiliary functions to help create a set of changes (undo + redo) (defn empty-changes [origin page-id] - (with-meta - {:redo-changes [] - :undo-changes [] - :origin origin} - {::page-id page-id})) + (let [changes {:redo-changes [] + :undo-changes [] + :origin origin}] + (with-meta changes + {::page-id page-id}))) (defn with-objects [changes objects] - (with-meta - changes - (-> (meta changes) - (assoc ::objects objects)))) + (vary-meta changes assoc ::objects objects)) (defn add-obj ([changes obj index] diff --git a/common/src/app/common/path/shapes_to_path.cljc b/common/src/app/common/path/shapes_to_path.cljc index 83a9358c8..24cbd1892 100644 --- a/common/src/app/common/path/shapes_to_path.cljc +++ b/common/src/app/common/path/shapes_to_path.cljc @@ -16,23 +16,23 @@ (def ^:const bezier-circle-c 0.551915024494) -(def ^:const dissoc-attrs +(def dissoc-attrs [:x :y :width :height :rx :ry :r1 :r2 :r3 :r4 :metadata :shapes]) -(def ^:const allowed-transform-types +(def allowed-transform-types #{:rect :circle :image :group :bool}) -(def ^:const style-group-properties +(def style-group-properties [:shadow :blur]) -(def ^:const style-properties +(def style-properties (d/concat style-group-properties [:fill-color diff --git a/frontend/src/app/main/ui/shapes/bool.cljs b/frontend/src/app/main/ui/shapes/bool.cljs index e4f8fc3dc..ebbe4753f 100644 --- a/frontend/src/app/main/ui/shapes/bool.cljs +++ b/frontend/src/app/main/ui/shapes/bool.cljs @@ -44,7 +44,7 @@ (assoc :type :path) (assoc :stroke-color "blue") (assoc :stroke-opacity 1) - (assoc :stroke-width 0.5) + (assoc :stroke-width 1) (assoc :stroke-style :solid) (dissoc :fill-color :fill-opacity) (assoc :content content-b))