1 | export 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 |
|
12 | export function isOutside(pos, range) {
|
13 | return pos < range[0] || pos > range[1];
|
14 | }
|
15 | export function getDuration(distance, deceleration) {
|
16 | var duration = Math.sqrt(distance / deceleration * 2);
|
17 |
|
18 | return duration < 100 ? 0 : duration;
|
19 | }
|
20 | export function isCircularable(destPos, range, circular) {
|
21 | return (circular[1] && destPos > range[1]) ||
|
22 | (circular[0] && destPos < range[0]);
|
23 | }
|
24 | export 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) {
|
30 | toPos = (toPos - max) % length + min;
|
31 | }
|
32 | if (circular[0] && pos < min) {
|
33 | toPos = (toPos - min) % length + max;
|
34 | }
|
35 | return toPos;
|
36 | }
|
37 |
|
\ | No newline at end of file |