-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmath.go
74 lines (67 loc) · 1.16 KB
/
math.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package diagram
import "math"
func niceNumber(span float64, round bool) float64 {
exp := math.Floor(math.Log10(span))
frac := span / math.Pow(10, exp)
var nice float64
if round {
switch {
case frac < 1.5:
nice = 1
case frac < 3:
nice = 2
case frac < 7:
nice = 5
default:
nice = 10
}
} else {
switch {
case frac <= 1:
nice = 1
case frac <= 2:
nice = 2
case frac <= 5:
nice = 5
default:
nice = 10
}
}
return nice * math.Pow(10, exp)
}
func lerpUnit(p, min, max float64) float64 {
pu := (p + 1) * 0.5
return pu*(max-min) + min
}
func cubicPulse(center, radius, invradius, at float64) float64 {
at = at - center
if at < 0 {
at = -at
}
if at > radius {
return 0
}
at *= invradius
return 1 - at*at*(3-2*at)
}
func IntsToFloat64s(xs []int) []float64 {
r := make([]float64, len(xs))
for i := range xs {
r[i] = float64(xs[i])
}
return r
}
func Int32sToFloat64s(xs []int32) []float64 {
r := make([]float64, len(xs))
for i := range xs {
r[i] = float64(xs[i])
}
return r
}
func Int64sToFloat64s(xs []int64) []float64 {
r := make([]float64, len(xs))
for i := range xs {
r[i] = float64(xs[i])
}
return r
}