@benev/math 0.3.0-2 → 0.3.0-4

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.
Files changed (104) hide show
  1. package/package.json +1 -1
  2. package/s/index.ts +1 -2
  3. package/s/tools/noise.ts +5 -15
  4. package/s/tools/randy.ts +4 -4
  5. package/x/index.d.ts +1 -1
  6. package/x/index.js +1 -1
  7. package/x/tools/noise.d.ts +1 -8
  8. package/x/tools/noise.js +5 -16
  9. package/x/tools/noise.js.map +1 -1
  10. package/x/tools/randy.d.ts +2 -2
  11. package/x/tools/randy.js +4 -4
  12. package/x/tools/randy.js.map +1 -1
  13. package/s/tools/make-noise.ts +0 -13
  14. package/x/concepts/angles.d.ts +0 -29
  15. package/x/concepts/angles.js +0 -62
  16. package/x/concepts/angles.js.map +0 -1
  17. package/x/concepts/circular.d.ts +0 -17
  18. package/x/concepts/circular.js +0 -70
  19. package/x/concepts/circular.js.map +0 -1
  20. package/x/concepts/noise.d.ts +0 -9
  21. package/x/concepts/noise.js +0 -20
  22. package/x/concepts/noise.js.map +0 -1
  23. package/x/concepts/quat.d.ts +0 -35
  24. package/x/concepts/quat.js +0 -110
  25. package/x/concepts/quat.js.map +0 -1
  26. package/x/concepts/randy.d.ts +0 -39
  27. package/x/concepts/randy.js +0 -95
  28. package/x/concepts/randy.js.map +0 -1
  29. package/x/concepts/scalar.d.ts +0 -51
  30. package/x/concepts/scalar.js +0 -219
  31. package/x/concepts/scalar.js.map +0 -1
  32. package/x/concepts/spline.d.ts +0 -9
  33. package/x/concepts/spline.js +0 -59
  34. package/x/concepts/spline.js.map +0 -1
  35. package/x/concepts/vec2.d.ts +0 -114
  36. package/x/concepts/vec2.js +0 -314
  37. package/x/concepts/vec2.js.map +0 -1
  38. package/x/concepts/vec3.d.ts +0 -117
  39. package/x/concepts/vec3.js +0 -357
  40. package/x/concepts/vec3.js.map +0 -1
  41. package/x/concepts/vec4.d.ts +0 -21
  42. package/x/concepts/vec4.js +0 -62
  43. package/x/concepts/vec4.js.map +0 -1
  44. package/x/helpers/angles.d.ts +0 -19
  45. package/x/helpers/angles.js +0 -41
  46. package/x/helpers/angles.js.map +0 -1
  47. package/x/helpers/circular.d.ts +0 -17
  48. package/x/helpers/circular.js +0 -71
  49. package/x/helpers/circular.js.map +0 -1
  50. package/x/helpers/noise.d.ts +0 -9
  51. package/x/helpers/noise.js +0 -20
  52. package/x/helpers/noise.js.map +0 -1
  53. package/x/helpers/randy.d.ts +0 -31
  54. package/x/helpers/randy.js +0 -85
  55. package/x/helpers/randy.js.map +0 -1
  56. package/x/helpers/scalar.d.ts +0 -51
  57. package/x/helpers/scalar.js +0 -219
  58. package/x/helpers/scalar.js.map +0 -1
  59. package/x/helpers/spline.d.ts +0 -9
  60. package/x/helpers/spline.js +0 -61
  61. package/x/helpers/spline.js.map +0 -1
  62. package/x/importmap.json +0 -7
  63. package/x/primitives/circular.d.ts +0 -17
  64. package/x/primitives/circular.js +0 -70
  65. package/x/primitives/circular.js.map +0 -1
  66. package/x/primitives/quat.d.ts +0 -35
  67. package/x/primitives/quat.js +0 -110
  68. package/x/primitives/quat.js.map +0 -1
  69. package/x/primitives/scalar.d.ts +0 -51
  70. package/x/primitives/scalar.js +0 -219
  71. package/x/primitives/scalar.js.map +0 -1
  72. package/x/primitives/vec2.d.ts +0 -114
  73. package/x/primitives/vec2.js +0 -319
  74. package/x/primitives/vec2.js.map +0 -1
  75. package/x/primitives/vec3.d.ts +0 -117
  76. package/x/primitives/vec3.js +0 -363
  77. package/x/primitives/vec3.js.map +0 -1
  78. package/x/primitives/vec4.d.ts +0 -21
  79. package/x/primitives/vec4.js +0 -62
  80. package/x/primitives/vec4.js.map +0 -1
  81. package/x/tools/circular.d.ts +0 -17
  82. package/x/tools/circular.js +0 -71
  83. package/x/tools/circular.js.map +0 -1
  84. package/x/tools/scalar.d.ts +0 -51
  85. package/x/tools/scalar.js +0 -219
  86. package/x/tools/scalar.js.map +0 -1
  87. package/x/utils/angles.d.ts +0 -19
  88. package/x/utils/angles.js +0 -41
  89. package/x/utils/angles.js.map +0 -1
  90. package/x/utils/circular.d.ts +0 -17
  91. package/x/utils/circular.js +0 -70
  92. package/x/utils/circular.js.map +0 -1
  93. package/x/utils/noise.d.ts +0 -9
  94. package/x/utils/noise.js +0 -20
  95. package/x/utils/noise.js.map +0 -1
  96. package/x/utils/randy.d.ts +0 -31
  97. package/x/utils/randy.js +0 -85
  98. package/x/utils/randy.js.map +0 -1
  99. package/x/utils/scalar.d.ts +0 -51
  100. package/x/utils/scalar.js +0 -219
  101. package/x/utils/scalar.js.map +0 -1
  102. package/x/utils/spline.d.ts +0 -9
  103. package/x/utils/spline.js +0 -61
  104. package/x/utils/spline.js.map +0 -1
