From 7d464c14c01350e7483907e85e451650c18386cf Mon Sep 17 00:00:00 2001 From: "alonso.torres" <alonso.torres@kaleidos.net> Date: Thu, 21 May 2020 15:27:33 +0200 Subject: [PATCH] :recycle: Moved math and some geom namespaces to common --- common/uxbox/common/data.cljc | 3 + .../uxbox/common/geom/matrix.cljc | 23 +- .../uxbox/common/geom/point.cljc | 24 +- .../uxbox/common/geom/shapes.cljc | 11 +- .../uxbox/common/math.cljc | 61 +++-- frontend/src/uxbox/main/data/workspace.cljs | 8 +- .../src/uxbox/main/data/workspace/common.cljs | 2 +- .../main/data/workspace/notifications.cljs | 2 +- .../main/data/workspace/persistence.cljs | 2 +- .../src/uxbox/main/data/workspace/ruler.cljs | 95 ------- .../uxbox/main/data/workspace/transforms.cljs | 6 +- frontend/src/uxbox/main/exports.cljs | 8 +- frontend/src/uxbox/main/snap.cljs | 4 +- frontend/src/uxbox/main/streams.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/circle.cljs | 2 +- .../uxbox/main/ui/shapes/custom_stroke.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/frame.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/group.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/icon.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/image.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/path.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/rect.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/text.cljs | 6 +- frontend/src/uxbox/main/ui/viewer/header.cljs | 2 +- frontend/src/uxbox/main/ui/viewer/shapes.cljs | 6 +- .../src/uxbox/main/ui/viewer/thumbnails.cljs | 6 +- frontend/src/uxbox/main/ui/workspace.cljs | 2 +- .../src/uxbox/main/ui/workspace/drawarea.cljs | 8 +- .../uxbox/main/ui/workspace/frame_grid.cljs | 2 +- .../src/uxbox/main/ui/workspace/header.cljs | 2 +- .../src/uxbox/main/ui/workspace/rules.cljs | 2 +- .../src/uxbox/main/ui/workspace/scroll.cljs | 2 +- .../uxbox/main/ui/workspace/selection.cljs | 8 +- .../src/uxbox/main/ui/workspace/shapes.cljs | 2 +- .../uxbox/main/ui/workspace/shapes/bbox.cljs | 6 +- .../main/ui/workspace/shapes/common.cljs | 6 +- .../uxbox/main/ui/workspace/shapes/frame.cljs | 6 +- .../ui/workspace/shapes/interactions.cljs | 7 +- .../uxbox/main/ui/workspace/shapes/path.cljs | 3 - .../uxbox/main/ui/workspace/shapes/text.cljs | 3 +- .../ui/workspace/sidebar/options/frame.cljs | 4 +- .../workspace/sidebar/options/frame_grid.cljs | 2 +- .../workspace/sidebar/options/measures.cljs | 6 +- .../sidebar/options/rows/color_row.cljs | 2 +- .../ui/workspace/sidebar/options/stroke.cljs | 2 +- .../main/ui/workspace/snap_feedback.cljs | 2 +- .../src/uxbox/main/ui/workspace/viewport.cljs | 4 +- frontend/src/uxbox/util/color.cljs | 2 +- frontend/src/uxbox/util/data.cljs | 3 - frontend/src/uxbox/util/dom.cljs | 2 +- frontend/src/uxbox/util/geom/_matrix.js | 229 ----------------- frontend/src/uxbox/util/geom/_point.js | 242 ------------------ frontend/src/uxbox/util/geom/grid.cljs | 4 +- frontend/src/uxbox/util/geom/range_tree.cljs | 25 -- frontend/src/uxbox/util/geom/snap_points.cljs | 4 +- frontend/src/uxbox/util/perf.cljs | 11 +- frontend/src/uxbox/util/transit.cljs | 35 ++- frontend/src/uxbox/worker/selection.cljs | 2 +- frontend/tests/uxbox/test_util_geom.cljs | 4 +- .../tests/uxbox/test_util_range_tree.cljs | 2 +- 60 files changed, 172 insertions(+), 761 deletions(-) rename frontend/src/uxbox/util/geom/matrix.cljs => common/uxbox/common/geom/matrix.cljc (87%) rename frontend/src/uxbox/util/geom/point.cljs => common/uxbox/common/geom/point.cljc (92%) rename frontend/src/uxbox/util/geom/shapes.cljs => common/uxbox/common/geom/shapes.cljc (99%) rename frontend/src/uxbox/util/math.cljs => common/uxbox/common/math.cljc (60%) delete mode 100644 frontend/src/uxbox/main/data/workspace/ruler.cljs delete mode 100644 frontend/src/uxbox/util/geom/_matrix.js delete mode 100644 frontend/src/uxbox/util/geom/_point.js delete mode 100644 frontend/src/uxbox/util/geom/range_tree.cljs diff --git a/common/uxbox/common/data.cljc b/common/uxbox/common/data.cljc index af39f80f2..dd39982ca 100644 --- a/common/uxbox/common/data.cljc +++ b/common/uxbox/common/data.cljc @@ -102,6 +102,9 @@ (subvec v 0 index) (subvec v (inc index))))) +(defn zip [col1 col2] + (map vector col1 col2)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data Parsing / Conversion ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/uxbox/util/geom/matrix.cljs b/common/uxbox/common/geom/matrix.cljc similarity index 87% rename from frontend/src/uxbox/util/geom/matrix.cljs rename to common/uxbox/common/geom/matrix.cljc index d8b97010e..db5b65db1 100644 --- a/frontend/src/uxbox/util/geom/matrix.cljs +++ b/common/uxbox/common/geom/matrix.cljc @@ -5,13 +5,13 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2015-2020 Andrey Antukh <niwi@niwi.nz> +;; Copyright (c) 2020 UXBOX Labs SL -(ns uxbox.util.geom.matrix - (:require [cuerdas.core :as str] - [cognitect.transit :as t] - [uxbox.util.math :as mth] - [uxbox.util.geom.point :as gpt])) +(ns uxbox.common.geom.matrix + (:require + [cuerdas.core :as str] + [uxbox.common.math :as mth] + [uxbox.common.geom.point :as gpt])) ;; --- Matrix Impl @@ -121,14 +121,3 @@ ([m angle-x angle-y p] (multiply m (skew-matrix angle-x angle-y p)))) -;; --- Transit Adapter - -(def matrix-write-handler - (t/write-handler - (constantly "matrix") - (fn [v] (into {} v)))) - -(def matrix-read-handler - (t/read-handler - (fn [value] - (map->Matrix value)))) diff --git a/frontend/src/uxbox/util/geom/point.cljs b/common/uxbox/common/geom/point.cljc similarity index 92% rename from frontend/src/uxbox/util/geom/point.cljs rename to common/uxbox/common/geom/point.cljc index 5433334b2..551bf3b45 100644 --- a/frontend/src/uxbox/util/geom/point.cljs +++ b/common/uxbox/common/geom/point.cljc @@ -5,15 +5,15 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2015-2020 Andrey Antukh <niwi@niwi.nz> +;; Copyright (c) 2020 UXBOX Labs SL -(ns uxbox.util.geom.point +(ns uxbox.common.geom.point (:refer-clojure :exclude [divide min max]) (:require - [cljs.core :as c] + #?(:cljs [cljs.core :as c] + :clj [clj.core :as c]) [cuerdas.core :as str] - [uxbox.util.math :as mth] - [cognitect.transit :as t])) + [uxbox.common.math :as mth])) ;; --- Point Impl @@ -165,19 +165,6 @@ (Point. (+ (* x a) (* y c) e) (+ (* x b) (* y d) f))) -;; --- Transit Adapter - -(def point-write-handler - (t/write-handler - (constantly "point") - (fn [v] (into {} v)))) - -(def point-read-handler - (t/read-handler - (fn [value] - (map->Point value)))) - - ;; Vector functions (defn to-vec [p1 p2] (subtract p2 p1)) @@ -195,4 +182,3 @@ (multiply v2-unit (point scalar-projection scalar-projection)))) - diff --git a/frontend/src/uxbox/util/geom/shapes.cljs b/common/uxbox/common/geom/shapes.cljc similarity index 99% rename from frontend/src/uxbox/util/geom/shapes.cljs rename to common/uxbox/common/geom/shapes.cljc index d130fe8cd..26404d904 100644 --- a/frontend/src/uxbox/util/geom/shapes.cljs +++ b/common/uxbox/common/geom/shapes.cljc @@ -7,16 +7,15 @@ ;; ;; Copyright (c) 2020 UXBOX Labs SL -(ns uxbox.util.geom.shapes +(ns uxbox.common.geom.shapes (:require [clojure.spec.alpha :as s] [uxbox.common.pages :as cp] [uxbox.common.spec :as us] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.math :as mth] - [uxbox.util.data :as d] - [uxbox.util.debug :as debug])) + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.math :as mth] + [uxbox.common.data :as d])) ;; --- Relative Movement diff --git a/frontend/src/uxbox/util/math.cljs b/common/uxbox/common/math.cljc similarity index 60% rename from frontend/src/uxbox/util/math.cljs rename to common/uxbox/common/math.cljc index 57df24608..ef037ca84 100644 --- a/frontend/src/uxbox/util/math.cljs +++ b/common/uxbox/common/math.cljc @@ -7,46 +7,55 @@ ;; ;; Copyright (c) 2020 UXBOX Labs SL -(ns uxbox.util.math +(ns uxbox.common.math "A collection of math utils." - (:require [goog.math :as math])) + #?(:cljs + (:require [goog.math :as math]))) (defn ^boolean nan? [v] - (js/isNaN v)) + #?(:cljs (js/isNaN v) + :clj (Double/isNaN v))) (defn ^boolean finite? [v] - (js/isFinite v)) + #?(:cljs (js/isFinite v) + :clj (Double/isFinite v))) (defn abs [^number v] - (js/Math.abs v)) + #?(:cljs (js/Math.abs v) + :clj (Math/abs v))) (defn sin "Returns the sine of a number" [^number v] - (js/Math.sin v)) + #?(:cljs (js/Math.sin v) + :clj (Math/sin))) (defn cos "Returns the cosine of a number." [^number v] - (js/Math.cos v)) + #?(:cljs (js/Math.cos v) + :clj (Math/cos v))) (defn acos "Returns the arccosine of a number." [^number v] - (js/Math.acos v)) + #?(:cljs (js/Math.acos v) + :clj (Math/acos v))) (defn tan "Returns the tangent of a number." [^number v] - (js/Math.tan v)) + #?(:cljs (js/Math.tan v) + :clj (Math/tan v))) (defn atan2 "Returns the arctangent of the quotient of its arguments." [^number x ^number y] - (js/Math.atan2 x y)) + #?(:cljs (js/Math.atan2 x y) + :clj (Math/atan2 x y))) (defn neg "Negate the number" @@ -56,51 +65,53 @@ (defn sqrt "Returns the square root of a number." [v] - (js/Math.sqrt v)) + #?(:cljs (js/Math.sqrt v) + :clj (Math/sqrt v))) (defn pow "Returns the base to the exponent power." [b e] - (js/Math.pow b e)) + #?(:cljs (js/Math.pow b e) + :clj (Math/pow b e))) (defn floor "Returns the largest integer less than or equal to a given number." [^number v] - (js/Math.floor v)) + #?(:cljs (js/Math.floor v) + :clj (Math/floor))) (defn round "Returns the value of a number rounded to the nearest integer." [^number v] - (js/Math.round v)) + #?(:cljs (js/Math.round v) + :clj (Math/round v))) (defn ceil "Returns the smallest integer greater than or equal to a given number." [^number v] - (js/Math.ceil v)) + #?(:cljs (js/Math.ceil v) + :clj (Math/ceil v))) (defn precision [^number v ^number n] (when (and (number? v) (number? n)) - (js/parseFloat (.toFixed v n)))) - -(defn precision-or-0 - [^number v ^number n] - (if (.-toFixed v) - (js/parseFloat (.toFixed v n)) - 0)) + #?(:cljs (js/parseFloat (.toFixed v n)) + :clj (.. (BigDecimal/valueOf v) (setScale n java.math.RoundingMode/HALF_UP) (doubleValue))))) (defn radians "Converts degrees to radians." [^number degrees] - (math/toRadians degrees)) + #?(:cljs (math/toRadians degrees) + :clj (Math/toRadians degrees))) (defn degrees "Converts radians to degrees." - [^number radiants] - (math/toDegrees radiants)) + [^number radians] + #?(:cljs (math/toDegrees radians) + :clj (Math/toDegrees radians))) (defn distance "Calculate the distance between two points." diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index ea9c2cc74..17fdad5d8 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -29,10 +29,10 @@ [uxbox.main.store :as st] [uxbox.main.streams :as ms] [uxbox.main.worker :as uw] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as geom] - [uxbox.util.math :as mth] + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.math :as mth] [uxbox.util.router :as rt] [uxbox.util.transit :as t] [uxbox.util.webapi :as wapi])) diff --git a/frontend/src/uxbox/main/data/workspace/common.cljs b/frontend/src/uxbox/main/data/workspace/common.cljs index bfcb67f9a..fdbba4760 100644 --- a/frontend/src/uxbox/main/data/workspace/common.cljs +++ b/frontend/src/uxbox/main/data/workspace/common.cljs @@ -19,7 +19,7 @@ [uxbox.common.uuid :as uuid] [uxbox.main.worker :as uw] [uxbox.util.timers :as ts] - [uxbox.util.geom.shapes :as geom])) + [uxbox.common.geom.shapes :as geom])) ;; --- Protocols diff --git a/frontend/src/uxbox/main/data/workspace/notifications.cljs b/frontend/src/uxbox/main/data/workspace/notifications.cljs index 2da564e32..a254a34f9 100644 --- a/frontend/src/uxbox/main/data/workspace/notifications.cljs +++ b/frontend/src/uxbox/main/data/workspace/notifications.cljs @@ -21,7 +21,7 @@ [uxbox.main.data.workspace.common :as dwc] [uxbox.main.data.workspace.persistence :as dwp] [uxbox.util.avatars :as avatars] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.point :as gpt] [uxbox.util.time :as dt] [uxbox.util.transit :as t] [uxbox.util.websockets :as ws])) diff --git a/frontend/src/uxbox/main/data/workspace/persistence.cljs b/frontend/src/uxbox/main/data/workspace/persistence.cljs index 29afd2700..9a54ccd3d 100644 --- a/frontend/src/uxbox/main/data/workspace/persistence.cljs +++ b/frontend/src/uxbox/main/data/workspace/persistence.cljs @@ -19,7 +19,7 @@ [uxbox.main.data.workspace.common :as dwc] [uxbox.main.repo :as rp] [uxbox.main.store :as st] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.point :as gpt] [uxbox.util.router :as rt] [uxbox.util.time :as dt] [uxbox.util.transit :as t])) diff --git a/frontend/src/uxbox/main/data/workspace/ruler.cljs b/frontend/src/uxbox/main/data/workspace/ruler.cljs deleted file mode 100644 index be34e81fa..000000000 --- a/frontend/src/uxbox/main/data/workspace/ruler.cljs +++ /dev/null @@ -1,95 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz> - -(ns uxbox.main.data.workspace.ruler - "Workspace ruler related events. Mostly or all events - are related to UI logic." - #_(:require [beicon.core :as rx] - [potok.core :as ptk] - [uxbox.main.refs :as refs] - [uxbox.main.streams :as streams] - [uxbox.main.user-events :as uev] - [uxbox.util.dom :as dom] - [uxbox.util.geom.point :as gpt])) - -;; --- Constants - -;; (declare stop-ruler?) -;; (declare clear-ruler) -;; (declare update-ruler) - -;; (def ^:private immanted-zones -;; (let [transform #(vector (- % 7) (+ % 7) %) -;; right (map transform (range 0 181 15)) -;; left (map (comp transform -) (range 0 181 15))] -;; (vec (concat right left)))) - -;; (defn- align-position -;; [pos] -;; (let [angle (gpt/angle pos)] -;; (reduce (fn [pos [a1 a2 v]] -;; (if (< a1 angle a2) -;; (reduced (gpt/update-angle pos v)) -;; pos)) -;; pos -;; immanted-zones))) - -;; ;; --- Start Ruler - -;; (deftype StartRuler [] -;; ptk/UpdateEvent -;; (update [_ state] -;; (let [pid (get-in state [:workspace :current]) -;; pos (get-in state [:workspace :pointer :viewport])] -;; (assoc-in state [:workspace pid :ruler] {:start pos :end pos}))) - -;; ptk/WatchEvent -;; (watch [_ state stream] -;; (let [stoper (->> (rx/filter #(= ::uev/interrupt %) stream) -;; (rx/take 1))] -;; (->> streams/mouse-position -;; (rx/take-until stoper) -;; (rx/map (juxt :viewport :ctrl)) -;; (rx/map (fn [[pt ctrl?]] -;; (update-ruler pt ctrl?))))))) - -;; (defn start-ruler -;; [] -;; (StartRuler.)) - -;; ;; --- Update Ruler - -;; (deftype UpdateRuler [point ctrl?] -;; ptk/UpdateEvent -;; (update [_ state] -;; (let [pid (get-in state [:workspace :current]) -;; ruler (get-in state [:workspace pid :ruler])] -;; (if-not ctrl? -;; (assoc-in state [:workspace pid :ruler :end] point) -;; (let [start (get-in state [:workspace pid :ruler :start]) -;; end (-> (gpt/subtract point start) -;; (align-position) -;; (gpt/add start))] -;; (assoc-in state [:workspace pid :ruler :end] end)))))) - -;; (defn update-ruler -;; [point ctrl?] -;; {:pre [(gpt/point? point) -;; (boolean? ctrl?)]} -;; (UpdateRuler. point ctrl?)) - -;; ;; --- Clear Ruler - -;; (deftype ClearRuler [] -;; ptk/UpdateEvent -;; (update [_ state] -;; (let [pid (get-in state [:workspace :current])] -;; (update-in state [:workspace pid] dissoc :ruler)))) - -;; (defn clear-ruler -;; [] -;; (ClearRuler.)) - diff --git a/frontend/src/uxbox/main/data/workspace/transforms.cljs b/frontend/src/uxbox/main/data/workspace/transforms.cljs index 3392c35d7..81f506b64 100644 --- a/frontend/src/uxbox/main/data/workspace/transforms.cljs +++ b/frontend/src/uxbox/main/data/workspace/transforms.cljs @@ -21,9 +21,9 @@ [uxbox.main.refs :as refs] [uxbox.main.store :as st] [uxbox.main.streams :as ms] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as gsh] + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.shapes :as gsh] [uxbox.main.snap :as snap])) ;; -- Declarations diff --git a/frontend/src/uxbox/main/exports.cljs b/frontend/src/uxbox/main/exports.cljs index 806c0dbbe..67e3036c4 100644 --- a/frontend/src/uxbox/main/exports.cljs +++ b/frontend/src/uxbox/main/exports.cljs @@ -13,10 +13,10 @@ [rumext.alpha :as mf] [uxbox.common.uuid :as uuid] [uxbox.common.pages :as cp] - [uxbox.util.math :as mth] - [uxbox.util.geom.shapes :as geom] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.matrix :as gmt] + [uxbox.common.math :as mth] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.matrix :as gmt] [uxbox.main.ui.shapes.frame :as frame] [uxbox.main.ui.shapes.circle :as circle] [uxbox.main.ui.shapes.icon :as icon] diff --git a/frontend/src/uxbox/main/snap.cljs b/frontend/src/uxbox/main/snap.cljs index 8e5c2c85c..45b25ed14 100644 --- a/frontend/src/uxbox/main/snap.cljs +++ b/frontend/src/uxbox/main/snap.cljs @@ -11,8 +11,8 @@ (:require [beicon.core :as rx] [uxbox.common.uuid :refer [zero]] - [uxbox.util.math :as mth] - [uxbox.util.geom.point :as gpt] + [uxbox.common.math :as mth] + [uxbox.common.geom.point :as gpt] [uxbox.main.worker :as uw] [uxbox.util.geom.snap-points :as sp])) diff --git a/frontend/src/uxbox/main/streams.cljs b/frontend/src/uxbox/main/streams.cljs index 31ce917d8..be9f95697 100644 --- a/frontend/src/uxbox/main/streams.cljs +++ b/frontend/src/uxbox/main/streams.cljs @@ -10,7 +10,7 @@ [beicon.core :as rx] [uxbox.main.store :as st] [uxbox.main.refs :as refs] - [uxbox.util.geom.point :as gpt])) + [uxbox.common.geom.point :as gpt])) ;; --- User Events diff --git a/frontend/src/uxbox/main/ui/shapes/circle.cljs b/frontend/src/uxbox/main/ui/shapes/circle.cljs index b9144498e..fea695664 100644 --- a/frontend/src/uxbox/main/ui/shapes/circle.cljs +++ b/frontend/src/uxbox/main/ui/shapes/circle.cljs @@ -12,7 +12,7 @@ [rumext.alpha :as mf] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.main.ui.shapes.custom-stroke :refer [shape-custom-stroke]] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.object :as obj])) (mf/defc circle-shape diff --git a/frontend/src/uxbox/main/ui/shapes/custom_stroke.cljs b/frontend/src/uxbox/main/ui/shapes/custom_stroke.cljs index befa887ac..8062d9f9f 100644 --- a/frontend/src/uxbox/main/ui/shapes/custom_stroke.cljs +++ b/frontend/src/uxbox/main/ui/shapes/custom_stroke.cljs @@ -7,7 +7,7 @@ (ns uxbox.main.ui.shapes.custom-stroke (:require [rumext.alpha :as mf] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.object :as obj])) ; The SVG standard does not implement yet the 'stroke-alignment' diff --git a/frontend/src/uxbox/main/ui/shapes/frame.cljs b/frontend/src/uxbox/main/ui/shapes/frame.cljs index 2ec407dd1..8a5e62b8c 100644 --- a/frontend/src/uxbox/main/ui/shapes/frame.cljs +++ b/frontend/src/uxbox/main/ui/shapes/frame.cljs @@ -12,7 +12,7 @@ [rumext.alpha :as mf] [uxbox.common.data :as d] [uxbox.main.ui.shapes.attrs :as attrs] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.object :as obj])) (def frame-default-props {:fill-color "#ffffff"}) diff --git a/frontend/src/uxbox/main/ui/shapes/group.cljs b/frontend/src/uxbox/main/ui/shapes/group.cljs index 999efca25..5a2da89f5 100644 --- a/frontend/src/uxbox/main/ui/shapes/group.cljs +++ b/frontend/src/uxbox/main/ui/shapes/group.cljs @@ -12,7 +12,7 @@ [rumext.alpha :as mf] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.util.debug :refer [debug?]] - [uxbox.util.geom.shapes :as geom])) + [uxbox.common.geom.shapes :as geom])) (defn group-shape [shape-wrapper] diff --git a/frontend/src/uxbox/main/ui/shapes/icon.cljs b/frontend/src/uxbox/main/ui/shapes/icon.cljs index a2fb31b0b..9d5835168 100644 --- a/frontend/src/uxbox/main/ui/shapes/icon.cljs +++ b/frontend/src/uxbox/main/ui/shapes/icon.cljs @@ -10,7 +10,7 @@ (ns uxbox.main.ui.shapes.icon (:require [rumext.alpha :as mf] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.util.object :as obj])) diff --git a/frontend/src/uxbox/main/ui/shapes/image.cljs b/frontend/src/uxbox/main/ui/shapes/image.cljs index de39928ec..45102ed44 100644 --- a/frontend/src/uxbox/main/ui/shapes/image.cljs +++ b/frontend/src/uxbox/main/ui/shapes/image.cljs @@ -10,7 +10,7 @@ (ns uxbox.main.ui.shapes.image (:require [rumext.alpha :as mf] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.util.object :as obj])) diff --git a/frontend/src/uxbox/main/ui/shapes/path.cljs b/frontend/src/uxbox/main/ui/shapes/path.cljs index 889866b60..0145c98c0 100644 --- a/frontend/src/uxbox/main/ui/shapes/path.cljs +++ b/frontend/src/uxbox/main/ui/shapes/path.cljs @@ -13,7 +13,7 @@ [rumext.alpha :as mf] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.main.ui.shapes.custom-stroke :refer [shape-custom-stroke]] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.object :as obj])) ;; --- Path Shape diff --git a/frontend/src/uxbox/main/ui/shapes/rect.cljs b/frontend/src/uxbox/main/ui/shapes/rect.cljs index 0d5b71c9d..bd68d0636 100644 --- a/frontend/src/uxbox/main/ui/shapes/rect.cljs +++ b/frontend/src/uxbox/main/ui/shapes/rect.cljs @@ -12,7 +12,7 @@ [rumext.alpha :as mf] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.main.ui.shapes.custom-stroke :refer [shape-custom-stroke]] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.object :as obj])) (mf/defc rect-shape diff --git a/frontend/src/uxbox/main/ui/shapes/text.cljs b/frontend/src/uxbox/main/ui/shapes/text.cljs index 9d4652cb9..8996eb6f3 100644 --- a/frontend/src/uxbox/main/ui/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/shapes/text.cljs @@ -8,10 +8,10 @@ (:require [rumext.alpha :as mf] [uxbox.common.data :as d] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.geom.matrix :as gmt] [uxbox.main.fonts :as fonts] - [uxbox.util.geom.shapes :as geom] - [uxbox.util.object :as obj] - [uxbox.util.geom.matrix :as gmt])) + [uxbox.util.object :as obj])) ;; --- Text Editor Rendering diff --git a/frontend/src/uxbox/main/ui/viewer/header.cljs b/frontend/src/uxbox/main/ui/viewer/header.cljs index d957ddbd7..c7a5bfe29 100644 --- a/frontend/src/uxbox/main/ui/viewer/header.cljs +++ b/frontend/src/uxbox/main/ui/viewer/header.cljs @@ -20,7 +20,7 @@ [uxbox.util.dom :as dom] [uxbox.util.i18n :as i18n :refer [t]] [uxbox.util.router :as rt] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.common.uuid :as uuid] [uxbox.util.webapi :as wapi])) diff --git a/frontend/src/uxbox/main/ui/viewer/shapes.cljs b/frontend/src/uxbox/main/ui/viewer/shapes.cljs index 1c29ffc2f..91db8caf8 100644 --- a/frontend/src/uxbox/main/ui/viewer/shapes.cljs +++ b/frontend/src/uxbox/main/ui/viewer/shapes.cljs @@ -24,9 +24,9 @@ [uxbox.main.ui.shapes.rect :as rect] [uxbox.main.ui.shapes.text :as text] [uxbox.util.object :as obj] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as geom])) + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.shapes :as geom])) (defn on-mouse-down [event {:keys [interactions] :as shape}] diff --git a/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs b/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs index 13eabfea2..d4d6f0e7c 100644 --- a/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs +++ b/frontend/src/uxbox/main/ui/viewer/thumbnails.cljs @@ -22,10 +22,10 @@ [uxbox.main.exports :as exports] [uxbox.util.data :refer [classnames]] [uxbox.util.dom :as dom] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] [uxbox.util.i18n :as i18n :refer [t tr]] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.util.router :as rt] [uxbox.main.data.viewer :as vd]) (:import goog.events.EventType diff --git a/frontend/src/uxbox/main/ui/workspace.cljs b/frontend/src/uxbox/main/ui/workspace.cljs index f33c86e76..5ca04a913 100644 --- a/frontend/src/uxbox/main/ui/workspace.cljs +++ b/frontend/src/uxbox/main/ui/workspace.cljs @@ -34,7 +34,7 @@ [uxbox.main.ui.workspace.left-toolbar :refer [left-toolbar]] [uxbox.util.data :refer [classnames]] [uxbox.util.dom :as dom] - [uxbox.util.geom.point :as gpt])) + [uxbox.common.geom.point :as gpt])) ;; --- Workspace diff --git a/frontend/src/uxbox/main/ui/workspace/drawarea.cljs b/frontend/src/uxbox/main/ui/workspace/drawarea.cljs index 2f9ec8cd3..4bc3d5c40 100644 --- a/frontend/src/uxbox/main/ui/workspace/drawarea.cljs +++ b/frontend/src/uxbox/main/ui/workspace/drawarea.cljs @@ -12,17 +12,17 @@ [rumext.alpha :as mf] [uxbox.main.constants :as c] [uxbox.main.data.workspace :as dw] - [uxbox.util.geom.shapes :as geom] [uxbox.main.refs :as refs] [uxbox.main.store :as st] [uxbox.main.streams :as ms] [uxbox.main.ui.workspace.shapes :as shapes] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.util.dom :as dom] [uxbox.util.data :refer [seek]] - [uxbox.util.geom.matrix :as gmt] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] [uxbox.util.geom.path :as path] - [uxbox.util.geom.point :as gpt] [uxbox.util.i18n :as i18n :refer [t]] [uxbox.main.snap :as snap] [uxbox.common.uuid :as uuid])) diff --git a/frontend/src/uxbox/main/ui/workspace/frame_grid.cljs b/frontend/src/uxbox/main/ui/workspace/frame_grid.cljs index b8905b222..6f773a100 100644 --- a/frontend/src/uxbox/main/ui/workspace/frame_grid.cljs +++ b/frontend/src/uxbox/main/ui/workspace/frame_grid.cljs @@ -12,7 +12,7 @@ [rumext.alpha :as mf] [uxbox.main.refs :as refs] [uxbox.common.pages :as cp] - [uxbox.util.geom.shapes :as gsh] + [uxbox.common.geom.shapes :as gsh] [uxbox.util.geom.grid :as gg])) (mf/defc square-grid [{:keys [frame zoom grid] :as props}] diff --git a/frontend/src/uxbox/main/ui/workspace/header.cljs b/frontend/src/uxbox/main/ui/workspace/header.cljs index 2ad160e17..c2fad9b51 100644 --- a/frontend/src/uxbox/main/ui/workspace/header.cljs +++ b/frontend/src/uxbox/main/ui/workspace/header.cljs @@ -23,7 +23,7 @@ [uxbox.main.ui.workspace.presence :as presence] [uxbox.util.i18n :as i18n :refer [t]] [uxbox.util.data :refer [classnames]] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.util.router :as rt])) ;; --- Zoom Widget diff --git a/frontend/src/uxbox/main/ui/workspace/rules.cljs b/frontend/src/uxbox/main/ui/workspace/rules.cljs index 850e26f7a..9d2a7f63b 100644 --- a/frontend/src/uxbox/main/ui/workspace/rules.cljs +++ b/frontend/src/uxbox/main/ui/workspace/rules.cljs @@ -10,7 +10,7 @@ (ns uxbox.main.ui.workspace.rules (:require [rumext.alpha :as mf] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.util.object :as obj])) (defn- calculate-step-size diff --git a/frontend/src/uxbox/main/ui/workspace/scroll.cljs b/frontend/src/uxbox/main/ui/workspace/scroll.cljs index b4df040c0..57d128956 100644 --- a/frontend/src/uxbox/main/ui/workspace/scroll.cljs +++ b/frontend/src/uxbox/main/ui/workspace/scroll.cljs @@ -11,7 +11,7 @@ [potok.core :as ptk] [uxbox.main.refs :as refs] [uxbox.util.dom :as dom] - [uxbox.util.geom.point :as gpt])) + [uxbox.common.geom.point :as gpt])) ;; FIXME: revisit this ns in order to find a better location for its functions ;; TODO: this need a good refactor (probably move to events with access to the state) diff --git a/frontend/src/uxbox/main/ui/workspace/selection.cljs b/frontend/src/uxbox/main/ui/workspace/selection.cljs index ee16fc11c..0f26b1362 100644 --- a/frontend/src/uxbox/main/ui/workspace/selection.cljs +++ b/frontend/src/uxbox/main/ui/workspace/selection.cljs @@ -15,14 +15,14 @@ [rumext.alpha :as mf] [rumext.util :refer [map->obj]] [uxbox.main.data.workspace :as dw] - [uxbox.util.geom.shapes :as geom] [uxbox.main.refs :as refs] [uxbox.main.store :as st] [uxbox.main.streams :as ms] [uxbox.util.dom :as dom] [uxbox.util.object :as obj] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.matrix :as gmt] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.matrix :as gmt] [uxbox.util.debug :refer [debug?]])) (defn rotation-cursor [angle] @@ -161,7 +161,7 @@ (mf/defc resize-side-handler [{:keys [x y length angle zoom position transform on-resize]}] [:rect {:x (+ x (/ resize-point-rect-size zoom)) :y (- y (/ resize-side-height 2 zoom)) - :width (- length (/ (* resize-point-rect-size 2) zoom)) + :width (max 0 (- length (/ (* resize-point-rect-size 2) zoom))) :height (/ resize-side-height zoom) :transform (gmt/multiply transform (gmt/rotate-matrix angle (gpt/point x y))) diff --git a/frontend/src/uxbox/main/ui/workspace/shapes.cljs b/frontend/src/uxbox/main/ui/workspace/shapes.cljs index 37e50afe4..0d81d6f7e 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes.cljs @@ -26,7 +26,7 @@ [uxbox.main.ui.workspace.shapes.group :as group] [uxbox.main.ui.workspace.shapes.path :as path] [uxbox.main.ui.workspace.shapes.text :as text] - [uxbox.util.geom.shapes :as geom])) + [uxbox.common.geom.shapes :as geom])) (declare group-wrapper) (declare frame-wrapper) diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/bbox.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/bbox.cljs index ad707e253..6ddb5fa94 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/bbox.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/bbox.cljs @@ -9,9 +9,9 @@ [cuerdas.core :as str] [rumext.alpha :as mf] [uxbox.util.debug :as debug] - [uxbox.util.geom.shapes :as geom] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.shapes :as geom] + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] [uxbox.util.debug :refer [debug?]] ["randomcolor" :as rdcolor])) diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs index 51b6adfa0..1385967e1 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs @@ -15,9 +15,9 @@ [uxbox.main.store :as st] [uxbox.main.ui.keyboard :as kbd] [uxbox.util.dom :as dom] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as geom])) + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.shapes :as geom])) (defn- on-mouse-down [event {:keys [id type] :as shape}] diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/frame.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/frame.cljs index e39abfe6c..ec469e8cd 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/frame.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/frame.cljs @@ -17,9 +17,9 @@ [uxbox.main.store :as st] [uxbox.main.ui.workspace.shapes.common :as common] [uxbox.main.ui.shapes.frame :as frame] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.shapes :as geom] [uxbox.util.dom :as dom] [uxbox.main.streams :as ms] [uxbox.util.timers :as ts])) diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/interactions.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/interactions.cljs index 2bc191e1d..279cb27b4 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/interactions.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/interactions.cljs @@ -14,13 +14,12 @@ [cuerdas.core :as str] [uxbox.util.data :as dt] [uxbox.util.dom :as dom] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.shapes :as geom] [uxbox.main.store :as st] [uxbox.main.refs :as refs] [uxbox.main.data.workspace :as dw] - [uxbox.main.ui.keyboard :as kbd] - )) + [uxbox.main.ui.keyboard :as kbd])) (defn- get-click-interaction [shape] diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/path.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/path.cljs index 878b2534d..3af9c84fe 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/path.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/path.cljs @@ -19,9 +19,6 @@ [uxbox.main.ui.shapes.path :as path] [uxbox.main.ui.workspace.shapes.common :as common] [uxbox.util.dom :as dom] - [uxbox.util.geom.matrix :as gmt] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.shapes :as geom] [uxbox.util.interop :as itr] [uxbox.main.streams :as ms] [uxbox.util.timers :as ts])) diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs index 3a41a73cf..492667af8 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs @@ -22,9 +22,8 @@ [uxbox.main.fonts :as fonts] [uxbox.util.color :as color] [uxbox.util.dom :as dom] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.object :as obj] - [uxbox.util.geom.matrix :as gmt] ["slate" :as slate] ["slate-react" :as rslate]) (:import diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame.cljs index 1c49bb35f..3306c0ea7 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame.cljs @@ -13,9 +13,9 @@ [rumext.alpha :as mf] [uxbox.common.data :as d] [uxbox.util.dom :as dom] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.point :as gpt] [uxbox.util.i18n :refer [tr]] - [uxbox.util.math :as math] + [uxbox.common.math :as math] [uxbox.main.store :as st] [uxbox.main.data.workspace :as udw] [uxbox.main.ui.icons :as i] diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame_grid.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame_grid.cljs index 862a6279b..280a889c8 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame_grid.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/frame_grid.cljs @@ -12,7 +12,7 @@ [rumext.alpha :as mf] [uxbox.util.dom :as dom] [uxbox.util.data :as d] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.common.data :refer [parse-integer]] [uxbox.main.store :as st] [uxbox.main.refs :as refs] diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs index 159d0b35c..66b649f77 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs @@ -15,10 +15,10 @@ [uxbox.main.refs :as refs] [uxbox.common.data :as d] [uxbox.util.dom :as dom] - [uxbox.util.geom.shapes :as gsh] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.shapes :as gsh] + [uxbox.common.geom.point :as gpt] [uxbox.main.data.workspace :as udw] - [uxbox.util.math :as math] + [uxbox.common.math :as math] [uxbox.util.i18n :refer [t] :as i18n])) ;; -- User/drawing coords diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/rows/color_row.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/rows/color_row.cljs index fd3e69bf5..6bf7aee51 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/rows/color_row.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/rows/color_row.cljs @@ -10,7 +10,7 @@ (ns uxbox.main.ui.workspace.sidebar.options.rows.color-row (:require [rumext.alpha :as mf] - [uxbox.util.math :as math] + [uxbox.common.math :as math] [uxbox.util.dom :as dom] [uxbox.main.ui.modal :as modal] [uxbox.main.ui.workspace.colorpicker :refer [colorpicker-modal]] diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/stroke.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/stroke.cljs index 63c1839a8..dc3e40146 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/stroke.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/stroke.cljs @@ -19,7 +19,7 @@ [uxbox.util.dom :as dom] [uxbox.util.object :as obj] [uxbox.util.i18n :as i18n :refer [tr t]] - [uxbox.util.math :as math] + [uxbox.common.math :as math] [uxbox.main.ui.workspace.sidebar.options.rows.color-row :refer [color-row]])) (defn- stroke-menu-memo-equals? diff --git a/frontend/src/uxbox/main/ui/workspace/snap_feedback.cljs b/frontend/src/uxbox/main/ui/workspace/snap_feedback.cljs index 150278aad..5beea4daf 100644 --- a/frontend/src/uxbox/main/ui/workspace/snap_feedback.cljs +++ b/frontend/src/uxbox/main/ui/workspace/snap_feedback.cljs @@ -5,7 +5,7 @@ [uxbox.main.refs :as refs] [uxbox.main.snap :as snap] [uxbox.util.geom.snap-points :as sp] - [uxbox.util.geom.point :as gpt])) + [uxbox.common.geom.point :as gpt])) (def ^:private line-color "#D383DA") diff --git a/frontend/src/uxbox/main/ui/workspace/viewport.cljs b/frontend/src/uxbox/main/ui/workspace/viewport.cljs index 8cd0e0662..99606351f 100644 --- a/frontend/src/uxbox/main/ui/workspace/viewport.cljs +++ b/frontend/src/uxbox/main/ui/workspace/viewport.cljs @@ -30,10 +30,10 @@ [uxbox.main.ui.workspace.presence :as presence] [uxbox.main.ui.workspace.snap-feedback :refer [snap-feedback]] [uxbox.main.ui.workspace.frame-grid :refer [frame-grid]] - [uxbox.util.math :as mth] + [uxbox.common.math :as mth] [uxbox.util.dom :as dom] [uxbox.util.object :as obj] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.point :as gpt] [uxbox.util.perf :as perf] [uxbox.common.uuid :as uuid]) (:import goog.events.EventType)) diff --git a/frontend/src/uxbox/util/color.cljs b/frontend/src/uxbox/util/color.cljs index 40b5f6725..7fa58773b 100644 --- a/frontend/src/uxbox/util/color.cljs +++ b/frontend/src/uxbox/util/color.cljs @@ -11,7 +11,7 @@ "Color conversion utils." (:require [cuerdas.core :as str] - [uxbox.util.math :as math] + [uxbox.common.math :as math] [goog.color :as gcolor])) (defn rgb->str diff --git a/frontend/src/uxbox/util/data.cljs b/frontend/src/uxbox/util/data.cljs index d252743f8..61145306d 100644 --- a/frontend/src/uxbox/util/data.cljs +++ b/frontend/src/uxbox/util/data.cljs @@ -111,9 +111,6 @@ not-found)) not-found coll))) -(defn zip [col1 col2] - (map vector col1 col2)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Numbers Parsing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/uxbox/util/dom.cljs b/frontend/src/uxbox/util/dom.cljs index 1f65132c9..64c85d787 100644 --- a/frontend/src/uxbox/util/dom.cljs +++ b/frontend/src/uxbox/util/dom.cljs @@ -13,7 +13,7 @@ [cuerdas.core :as str] [beicon.core :as rx] [cuerdas.core :as str] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.point :as gpt] [uxbox.util.blob :as blob] [uxbox.util.transit :as ts])) diff --git a/frontend/src/uxbox/util/geom/_matrix.js b/frontend/src/uxbox/util/geom/_matrix.js deleted file mode 100644 index 48b0282e1..000000000 --- a/frontend/src/uxbox/util/geom/_matrix.js +++ /dev/null @@ -1,229 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This Source Code Form is "Incompatible With Secondary Licenses", as - * defined by the Mozilla Public License, v. 2.0. - * - * Copyright (c) 2020 Andrey Antukh <niwi@niwi.nz> -*/ - -// NOTE: this code is unused, but is preserved for the case when we -// note that the cljs impl has not not enough performance. - -goog.provide("uxbox.util.geom.matrix_impl"); -goog.provide("uxbox.util.geom.matrix_impl.Matrix"); -goog.require("goog.math"); -goog.require("uxbox.util.geom.point_impl"); - -goog.scope(function() { - const self = uxbox.util.geom.matrix_impl; - const gpt = uxbox.util.geom.point_impl; - const math = goog.math; - - /** - * @param {number} a - * @param {number} b - * @param {number} c - * @param {number} d - * @param {number} e - * @param {number} f - * @struct - */ - class Matrix { - constructor(a, b, c, d, e, f) { - this.a = a; - this.b = b; - this.c = c; - this.d = d; - this.e = e; - this.f = f; - } - - [Symbol.iterator]() { - return [["a", this.a] - ["b", this.b]]; - } - - toString() { - return `matrix(${this.a},${this.b},${this.c},${this.d},${this.e},${this.f})`; - } - - copy() { - return new Matrix( - this.a, - this.b, - this.c, - this.d, - this.e, - this.f - ); - } - } - - self.Matrix = Matrix; - - /** - * @param {number?} a - * @param {number?} b - * @param {number?} c - * @param {number?} d - * @param {number?} e - * @param {number?} f - * @return {Matrix} - */ - self.matrix = function(a, b, c, d, e, f) { - if (a === undefined) { - return new Matrix(1,0,0,1,0,0); - } else { - return new Matrix(a,b,c,d,e,f); - } - }; - - /** - * @param {?} m - * @return {boolean} - */ - function isMatrix(m) { - return m instanceof Matrix; - } - - self.isMatrix = isMatrix - - - /** - * @param {Matrix} m1 - * @param {Matrix} m2 - * @return {Matrix} - */ - self.multiplyUnsafe = function(m1, m2) { - const a = m1.a * m2.a + m1.c * m2.b; - const b = m1.b * m2.a + m1.d * m2.b; - const c = m1.a * m2.c + m1.c * m2.d; - const d = m1.b * m2.c + m1.d * m2.d; - const e = m1.a * m2.e + m1.c * m2.f + m1.e; - const f = m1.b * m2.e + m1.d * m2.f + m1.f; - m1.a = a; - m1.b = b; - m1.c = c; - m1.d = d; - m1.e = e; - m1.f = f; - return m1; - } - - /** - * @param {Matrix} m1 - * @param {Matrix} m2 - * @return {Matrix} - */ - self.multiply = function(m1, m2) { - m1 = m1.copy(); - return self.multiplyUnsafe(m1, m2); - } - - /** - * @param {...Matrix} matrices - * @return {Matrix} - */ - self.compose = function(...matrices) { - switch (matrices.length) { - case 0: - throw new Error('no matrices provided') - - case 1: - return matrices[0] - - case 2: - return self.multiply(matrices[0], matrices[1]) - - default: { - let result = matrices[0].copy(); - for (let i=1; i<matrices.length; i++) { - result = self.multiplyUnsafe(result, matrices[i]); - } - return result; - } - } - }; - - /** - * @param {gpt.Point} p - * @return {Matrix} - */ - self.translateMatrix = function(p) { - return new Matrix(1, 0, 0, 1, p.x, p.y); - }; - - /** - * @param {gpt.Point} p - * @return {Matrix} - */ - self.scaleMatrix = function(p) { - return new Matrix(p.x, 0, 0, p.y, 0, 0); - }; - - /** - * @param {number} angle - * @return {Matrix} - */ - self.rotateMatrix = function(angle) { - const r = math.toRadiants(angle); - return new Matrix( - Math.cos(r), - Math.sin(r), - -Math.sin(r), - Math.cos(r), - 0, - 0 - ); - }; - - /** - * @param {Matrix} m - * @param {gpt.Point} p - * @return {Matrix} - */ - self.translate = function(m, p) { - return self.multiply(m, self.translateMatrix(p)); - } - - /** - * @param {Matrix} m - * @param {angle} angle - * @param {gpt.Point?} center - * @return {Matrix} - */ - self.rotate = function(m, angle, center) { - if (center === undefined) { - return self.multiply(m, self.rotateMatrix(angle)); - } else { - return self.compose( - m, - self.translateMatrix(center), - self.rotateMatrix(angle), - self.translateMatrix(gpt.negate(center)) - ); - } - }; - - /** - * @param {Matrix} m - * @param {gpt.Point} scale - * @param {gpt.Point?} center - * @return {Matrix} - */ - self.scale = function(m, scale, center) { - if (center === undefined) { - return self.multiply(m, self.scaleMatrix(scale)); - } else { - return self.compose( - m, - self.translateMatrix(center), - self.scaleMatrix(scale), - self.translateMatrix(gpt.negate(center)) - ); - } - }; -}); diff --git a/frontend/src/uxbox/util/geom/_point.js b/frontend/src/uxbox/util/geom/_point.js deleted file mode 100644 index 720d2f904..000000000 --- a/frontend/src/uxbox/util/geom/_point.js +++ /dev/null @@ -1,242 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This Source Code Form is "Incompatible With Secondary Licenses", as - * defined by the Mozilla Public License, v. 2.0. - * - * Copyright (c) 2020 Andrey Antukh <niwi@niwi.nz> -*/ - -// NOTE: this code is unused, but is preserved for the case when we -// note that the cljs impl has not not enough performance. - -goog.provide("uxbox.util.geom.point_impl"); -goog.provide("uxbox.util.geom.point_impl.Point"); -goog.require("goog.math"); - -goog.scope(function() { - const self = uxbox.util.geom.point_impl; - const math = goog.math; - - /** - * @param {number} x - * @param {number} y - * @struct - */ - class Point { - constructor(x, y) { - this.x = x; - this.y = y; - } - - toString() { - return "point(" + this.x + ", " + this.y + ")"; - } - } - - self.Point = Point; - - self.point = function(x, y) { - let xv = null; - let yv = null; - - if (x === undefined) { - return new Point(0, 0); - } else { - xv = x; - } - - if (y === undefined) { - yv = x; - } else { - yv = y; - } - - return new Point(xv, yv); - }; - - function isPoint(p) { - return p instanceof Point; - } - - self.isPoint = isPoint; - - /** - * @param {Point} p - * @param {number} angle - * @return {Point} - */ - self.rotate = function(p, angle) { - const r = math.toRadians(angle); - const sin = Math.sin(r); - const cos = Math.cos(r); - - const x = p.x; - const y = p.y; - - const point = new Point( - x * cos - y * sin, - x * sin + y * cos - ); - - return self.roundTo(point, 6) - }; - - /** - * @param {Point} p - * @param {Point} other - * @return {Point} - */ - self.add = function(p, other) { - return new Point( - p.x + other.x, - p.y + other.y - ); - }; - - /** - * @param {Point} p - * @param {Point} other - * @return {Point} - */ - self.subtract = function(p, other) { - return new Point( - p.x - other.x, - p.y - other.y - ); - }; - - /** - * @param {Point} p - * @param {Point} other - * @return {Point} - */ - self.multiply = function(p, other) { - return new Point( - p.x * other.x, - p.y * other.y - ); - }; - - /** - * @param {Point} p - * @param {Point} other - * @return {Point} - */ - self.divide = function(p, other) { - return new Point( - p.x / other.x, - p.y / other.y - ); - }; - - /** - * @param {Point} p - * @return {Point} - */ - self.negate = function(p) { - const x = p.x, y = p.y; - return new Point( - x === 0 ? x : x * -1, - y === 0 ? y : y * -1 - ); - }; - - /** - * @param {Point} p - * @param {Point} other - * @return {number} - */ - self.distance = function(p, other) { - const dx = p.x - other.x; - const dy = p.y - other.y; - return Math.sqrt(Math.pow(dx, 2), - Math.pow(dy, 2)); - }; - - /** - * @param {Point} p - * @param {Point} center - * @return {number} - */ - self.angle = function(p, center) { - if (center !== undefined) { - p = self.subtract(p, center); - } - - return math.toDegrees(Math.atan2(p.y, p.x)); - }; - - /** - * @param {Point} p - * @param {Point} other - * @return {number} - */ - self.length = function(p) { - return Math.sqrt(Math.pow(p.x, 2) + Math.pow(p.y, 2)); - }; - - /** - * @param {Point} p - * @return {number} - */ - self.angle2other = function(p, other) { - let angle = ((p.x * other.x) + (p.y * other.y)) / (self.length(p) * self.length(other)); - - if (angle < -1) { - angle = -1; - } else if (angle > 1) { - angle = 1; - } - - angle = Math.acos(angle); - angle = math.toDegrees(angle); - return parseFloat(angle.toFixed(6)); - }; - - /** - * @param {Point} p - * @param {number} angle - * @return {Point} - */ - self.updateAngle = function(p, angle) { - const len = self.length(p); - const r = math.toRadiants(angle); - - return new Point( - Math.cos(r) * len, - Math.sin(r) * len - ); - }; - - /** - * @param {Point} p - * @param {number} decimals - * @return {Point} - */ - self.roundTo = function(p, decimals) { - return new Point( - parseFloat(p.x.toFixed(decimals)), - parseFloat(p.y.toFixed(decimals)) - ); - }; - - // class Matrix { - // constructor() { - // this.a = 1; - // this.b = 0; - // this.c = 0; - // this.d = 1; - // this.e = 0; - // this.f = 0; - // } - // } - - // self = uxbox.util.geom.matrix_impl; - // self.Matrix = Matrix; - // self.sayHello = function() { - // console.log("hello"); - // } -}); diff --git a/frontend/src/uxbox/util/geom/grid.cljs b/frontend/src/uxbox/util/geom/grid.cljs index f1143f192..cffa86088 100644 --- a/frontend/src/uxbox/util/geom/grid.cljs +++ b/frontend/src/uxbox/util/geom/grid.cljs @@ -9,8 +9,8 @@ (ns uxbox.util.geom.grid (:require - [uxbox.util.math :as mth] - [uxbox.util.geom.point :as gpt])) + [uxbox.common.math :as mth] + [uxbox.common.geom.point :as gpt])) (def ^:private default-items 12) diff --git a/frontend/src/uxbox/util/geom/range_tree.cljs b/frontend/src/uxbox/util/geom/range_tree.cljs deleted file mode 100644 index 72eeae5d8..000000000 --- a/frontend/src/uxbox/util/geom/range_tree.cljs +++ /dev/null @@ -1,25 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; This Source Code Form is "Incompatible With Secondary Licenses", as -;; defined by the Mozilla Public License, v. 2.0. -;; -;; Copyright (c) 2020 UXBOX Labs SL - -(ns uxbox.util.geom.range-tree - (:require - [cljs.spec.alpha :as s])) - - -(defn make-tree [objects]) - -(defn add-shape [shape]) -(defn remove-shape [shape]) -(defn update-shape [old-shape new-shape]) - -(defn query [point match-dist]) ;; Return {:x => [(point, distance, shape-id)]} - - - -;; diff --git a/frontend/src/uxbox/util/geom/snap_points.cljs b/frontend/src/uxbox/util/geom/snap_points.cljs index ebdfbc54d..593e327ae 100644 --- a/frontend/src/uxbox/util/geom/snap_points.cljs +++ b/frontend/src/uxbox/util/geom/snap_points.cljs @@ -11,8 +11,8 @@ (:require [cljs.spec.alpha :as s] [clojure.set :as set] - [uxbox.util.geom.shapes :as gsh] - [uxbox.util.geom.point :as gpt])) + [uxbox.common.geom.shapes :as gsh] + [uxbox.common.geom.point :as gpt])) (defn- frame-snap-points [{:keys [x y width height] :as frame}] (into #{(gpt/point x y) diff --git a/frontend/src/uxbox/util/perf.cljs b/frontend/src/uxbox/util/perf.cljs index 2ce76a1d3..6f6b493c0 100644 --- a/frontend/src/uxbox/util/perf.cljs +++ b/frontend/src/uxbox/util/perf.cljs @@ -7,11 +7,12 @@ (ns uxbox.util.perf "Performance profiling for react components." (:require-macros [uxbox.util.perf]) - (:require [uxbox.util.math :as math] - [rumext.alpha :as mf] - [goog.functions :as f] - ["react" :as react] - ["tdigest" :as td])) + (:require + [uxbox.common.math :as math] + [rumext.alpha :as mf] + [goog.functions :as f] + ["react" :as react] + ["tdigest" :as td])) ;; For use it, just wrap the component you want to profile with ;; `perf/profiler` component and pass a label for debug purpose. diff --git a/frontend/src/uxbox/util/transit.cljs b/frontend/src/uxbox/util/transit.cljs index 5b364eb28..c1c37c562 100644 --- a/frontend/src/uxbox/util/transit.cljs +++ b/frontend/src/uxbox/util/transit.cljs @@ -7,8 +7,8 @@ (ns uxbox.util.transit "A lightweight abstraction for transit serialization." (:require [cognitect.transit :as t] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.matrix :as gmt] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.matrix :as gmt] [uxbox.util.time :as dt])) (deftype Blob [content] @@ -29,18 +29,40 @@ (fn [value] (->Blob (js/JSON.parse value))))) +;; --- Transit adapters + +(def point-write-handler + (t/write-handler + (constantly "point") + (fn [v] (into {} v)))) + +(def point-read-handler + (t/read-handler + (fn [value] + (gpt/map->Point value)))) + +(def matrix-write-handler + (t/write-handler + (constantly "matrix") + (fn [v] (into {} v)))) + +(def matrix-read-handler + (t/read-handler + (fn [value] + (gmt/map->Matrix value)))) + ;; --- Transit Handlers (def ^:privare +read-handlers+ {"u" uuid "jsonblob" blob-read-handler - "matrix" gmt/matrix-read-handler - "point" gpt/point-read-handler}) + "matrix" matrix-read-handler + "point" point-read-handler}) (def ^:privare +write-handlers+ - {gmt/Matrix gmt/matrix-write-handler + {gmt/Matrix matrix-write-handler Blob blob-write-handler - gpt/Point gpt/point-write-handler}) + gpt/Point point-write-handler}) ;; --- Public Api @@ -56,4 +78,3 @@ (t/write w data)) (catch :default e (throw e)))) - diff --git a/frontend/src/uxbox/worker/selection.cljs b/frontend/src/uxbox/worker/selection.cljs index 8d7a5e248..603d17b2d 100644 --- a/frontend/src/uxbox/worker/selection.cljs +++ b/frontend/src/uxbox/worker/selection.cljs @@ -16,7 +16,7 @@ [uxbox.common.pages :as cp] [uxbox.common.uuid :as uuid] [uxbox.worker.impl :as impl] - [uxbox.util.geom.shapes :as geom] + [uxbox.common.geom.shapes :as geom] [uxbox.util.quadtree :as qdt])) (defonce state (l/atom {})) diff --git a/frontend/tests/uxbox/test_util_geom.cljs b/frontend/tests/uxbox/test_util_geom.cljs index 8770d7e42..ae79fabea 100644 --- a/frontend/tests/uxbox/test_util_geom.cljs +++ b/frontend/tests/uxbox/test_util_geom.cljs @@ -1,8 +1,8 @@ (ns uxbox.test-util-geom (:require [cljs.test :as t :include-macros true] [cljs.pprint :refer [pprint]] - [uxbox.util.geom.point :as gpt] - [uxbox.util.geom.matrix :as gmt])) + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.matrix :as gmt])) (t/deftest point-constructors-test (let [p (gpt/point 1 2)] diff --git a/frontend/tests/uxbox/test_util_range_tree.cljs b/frontend/tests/uxbox/test_util_range_tree.cljs index ba0c82ac4..8e009c07a 100644 --- a/frontend/tests/uxbox/test_util_range_tree.cljs +++ b/frontend/tests/uxbox/test_util_range_tree.cljs @@ -1,7 +1,7 @@ (ns uxbox.test-util-range-tree (:require [cljs.test :as t :include-macros true] [cljs.pprint :refer [pprint]] - [uxbox.util.geom.point :as gpt] + [uxbox.common.geom.point :as gpt] [uxbox.util.range-tree :as rt])) (defn check-max-height [tree num-nodes])