map-2d-base 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ function clamp(value, min, max) {
2
+ return Math.min(Math.max(value, min), max);
3
+ }
4
+ function squaredSegmentDistance(x, y, x1, y1, x2, y2) {
5
+ const dx = x2 - x1;
6
+ const dy = y2 - y1;
7
+ if (dx !== 0 || dy !== 0) {
8
+ const t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
9
+ if (t > 1) {
10
+ x1 = x2;
11
+ y1 = y2;
12
+ } else if (t > 0) {
13
+ x1 += dx * t;
14
+ y1 += dy * t;
15
+ }
16
+ }
17
+ return squaredDistance(x, y, x1, y1);
18
+ }
19
+ function squaredDistance(x1, y1, x2, y2) {
20
+ const dx = x2 - x1;
21
+ const dy = y2 - y1;
22
+ return dx * dx + dy * dy;
23
+ }
24
+ function solveLinearSystem(mat) {
25
+ const n = mat.length;
26
+ for (let i = 0; i < n; i++) {
27
+ let maxRow = i;
28
+ let maxEl = Math.abs(mat[i][i]);
29
+ for (let r = i + 1; r < n; r++) {
30
+ const absValue = Math.abs(mat[r][i]);
31
+ if (absValue > maxEl) {
32
+ maxEl = absValue;
33
+ maxRow = r;
34
+ }
35
+ }
36
+ if (maxEl === 0) {
37
+ return null;
38
+ }
39
+ const tmp = mat[maxRow];
40
+ mat[maxRow] = mat[i];
41
+ mat[i] = tmp;
42
+ for (let j = i + 1; j < n; j++) {
43
+ const coef = -mat[j][i] / mat[i][i];
44
+ for (let k = i; k < n + 1; k++) {
45
+ if (i == k) {
46
+ mat[j][k] = 0;
47
+ } else {
48
+ mat[j][k] += coef * mat[i][k];
49
+ }
50
+ }
51
+ }
52
+ }
53
+ const x = new Array(n);
54
+ for (let l = n - 1; l >= 0; l--) {
55
+ x[l] = mat[l][n] / mat[l][l];
56
+ for (let m = l - 1; m >= 0; m--) {
57
+ mat[m][n] -= mat[m][l] * x[l];
58
+ }
59
+ }
60
+ return x;
61
+ }
62
+ function toDegrees(angleInRadians) {
63
+ return angleInRadians * 180 / Math.PI;
64
+ }
65
+ function toRadians(angleInDegrees) {
66
+ return angleInDegrees * Math.PI / 180;
67
+ }
68
+ function modulo(a, b) {
69
+ const r = a % b;
70
+ return r * b < 0 ? r + b : r;
71
+ }
72
+ function lerp(a, b, x) {
73
+ return a + x * (b - a);
74
+ }
75
+ function toFixed(n, decimals) {
76
+ const factor = Math.pow(10, decimals);
77
+ return Math.round(n * factor) / factor;
78
+ }
79
+ function floor(n, decimals) {
80
+ return Math.floor(toFixed(n, decimals));
81
+ }
82
+ function ceil(n, decimals) {
83
+ return Math.ceil(toFixed(n, decimals));
84
+ }
85
+ function wrap(n, min, max) {
86
+ if (n >= min && n < max) {
87
+ return n;
88
+ }
89
+ const range = max - min;
90
+ return ((n - min) % range + range) % range + min;
91
+ }
92
+ export {
93
+ squaredSegmentDistance as a,
94
+ toFixed as b,
95
+ clamp as c,
96
+ solveLinearSystem as d,
97
+ ceil as e,
98
+ floor as f,
99
+ toDegrees as g,
100
+ lerp as l,
101
+ modulo as m,
102
+ squaredDistance as s,
103
+ toRadians as t,
104
+ wrap as w
105
+ };
@@ -0,0 +1,4 @@
1
+ import { P } from "./chunks/index-CwJi8_r0.js";
2
+ export {
3
+ P as Point
4
+ };