-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.gleam
39 lines (31 loc) · 950 Bytes
/
util.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pub fn degrees_to_radians(degrees) {
degrees /. 180.0 *. pi()
}
pub fn radians_to_degrees(radians) {
radians *. 180.0 /. pi()
}
pub fn wrap_to_range(x, min, max) {
let v = fmod(x -. min, max -. min) +. min
case v <=. 0.0 {
True -> v +. max
False -> v
}
}
@external(erlang, "math", "fmod")
@external(javascript, "./extern.mjs", "fmod")
pub fn fmod(x: Float, y: Float) -> Float
@external(erlang, "math", "pi")
@external(javascript, "./extern.mjs", "pi")
pub fn pi() -> Float
@external(erlang, "math", "sin")
@external(javascript, "./extern.mjs", "sin")
pub fn sin(x: Float) -> Float
@external(erlang, "math", "cos")
@external(javascript, "./extern.mjs", "cos")
pub fn cos(x: Float) -> Float
@external(erlang, "math", "atan")
@external(javascript, "./extern.mjs", "atan")
pub fn atan(x: Float) -> Float
@external(erlang, "math", "atan2")
@external(javascript, "./extern.mjs", "atan2")
pub fn atan2(y: Float, x: Float) -> Float