From b5a6d9981d3ba5aa4381765cb989109ea7636de1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 22 May 2020 13:50:52 +0200 Subject: [PATCH] :bug: Fix backend incompatibilities on common module. --- common/uxbox/common/geom/point.cljc | 2 +- common/uxbox/common/geom/shapes.cljc | 10 ++++---- common/uxbox/common/math.cljc | 34 ++++++++++++++-------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/common/uxbox/common/geom/point.cljc b/common/uxbox/common/geom/point.cljc index 551bf3b45b..1265221d2e 100644 --- a/common/uxbox/common/geom/point.cljc +++ b/common/uxbox/common/geom/point.cljc @@ -11,7 +11,7 @@ (:refer-clojure :exclude [divide min max]) (:require #?(:cljs [cljs.core :as c] - :clj [clj.core :as c]) + :clj [clojure.core :as c]) [cuerdas.core :as str] [uxbox.common.math :as mth])) diff --git a/common/uxbox/common/geom/shapes.cljc b/common/uxbox/common/geom/shapes.cljc index 26404d9049..7a0f2b8039 100644 --- a/common/uxbox/common/geom/shapes.cljc +++ b/common/uxbox/common/geom/shapes.cljc @@ -22,7 +22,7 @@ (declare move-rect) (declare move-path) -(defn- _chk +(defn -chk "Function that checks if a number is nil or nan. Will return 0 when not valid and the number otherwise." [v] @@ -42,8 +42,8 @@ for rect-like shapes." [shape {dx :x dy :y}] (assoc shape - :x (+ (_chk (:x shape)) (_chk dx)) - :y (+ (_chk (:y shape)) (_chk dy)))) + :x (+ (-chk (:x shape)) (-chk dx)) + :y (+ (-chk (:y shape)) (-chk dy)))) (defn- move-path "A specialized function for relative movement @@ -78,8 +78,8 @@ "A specialized function for absolute moviment for rect-like shapes." [shape {:keys [x y] :as pos}] - (let [dx (if x (- (_chk x) (_chk (:x shape))) 0) - dy (if y (- (_chk y) (_chk (:y shape))) 0)] + (let [dx (if x (- (-chk x) (-chk (:x shape))) 0) + dy (if y (- (-chk y) (-chk (:y shape))) 0)] (move shape (gpt/point dx dy)))) ;; --- Center diff --git a/common/uxbox/common/math.cljc b/common/uxbox/common/math.cljc index ef037ca842..d6d7598e43 100644 --- a/common/uxbox/common/math.cljc +++ b/common/uxbox/common/math.cljc @@ -12,54 +12,54 @@ #?(:cljs (:require [goog.math :as math]))) -(defn ^boolean nan? +(defn nan? [v] #?(:cljs (js/isNaN v) :clj (Double/isNaN v))) -(defn ^boolean finite? +(defn finite? [v] #?(:cljs (js/isFinite v) :clj (Double/isFinite v))) (defn abs - [^number v] + [v] #?(:cljs (js/Math.abs v) :clj (Math/abs v))) (defn sin "Returns the sine of a number" - [^number v] + [v] #?(:cljs (js/Math.sin v) - :clj (Math/sin))) + :clj (Math/sin v))) (defn cos "Returns the cosine of a number." - [^number v] + [v] #?(:cljs (js/Math.cos v) :clj (Math/cos v))) (defn acos "Returns the arccosine of a number." - [^number v] + [v] #?(:cljs (js/Math.acos v) :clj (Math/acos v))) (defn tan "Returns the tangent of a number." - [^number v] + [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] + [x y] #?(:cljs (js/Math.atan2 x y) :clj (Math/atan2 x y))) (defn neg "Negate the number" - [^number v] + [v] (- v)) (defn sqrt @@ -77,39 +77,39 @@ (defn floor "Returns the largest integer less than or equal to a given number." - [^number v] + [v] #?(:cljs (js/Math.floor v) - :clj (Math/floor))) + :clj (Math/floor v))) (defn round "Returns the value of a number rounded to the nearest integer." - [^number v] + [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] + [v] #?(:cljs (js/Math.ceil v) :clj (Math/ceil v))) (defn precision - [^number v ^number n] + [v n] (when (and (number? v) (number? n)) #?(: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] + [degrees] #?(:cljs (math/toRadians degrees) :clj (Math/toRadians degrees))) (defn degrees "Converts radians to degrees." - [^number radians] + [radians] #?(:cljs (math/toDegrees radians) :clj (Math/toDegrees radians)))