0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-11 06:21:30 -05:00

🐛 Fix backend incompatibilities on common module.

This commit is contained in:
Andrey Antukh 2020-05-22 13:50:52 +02:00 committed by alonso.torres
parent 524089e051
commit b5a6d9981d
3 changed files with 23 additions and 23 deletions

View file

@ -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]))

View file

@ -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

View file

@ -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)))