source: imaps-frontend/node_modules/@use-gesture/core/dist/maths-267f0992.cjs.dev.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3function clamp(v, min, max) {
4 return Math.max(min, Math.min(v, max));
5}
6const V = {
7 toVector(v, fallback) {
8 if (v === undefined) v = fallback;
9 return Array.isArray(v) ? v : [v, v];
10 },
11 add(v1, v2) {
12 return [v1[0] + v2[0], v1[1] + v2[1]];
13 },
14 sub(v1, v2) {
15 return [v1[0] - v2[0], v1[1] - v2[1]];
16 },
17 addTo(v1, v2) {
18 v1[0] += v2[0];
19 v1[1] += v2[1];
20 },
21 subTo(v1, v2) {
22 v1[0] -= v2[0];
23 v1[1] -= v2[1];
24 }
25};
26function rubberband(distance, dimension, constant) {
27 if (dimension === 0 || Math.abs(dimension) === Infinity) return Math.pow(distance, constant * 5);
28 return distance * dimension * constant / (dimension + constant * distance);
29}
30function rubberbandIfOutOfBounds(position, min, max, constant = 0.15) {
31 if (constant === 0) return clamp(position, min, max);
32 if (position < min) return -rubberband(min - position, max - min, constant) + min;
33 if (position > max) return +rubberband(position - max, max - min, constant) + max;
34 return position;
35}
36function computeRubberband(bounds, [Vx, Vy], [Rx, Ry]) {
37 const [[X0, X1], [Y0, Y1]] = bounds;
38 return [rubberbandIfOutOfBounds(Vx, X0, X1, Rx), rubberbandIfOutOfBounds(Vy, Y0, Y1, Ry)];
39}
40
41exports.V = V;
42exports.computeRubberband = computeRubberband;
43exports.rubberbandIfOutOfBounds = rubberbandIfOutOfBounds;
Note: See TracBrowser for help on using the repository browser.