diff --git a/common/src/app/common/geom/shapes/path.cljc b/common/src/app/common/geom/shapes/path.cljc index 54b7f165d..062f4ea46 100644 --- a/common/src/app/common/geom/shapes/path.cljc +++ b/common/src/app/common/geom/shapes/path.cljc @@ -284,13 +284,14 @@ ([command coord] (let [params (:params command) - xkey (cond (= :c1 coord) :c1x - (= :c2 coord) :c2x - :else :x) - ykey (cond (= :c1 coord) :c1y - (= :c2 coord) :c2y - :else :y) - + xkey (case coord + :c1 :c1x + :c2 :c2x + :x) + ykey (case coord + :c1 :c1y + :c2 :c2y + :y) x (get params xkey) y (get params ykey)] (when (and (some? x) (some? y)) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index e7cea35d3..44cc73b06 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -22,15 +22,18 @@ ;; --- Relative Movement (defn- move-selrect [selrect pt] - (let [dx (.-x pt) - dy (.-y pt)] - (-> selrect - (update :x + dx) - (update :y + dy) - (update :x1 + dx) - (update :y1 + dy) - (update :x2 + dx) - (update :y2 + dy)))) + (when (and (some? selrect) (some? pt)) + (let [dx (.-x pt) + dy (.-y pt) + {:keys [x y x1 y1 x2 y2 width height]} selrect] + {:x (if (some? x) (+ dx x) x) + :y (if (some? y) (+ dy y) y) + :x1 (if (some? x1) (+ dx x1) x1) + :y1 (if (some? y1) (+ dy y1) y1) + :x2 (if (some? x2) (+ dx x2) x2) + :y2 (if (some? y2) (+ dy y2) y2) + :width width + :height height}))) (defn- move-points [points move-vec] (->> points diff --git a/common/test/app/common/geom_shapes_test.cljc b/common/test/app/common/geom_shapes_test.cljc index 49d303611..72eb0e262 100644 --- a/common/test/app/common/geom_shapes_test.cljc +++ b/common/test/app/common/geom_shapes_test.cljc @@ -181,9 +181,11 @@ shape-before (-> (create-test-shape type {:modifiers modifiers}) (assoc :selrect selrect)) shape-after (gsh/transform-shape shape-before {:round-coords? false})] - (= (:selrect shape-before) (:selrect shape-after))) - :rect {:x 0 :y 0 :width ##Inf :height ##Inf} - :path {:x 0 :y 0 :width ##Inf :height ##Inf} + (= (:selrect shape-before) + (:selrect shape-after))) + + :rect {:x 0 :y 0 :x1 0 :y1 0 :x2 ##Inf :y2 ##Inf :width ##Inf :height ##Inf} + :path {:x 0 :y 0 :x1 0 :y1 0 :x2 ##Inf :y2 ##Inf :width ##Inf :height ##Inf} :rect nil :path nil)))