-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelpers.js
34 lines (32 loc) · 824 Bytes
/
helpers.js
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
export function sv2sl(s, v) {
var l = ((2 - s) * v) / 2
if (l !== 0) {
if (l === 1) {
s = 0
} else if (l < 0.5) {
s = (s * v) / (l * 2)
} else {
s = (s * v) / (2 - l * 2)
}
}
return [s, l]
}
export function xy2deg(x, y) {
const deltaX = 0.5 - x
const deltaY = y - 0.5
const rad = Math.atan2(deltaY, deltaX)
const deg = rad * (180 / Math.PI)
const correctedDeg = (270 + deg) % 360
const errorMargin = 5
const errorMarginFrom45 = correctedDeg % 45
const errorCorrectedDeg =
errorMarginFrom45 > 45 - errorMargin
? correctedDeg + 45 - errorMarginFrom45
: errorMarginFrom45 < errorMargin
? correctedDeg - errorMarginFrom45
: correctedDeg
return errorCorrectedDeg
}
export function angle2rad(angle) {
return angle * (Math.PI / 180)
}