@@ -1,95 +0,0 @@
1
- /** utility for generating and using random numbers. */
2
- export class Randy {
3
- seed;
4
- random;
5
- constructor(seed = Randy.randomSeed()) {
6
- this.seed = seed;
7
- this.random = Randy.makeRandom(seed);
8
- }
9
- /** obtain a random positive 32 bit integer. */
10
- static randomSeed() {
11
- return Math.floor(Math.random() * 2147483647);
12
- }
13
- /** seed a pseudo-random number generator function that produces numbers between 0 and 1. */
14
- static makeRandom(seed) {
15
- seed = (seed ^ 0x6D2B79F5) + 0x1E35A7BD;
16
- seed = (Math.abs(seed | 0) % 2147483647) || 1;
17
- function random() {
18
- seed = (Math.imul(48271, seed) | 0) % 2147483647;
19
- return (seed & 2147483647) / 2147483648;
20
- }
21
- random(); // discard first value
22
- return random;
23
- }
24
- /** obtain a random positive integer. */
25
- integer() {
26
- return Math.floor(this.random() * 2147483647);
27
- }
28
- /** return true or false, given a 0 to 1 probability fraction. */
29
- roll(chance = 0.5) {
30
- return this.random() <= chance;
31
- }
32
- /** generate a random number between two numbers. */
33
- range(a, b) {
34
- const difference = b - a;
35
- const value = difference * this.random();
36
- return a + value;
37
- }
38
- /** generate a random integer between two numbers (inclusive). */
39
- integerRange(a, b) {
40
- return Math.round(this.range(a, b));
41
- }
42
- /** randomly choose an index given an array length. */
43
- index(length) {
44
- return Math.floor(this.random() * length);
45
- }
46
- /** return a random item from the given array. */
47
- choose(array) {
48
- return array[this.index(array.length)];
49
- }
50
- /** remove and return a random item from the given array. */
51
- yoink(array) {
52
- const index = this.index(array.length);
53
- const [item] = array.splice(index, 1);
54
- return item;
55
- }
56
- /** randomly select a number of array items. */
57
- select(count, array) {
58
- const copy = [...array];
59
- if (count >= array.length)
60
- return copy;
61
- const selection = [];
62
- for (let i = 0; i < count; i++)
63
- selection.push(this.yoink(copy));
64
- return selection;
65
- }
66
- /** remove and return a number of items from the given array. */
67
- take(count, array) {
68
- const selection = [];
69
- for (let i = 0; i < count; i++) {
70
- if (array.length === 0)
71
- return selection;
72
- selection.push(this.yoink(array));
73
- }
74
- return selection;
75
- }
76
- /** shuffle an array in-place using (fisher-yates) */
77
- shuffle(array) {
78
- for (let i = array.length - 1; i > 0; i--) {
79
- const j = Math.floor(this.random() * (i + 1));
80
- [array[i], array[j]] = [array[j], array[i]];
81
- }
82
- return array;
83
- }
84
- /** @deprecated create an instance with the given seed number. */
85
- static seed(seed) {
86
- return new this(seed);
87
- }
88
- /** @deprecated renamed to `take` */
89
- extract(count, array) { return this.take(count, array); }
90
- /** @deprecated renamed to `range` */
91
- between(a, b) { return this.range(a, b); }
92
- /** @deprecated renamed to `integerRange` */
93
- integerBetween(a, b) { return this.integerRange(a, b); }
94
- }
95
- //# sourceMappingURL=randy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"randy.js","sourceRoot":"","sources":["../../s/concepts/randy.ts"],"names":[],"mappings":"AAGA,uDAAuD;AACvD,MAAM,OAAO,KAAK;IAGW;IAF5B,MAAM,CAAQ;IAEd,YAA4B,OAAe,KAAK,CAAC,UAAU,EAAE;QAAjC,SAAI,GAAJ,IAAI,CAA6B;QAC5D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,+CAA+C;IAC/C,MAAM,CAA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,OAAO,SAAS,CAAA;IACjB,CAAC;IAED,qDAAqD;IACrD,OAAO,CAAI,KAAU;QACpB,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAC5C;YAAA,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7C,CAAC;QACD,OAAO,KAAK,CAAA;IACb,CAAC;IAED,iEAAiE;IACjE,MAAM,CAAC,IAAI,CAAC,IAAY;QACvB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;IACtB,CAAC;IAED,oCAAoC;IACpC,OAAO,CAAI,KAAa,EAAE,KAAU,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA,CAAC,CAAC;IAExE,qCAAqC;IACrC,OAAO,CAAC,CAAS,EAAE,CAAS,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,CAAC;IAEzD,4CAA4C;IAC5C,cAAc,CAAC,CAAS,EAAE,CAAS,IAAI,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,CAAC;CACvE"}
@@ -1,51 +0,0 @@
1
- export declare class Scalar {
2
- x: number;
3
- constructor(x: number);
4
- static new(x: number): Scalar;
5
- clone(): Scalar;
6
- set(x: number): this;
7
- static isBetween(x: number, a?: number, b?: number): boolean;
8
- isBetween(a?: number, b?: number): boolean;
9
- static isNear(x: number, y: number, epsilon?: number): boolean;
10
- isNear(y: number, epsilon?: number): boolean;
11
- static add(...nums: number[]): number;
12
- add(...nums: number[]): this;
13
- subtract(...nums: number[]): this;
14
- static min(x: number, minimum?: number): number;
15
- min(minimum?: number): this;
16
- static max(x: number, maximum?: number): number;
17
- max(maximum?: number): this;
18
- static clamp(x: number, a?: number, b?: number): number;
19
- clamp(a?: number, b?: number): this;
20
- static lerp(x: number, y: number, fraction: number, max?: number): number;
21
- lerp(y: number, fraction: number, max?: number): this;
22
- static step(x: number, y: number, delta: number): number;
23
- step(y: number, delta: number): this;
24
- static creep(difference: number, speed: number, deltaTime: number, speedLimit?: number): number;
25
- static approach(x: number, y: number, speed: number, deltaTime: number, speedLimit?: number): number;
26
- approach(y: number, speed: number, deltaTime: number, speedLimit?: number): this;
27
- static wrap(x: number, a?: number, b?: number): number;
28
- wrap(a?: number, b?: number): this;
29
- static constrainProximity(x: number, y: number, range: number): number;
30
- constrainProximity(y: number, range: number): this;
31
- static inverse(x: number): number;
32
- inverse(): this;
33
- static center(x: number): number;
34
- center(): this;
35
- static uncenter(x: number): number;
36
- uncenter(): this;
37
- static map(x: number, a: number, b: number): number;
38
- map(a: number, b: number): this;
39
- static remap(x: number, a1: number, a2: number, b1?: number, b2?: number, clamp?: boolean): number;
40
- remap(a1: number, a2: number, b1?: number, b2?: number, clamp?: boolean): this;
41
- static magnify(x: number): number;
42
- magnify(): this;
43
- static floor(x: number): number;
44
- floor(): this;
45
- static ceil(x: number): number;
46
- ceil(): this;
47
- static round(x: number): number;
48
- round(): this;
49
- static smooth(x: number, y: number, smoothing: number): number;
50
- smooth(y: number, smoothing: number): this;
51
- }
@@ -1,219 +0,0 @@
1
- export class Scalar {
2
- x;
3
- constructor(x) {
4
- this.x = x;
5
- }
6
- static new(x) {
7
- return new this(x);
8
- }
9
- clone() {
10
- return new Scalar(this.x);
11
- }
12
- set(x) {
13
- this.x = x;
14
- return this;
15
- }
16
- //
17
- // queries
18
- //
19
- static isBetween(x, a = 0, b = 1) {
20
- const min = Math.min(a, b);
21
- const max = Math.max(a, b);
22
- return (x >= min) && (x <= max);
23
- }
24
- isBetween(a = 0, b = 1) {
25
- return Scalar.isBetween(this.x, a, b);
26
- }
27
- static isNear(x, y, epsilon = 0.01) {
28
- return Math.abs(x - y) <= epsilon;
29
- }
30
- isNear(y, epsilon = 0.01) {
31
- return Scalar.isNear(this.x, y, epsilon);
32
- }
33
- //
34
- // chainable transforms
35
- //
36
- static add(...nums) {
37
- let x = 0;
38
- for (const n of nums)
39
- x += n;
40
- return x;
41
- }
42
- add(...nums) {
43
- this.x = Scalar.add(...nums);
44
- return this;
45
- }
46
- subtract(...nums) {
47
- for (const n of nums)
48
- this.x -= n;
49
- return this;
50
- }
51
- static min(x, minimum = 0) {
52
- return Math.max(x, minimum);
53
- }
54
- min(minimum = 0) {
55
- this.x = Scalar.min(this.x, minimum);
56
- return this;
57
- }
58
- static max(x, maximum = 1) {
59
- return Math.min(x, maximum);
60
- }
61
- max(maximum = 1) {
62
- this.x = Scalar.max(this.x, maximum);
63
- return this;
64
- }
65
- static clamp(x, a = 0, b = 1) {
66
- x = Scalar.min(x, Math.min(a, b));
67
- x = Scalar.max(x, Math.max(a, b));
68
- return x;
69
- }
70
- clamp(a = 0, b = 1) {
71
- this.x = Scalar.clamp(this.x, a, b);
72
- return this;
73
- }
74
- static lerp(x, y, fraction, max) {
75
- const difference = y - x;
76
- let delta = difference * fraction;
77
- if (max !== undefined && Math.abs(delta) > max)
78
- delta = Math.sign(delta) * max;
79
- return x + delta;
80
- }
81
- lerp(y, fraction, max) {
82
- this.x = Scalar.lerp(this.x, y, fraction, max);
83
- return this;
84
- }
85
- static step(x, y, delta) {
86
- const difference = y - x;
87
- return (Math.abs(difference) <= delta)
88
- ? y
89
- : x + (Math.sign(difference) * delta);
90
- }
91
- step(y, delta) {
92
- this.x = Scalar.step(this.x, y, delta);
93
- return this;
94
- }
95
- static creep(difference, speed, deltaTime, speedLimit) {
96
- let change = (difference * (1 - Math.exp(-speed * deltaTime)));
97
- if (speedLimit !== undefined) {
98
- const changeLimit = speedLimit * deltaTime;
99
- if (Math.abs(change) > changeLimit)
100
- change = Math.sign(change) * changeLimit;
101
- }
102
- return change;
103
- }
104
- static approach(x, y, speed, deltaTime, speedLimit) {
105
- const difference = y - x;
106
- const change = this.creep(difference, speed, deltaTime, speedLimit);
107
- return x + change;
108
- }
109
- approach(y, speed, deltaTime, speedLimit) {
110
- this.x = Scalar.approach(this.x, y, speed, deltaTime, speedLimit);
111
- return this;
112
- }
113
- static wrap(x, a = 0, b = 1) {
114
- const min = Math.min(a, b);
115
- const max = Math.max(a, b);
116
- const span = max - min;
117
- const adjusted = x - min;
118
- const wrapped = (adjusted < 0)
119
- ? span - (-adjusted % span)
120
- : adjusted % span;
121
- return min + wrapped;
122
- }
123
- wrap(a = 0, b = 1) {
124
- this.x = Scalar.wrap(this.x, a, b);
125
- return this;
126
- }
127
- static constrainProximity(x, y, range) {
128
- const trueDiff = y - x;
129
- const positiveDiff = Math.abs(trueDiff);
130
- const cappedDiff = (positiveDiff > range)
131
- ? range
132
- : positiveDiff;
133
- const newDiff = (trueDiff < 0) ? -cappedDiff : cappedDiff;
134
- return x + newDiff;
135
- }
136
- constrainProximity(y, range) {
137
- this.x = Scalar.constrainProximity(this.x, y, range);
138
- return this;
139
- }
140
- static inverse(x) {
141
- return 1 - x;
142
- }
143
- inverse() {
144
- this.x = Scalar.inverse(this.x);
145
- return this;
146
- }
147
- static center(x) {
148
- return (x * 2) - 1;
149
- }
150
- center() {
151
- this.x = Scalar.center(this.x);
152
- return this;
153
- }
154
- static uncenter(x) {
155
- return (x + 1) / 2;
156
- }
157
- uncenter() {
158
- this.x = Scalar.uncenter(this.x);
159
- return this;
160
- }
161
- static map(x, a, b) {
162
- const difference = b - a;
163
- const value = difference * x;
164
- return a + value;
165
- }
166
- map(a, b) {
167
- this.x = Scalar.map(this.x, a, b);
168
- return this;
169
- }
170
- static remap(x, a1, a2, b1 = 0, b2 = 1, clamp = false) {
171
- const fraction = (x - a1) / (a2 - a1);
172
- const result = (fraction * (b2 - b1)) + b1;
173
- return clamp
174
- ? Scalar.clamp(result, b1, b2)
175
- : result;
176
- }
177
- remap(a1, a2, b1 = 0, b2 = 1, clamp = false) {
178
- this.x = Scalar.remap(this.x, a1, a2, b1, b2, clamp);
179
- return this;
180
- }
181
- static magnify(x) {
182
- return 4 * Math.pow(x - 0.5, 3) + 0.5;
183
- }
184
- magnify() {
185
- this.x = Scalar.magnify(this.x);
186
- return this;
187
- }
188
- static floor(x) {
189
- return Math.floor(x);
190
- }
191
- floor() {
192
- this.x = Scalar.floor(this.x);
193
- return this;
194
- }
195
- static ceil(x) {
196
- return Math.ceil(x);
197
- }
198
- ceil() {
199
- this.x = Scalar.ceil(this.x);
200
- return this;
201
- }
202
- static round(x) {
203
- return Math.round(x);
204
- }
205
- round() {
206
- this.x = Scalar.round(this.x);
207
- return this;
208
- }
209
- static smooth(x, y, smoothing) {
210
- return smoothing <= 1
211
- ? y
212
- : x + ((y - x) / smoothing);
213
- }
214
- smooth(y, smoothing) {
215
- this.x = Scalar.smooth(this.x, y, smoothing);
216
- return this;
217
- }
218
- }
219
- //# sourceMappingURL=scalar.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scalar.js","sourceRoot":"","sources":["../../s/concepts/scalar.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,MAAM;IACC;IAAnB,YAAmB,CAAS;QAAT,MAAC,GAAD,CAAC,CAAQ;IAAG,CAAC;IAEhC,MAAM,CAAC,GAAG,CAAC,CAAS;QACnB,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,CAAS;QACZ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACV,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,EAAE;IACF,UAAU;IACV,EAAE;IAEF,MAAM,CAAC,S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Z,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,SAAiB;QACpD,OAAO,SAAS,IAAI,CAAC;YACpB,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;IAC7B,CAAC;IAAC,MAAM,CAAC,CAAS,EAAE,SAAiB;QACpC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;QAC5C,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
@@ -1,9 +0,0 @@
1
- import { Vec2Array } from "./vec2.js";
2
- /** resolve a number within a linear spline. */
3
- export declare function linear(x: number, points: Vec2Array[]): number;
4
- /** resolve a number within a catmull-rom spline, that's all smooth-like. */
5
- export declare function catmullRom(x: number, points: Vec2Array[]): number;
6
- export declare const ez: {
7
- /** simple linear spline where the control points are equally-spaced based on their array indices (x is expected to be between 0 and 1). */
8
- linear(x: number, points: number[]): number;
9
- };
@@ -1,59 +0,0 @@
1
- import { Scalar } from "./scalar.js";
2
- /** resolve a number within a linear spline. */
3
- export function linear(x, points) {
4
- if (points.length < 2)
5
- throw new Error("need at least two points, come on");
6
- const [first] = points.at(0);
7
- const [last] = points.at(-1);
8
- x = Scalar.clamp(x, first, last);
9
- for (let i = 0; i < points.length - 1; i++) {
10
- const [x0, y0] = points[i];
11
- const [x1, y1] = points[i + 1];
12
- if (x >= x0 && x <= x1) {
13
- const t = (x - x0) / (x1 - x0);
14
- return y0 + t * (y1 - y0);
15
- }
16
- }
17
- throw new Error("x is out of bounds, what are you even doing");
18
- }
19
- /** resolve a number within a catmull-rom spline, that's all smooth-like. */
20
- export function catmullRom(x, points) {
21
- if (points.length < 4)
22
- throw new Error("need at least four points for this magic");
23
- x = Scalar.clamp(x);
24
- // find the segment where 'x' fits
25
- for (let i = 1; i < points.length - 2; i++) {
26
- const [x1,] = points[i];
27
- const [x2,] = points[i + 1];
28
- if (x >= x1 && x <= x2) {
29
- const t = (x - x1) / (x2 - x1);
30
- return helpers.catmullRom(t, points[i - 1], points[i], points[i + 1], points[i + 2]);
31
- }
32
- }
33
- throw new Error("x is out of bounds, try again");
34
- }
35
- export const ez = {
36
- /** simple linear spline where the control points are equally-spaced based on their array indices (x is expected to be between 0 and 1). */
37
- linear(x, points) {
38
- if (points.length < 2)
39
- throw new Error("need at least two points, come on");
40
- const points2 = points.map((p, index) => [Scalar.clamp(index / (points.length - 1)), p]);
41
- return linear(Scalar.clamp(x), points2);
42
- }
43
- };
44
- var helpers;
45
- (function (helpers) {
46
- /** internal big-brain maths for the catmull-rom implementation */
47
- function catmullRom(t, [, p0], [, p1], [, p2], [, p3]) {
48
- const t2 = t * t;
49
- const t3 = t2 * t;
50
- // coefficients for the cubic polynomial (Catmull-Rom)
51
- const a = -0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3;
52
- const b = p0 - 2.5 * p1 + 2 * p2 - 0.5 * p3;
53
- const c = -0.5 * p0 + 0.5 * p2;
54
- const d = p1;
55
- return a * t3 + b * t2 + c * t + d;
56
- }
57
- helpers.catmullRom = catmullRom;
58
- })(helpers || (helpers = {}));
59
- //# sourceMappingURL=spline.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spline.js","sourceRoot":"","sources":["../../s/concepts/spline.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAGlC,+CAA+C;AAC/C,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,MAAmB;IACpD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IAErD,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC7B,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CA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,GAAG,EAAE,GAAG,CAAC,CAAA;QAEjB,sDAAsD;QACtD,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;QACpD,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;QAC3C,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;QAC9B,MAAM,CAAC,GAAG,EAAE,CAAA;QAEZ,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACnC,CAAC;IAlBe,kBAAU,aAkBzB,CAAA;AACF,CAAC,EAtBS,OAAO,KAAP,OAAO,QAsBhB"}
@@ -1,114 +0,0 @@
1
- export type Vec2Array = [number, number];
2
- export type Xy = {
3
- x: number;
4
- y: number;
5
- };
6
- /** https://github.com/microsoft/TypeScript/issues/5863 */
7
- type TsHack<T> = {
8
- new (...a: ConstructorParameters<typeof Vec2>): T;
9
- };
10
- export declare class Vec2 implements Xy {
11
- x: number;
12
- y: number;
13
- constructor(x: number, y: number);
14
- static new<T extends Vec2>(this: TsHack<T>, x: number, y: number): T;
15
- static zero<T extends Vec2>(this: TsHack<T>): T;
16
- static all<T extends Vec2>(this: TsHack<T>, value: number): T;
17
- static array<T extends Vec2>(this: TsHack<T>, v: Vec2Array): T;
18
- static import<T extends Vec2>(this: TsHack<T>, { x, y }: Xy): T;
19
- static from(v: Vec2Array | Xy): Vec2;
20
- static magnitudeSquared(x: number, y: number): number;
21
- static magnitude(x: number, y: number): number;
22
- static average(...vectors: Xy[]): Vec2;
23
- static min(...vecs: Vec2[]): Vec2;
24
- static max(...vecs: Vec2[]): Vec2;
25
- clone(): Vec2;
26
- array(): Vec2Array;
27
- toString(): string;
28
- /** mutator */
29
- set_(x: number, y: number): this;
30
- /** mutator */
31
- set({ x, y }: Xy): this;
32
- magnitudeSquared(): number;
33
- magnitude(): number;
34
- rotation(): number;
35
- equals_(x: number, y: number): boolean;
36
- equals(...vecs: Xy[]): boolean;
37
- dot_(x: number, y: number): number;
38
- dot({ x, y }: Xy): number;
39
- distanceSquared_(x: number, y: number): number;
40
- distanceSquared({ x, y }: Xy): number;
41
- distance_(x: number, y: number): number;
42
- distance({ x, y }: Xy): number;
43
- angleBetween_(x: number, y: number): number;
44
- angleBetween({ x, y }: Xy): number;
45
- /** mutator */
46
- normalize(): this;
47
- /** mutator */
48
- half(): this;
49
- /** mutator */
50
- double(): this;
51
- /** mutator */
52
- abs(): this;
53
- /** mutator */
54
- rotate(radians: number): this;
55
- /** mutator */
56
- perpendicular(): this;
57
- /** mutator */
58
- clampMagnitude(max: number): this;
59
- /** mutator */
60
- floor(): this;
61
- /** mutator */
62
- ceil(): this;
63
- /** mutator */
64
- round(): this;
65
- /** mutator */
66
- map(fn: (a: number, index: number) => number): this;
67
- /** mutator */
68
- clamp(min: number, max: number): this;
69
- /** mutator */
70
- negate(): this;
71
- /** mutator */
72
- addBy(delta: number): this;
73
- /** mutator */
74
- subtractBy(delta: number): this;
75
- /** mutator */
76
- multiplyBy(coefficient: number): this;
77
- /** mutator */
78
- divideBy(divisor: number): this;
79
- /** mutator */
80
- add_(x: number, y: number): this;
81
- /** mutator */
82
- add(...vecs: Xy[]): this;
83
- /** mutator */
84
- subtract_(x: number, y: number): this;
85
- /** mutator */
86
- subtract(...vecs: Xy[]): this;
87
- /** mutator */
88
- multiply_(x: number, y: number): this;
89
- /** mutator */
90
- multiply(...vecs: Xy[]): this;
91
- /** mutator */
92
- divide_(x: number, y: number): this;
93
- /** mutator */
94
- divide(...vecs: Xy[]): this;
95
- /** mutator */
96
- lerp_(x: number, y: number, fraction: number): this;
97
- /** mutator */
98
- lerp({ x, y }: Xy, fraction: number): this;
99
- approach_(x: number, y: number, speed: number, deltaTime: number, speedLimit?: number): this;
100
- approach({ x, y }: Xy, speed: number, deltaTime: number, speedLimit?: number): this;
101
- /** mutator */
102
- reflect_(x: number, y: number): this;
103
- /** mutator */
104
- reflect({ x, y }: Xy): this;
105
- /** mutator */
106
- rotateAroundPoint_(x: number, y: number, radians: number): this;
107
- /** mutator */
108
- rotateAroundPoint({ x, y }: Vec2, radians: number): this;
109
- /** mutator */
110
- smooth_(x: number, y: number, smoothing: number): this;
111
- /** mutator */
112
- smooth({ x, y }: Xy, smoothing: number): this;
113
- }
114
- export {};