File tree 2 files changed +17
-2
lines changed
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
(ns renderer.tool.misc.measure
2
2
(:require
3
3
[clojure.core.matrix :as mat]
4
- [goog.math]
5
4
[re-frame.core :as rf]
6
5
[renderer.document.subs :as-alias document.s]
7
6
[renderer.element.handlers :as element.h]
8
7
[renderer.handlers :as handlers]
9
8
[renderer.tool.base :as tool]
10
9
[renderer.tool.overlay :as overlay]
10
+ [renderer.utils.math :as math]
11
11
[renderer.utils.units :as units]))
12
12
13
13
(derive :measure ::tool/tool )
53
53
[{:keys [attrs key hypotenuse]}]
54
54
(let [{:keys [x1 x2 y1 y2]} attrs
55
55
[x1 y1 x2 y2] (map units/unit->px [x1 y1 x2 y2])
56
- angle (goog. math/angle x1 y1 x2 y2)
56
+ angle (math/angle x1 y1 x2 y2)
57
57
zoom @(rf/subscribe [::document.s/zoom ])
58
58
straight? (< angle 180 )
59
59
straight-angle (if straight? angle (- angle 360 ))]
Original file line number Diff line number Diff line change 3
3
[clojure.math :as math]))
4
4
5
5
(defn clamp
6
+ " Clamps a number within the provided bounds."
6
7
[x minimum maximum]
7
8
(min (max x minimum) maximum))
8
9
13
14
(defn angle-dy
14
15
[degrees radius]
15
16
(* radius (Math/sin (math/to-radians degrees))))
17
+
18
+ (defn normalize-angle
19
+ " Normalizes an angle to be in range [0-360). Angles outside this range will
20
+ be normalized to be the equivalent angle with that range."
21
+ [angle]
22
+ (mod angle (* 2 Math/PI)))
23
+
24
+ (defn angle
25
+ [x1 y1 x2 y2]
26
+ (-> (Math/atan2 (- y2 y1) (- x2 x1))
27
+ normalize-angle
28
+ math/to-degrees))
29
+
30
+
You can’t perform that action at this time.
0 commit comments