UNPKG

1.29 kBJavaScriptView Raw
1export function getInsidePosition(destPos, range, circular, bounce) {
2 var toDestPos = destPos;
3 var targetRange = [
4 circular[0] ? range[0] : (bounce ? range[0] - bounce[0] : range[0]),
5 circular[1] ? range[1] : (bounce ? range[1] + bounce[1] : range[1]),
6 ];
7 toDestPos = Math.max(targetRange[0], toDestPos);
8 toDestPos = Math.min(targetRange[1], toDestPos);
9 return toDestPos;
10}
11// determine outside
12export function isOutside(pos, range) {
13 return pos < range[0] || pos > range[1];
14}
15export function getDuration(distance, deceleration) {
16 var duration = Math.sqrt(distance / deceleration * 2);
17 // when duration is under 100, then value is zero
18 return duration < 100 ? 0 : duration;
19}
20export function isCircularable(destPos, range, circular) {
21 return (circular[1] && destPos > range[1]) ||
22 (circular[0] && destPos < range[0]);
23}
24export function getCirculatedPos(pos, range, circular) {
25 var toPos = pos;
26 var min = range[0];
27 var max = range[1];
28 var length = max - min;
29 if (circular[1] && pos > max) { // right
30 toPos = (toPos - max) % length + min;
31 }
32 if (circular[0] && pos < min) { // left
33 toPos = (toPos - min) % length + max;
34 }
35 return toPos;
36}
37//# sourceMappingURL=Coordinate.js.map
\No newline at end of file