@pawells/math-extended 1.0.5 → 1.1.1
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.
- package/README.md +5 -5
- package/build/angles.d.ts +33 -3
- package/build/angles.d.ts.map +1 -1
- package/build/angles.js +51 -34
- package/build/angles.js.map +1 -1
- package/build/interpolation.d.ts +378 -63
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +378 -63
- package/build/interpolation.js.map +1 -1
- package/build/matrices/asserts.d.ts +12 -15
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +12 -15
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +11 -12
- package/build/matrices/core.d.ts.map +1 -1
- package/build/matrices/core.js +11 -12
- package/build/matrices/core.js.map +1 -1
- package/build/matrices/decompositions.d.ts +23 -24
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +85 -141
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +6 -1
- package/build/matrices/linear-algebra.d.ts.map +1 -1
- package/build/matrices/linear-algebra.js +54 -19
- package/build/matrices/linear-algebra.js.map +1 -1
- package/build/matrices/transformations.d.ts +9 -12
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +9 -12
- package/build/matrices/transformations.js.map +1 -1
- package/build/quaternions/core.d.ts +6 -2
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +17 -10
- package/build/quaternions/core.js.map +1 -1
- package/build/random.d.ts +5 -2
- package/build/random.d.ts.map +1 -1
- package/build/random.js +20 -17
- package/build/random.js.map +1 -1
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +5 -9
- package/build/vectors/core.js.map +1 -1
- package/package.json +11 -14
package/build/interpolation.js
CHANGED
|
@@ -50,8 +50,18 @@ export function LinearInterpolation(a, b, t) {
|
|
|
50
50
|
return a + ((b - a) * t);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Smooth step interpolation (3t²
|
|
54
|
-
* Provides smooth acceleration and deceleration with zero derivatives at endpoints
|
|
53
|
+
* Smooth step interpolation (3t² − 2t³).
|
|
54
|
+
* Provides smooth acceleration and deceleration with zero first derivatives at both endpoints.
|
|
55
|
+
*
|
|
56
|
+
* @param a - Start value (result when t = 0)
|
|
57
|
+
* @param b - End value (result when t = 1)
|
|
58
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
59
|
+
* @returns Interpolated value using cubic smooth-step curve
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* SmoothStep(0, 10, 0) // 0
|
|
63
|
+
* SmoothStep(0, 10, 1) // 10
|
|
64
|
+
* SmoothStep(0, 10, 0.25) // 1.5625 (slower start than LinearInterpolation's 2.5)
|
|
55
65
|
*/
|
|
56
66
|
export function SmoothStep(a, b, t) {
|
|
57
67
|
// Allow extrapolation by not clamping t
|
|
@@ -59,8 +69,19 @@ export function SmoothStep(a, b, t) {
|
|
|
59
69
|
return a + ((b - a) * smoothT);
|
|
60
70
|
}
|
|
61
71
|
/**
|
|
62
|
-
* Smoother step interpolation (6t⁵
|
|
63
|
-
* Even smoother than SmoothStep with zero first and second derivatives at endpoints
|
|
72
|
+
* Smoother step interpolation (6t⁵ − 15t⁴ + 10t³).
|
|
73
|
+
* Even smoother than SmoothStep with zero first and second derivatives at both endpoints
|
|
74
|
+
* (Ken Perlin's improvement).
|
|
75
|
+
*
|
|
76
|
+
* @param a - Start value (result when t = 0)
|
|
77
|
+
* @param b - End value (result when t = 1)
|
|
78
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
79
|
+
* @returns Interpolated value using quintic smoother-step curve
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* SmootherStep(0, 10, 0) // 0
|
|
83
|
+
* SmootherStep(0, 10, 1) // 10
|
|
84
|
+
* SmootherStep(0, 10, 0.25) // ~1.04 (smoother start than SmoothStep)
|
|
64
85
|
*/
|
|
65
86
|
export function SmootherStep(a, b, t) {
|
|
66
87
|
// Allow extrapolation by not clamping t
|
|
@@ -68,40 +89,90 @@ export function SmootherStep(a, b, t) {
|
|
|
68
89
|
return a + ((b - a) * smoothT);
|
|
69
90
|
}
|
|
70
91
|
/**
|
|
71
|
-
* Quadratic ease-in interpolation (t²)
|
|
72
|
-
* Accelerates slowly
|
|
92
|
+
* Quadratic ease-in interpolation (t²).
|
|
93
|
+
* Accelerates from rest — starts slowly and gains speed toward the end.
|
|
94
|
+
*
|
|
95
|
+
* @param a - Start value (result when t = 0)
|
|
96
|
+
* @param b - End value (result when t = 1)
|
|
97
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
98
|
+
* @returns Interpolated value with quadratic acceleration from start
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* QuadraticEaseIn(0, 10, 0) // 0
|
|
102
|
+
* QuadraticEaseIn(0, 10, 1) // 10
|
|
103
|
+
* QuadraticEaseIn(0, 10, 0.5) // 2.5 (only 25% progress at the midpoint)
|
|
73
104
|
*/
|
|
74
105
|
export function QuadraticEaseIn(a, b, t) {
|
|
75
106
|
// Allow extrapolation by not clamping t
|
|
76
107
|
return a + ((b - a) * t * t);
|
|
77
108
|
}
|
|
78
109
|
/**
|
|
79
|
-
* Quadratic ease-out interpolation (1
|
|
80
|
-
* Decelerates
|
|
110
|
+
* Quadratic ease-out interpolation (1 − (1−t)²).
|
|
111
|
+
* Decelerates to rest — starts quickly and slows toward the end.
|
|
112
|
+
*
|
|
113
|
+
* @param a - Start value (result when t = 0)
|
|
114
|
+
* @param b - End value (result when t = 1)
|
|
115
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
116
|
+
* @returns Interpolated value with quadratic deceleration toward end
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* QuadraticEaseOut(0, 10, 0) // 0
|
|
120
|
+
* QuadraticEaseOut(0, 10, 1) // 10
|
|
121
|
+
* QuadraticEaseOut(0, 10, 0.5) // 7.5 (already 75% progress at the midpoint)
|
|
81
122
|
*/
|
|
82
123
|
export function QuadraticEaseOut(a, b, t) {
|
|
83
124
|
// Allow extrapolation by not clamping t
|
|
84
125
|
return a + ((b - a) * (1 - Math.pow(1 - t, 2)));
|
|
85
126
|
}
|
|
86
127
|
/**
|
|
87
|
-
* Cubic ease-in interpolation (t³)
|
|
88
|
-
* More pronounced acceleration than quadratic
|
|
128
|
+
* Cubic ease-in interpolation (t³).
|
|
129
|
+
* More pronounced acceleration than quadratic — starts very slowly.
|
|
130
|
+
*
|
|
131
|
+
* @param a - Start value (result when t = 0)
|
|
132
|
+
* @param b - End value (result when t = 1)
|
|
133
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
134
|
+
* @returns Interpolated value with cubic acceleration from start
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* CubicEaseIn(0, 10, 0) // 0
|
|
138
|
+
* CubicEaseIn(0, 10, 1) // 10
|
|
139
|
+
* CubicEaseIn(0, 10, 0.5) // 1.25 (only 12.5% progress at the midpoint)
|
|
89
140
|
*/
|
|
90
141
|
export function CubicEaseIn(a, b, t) {
|
|
91
142
|
// Allow extrapolation by not clamping t
|
|
92
143
|
return a + ((b - a) * t * t * t);
|
|
93
144
|
}
|
|
94
145
|
/**
|
|
95
|
-
* Cubic ease-out interpolation (1
|
|
96
|
-
* More pronounced deceleration than quadratic
|
|
146
|
+
* Cubic ease-out interpolation (1 − (1−t)³).
|
|
147
|
+
* More pronounced deceleration than quadratic — slows very gradually at the end.
|
|
148
|
+
*
|
|
149
|
+
* @param a - Start value (result when t = 0)
|
|
150
|
+
* @param b - End value (result when t = 1)
|
|
151
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
152
|
+
* @returns Interpolated value with cubic deceleration toward end
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* CubicEaseOut(0, 10, 0) // 0
|
|
156
|
+
* CubicEaseOut(0, 10, 1) // 10
|
|
157
|
+
* CubicEaseOut(0, 10, 0.5) // 8.75 (already 87.5% progress at the midpoint)
|
|
97
158
|
*/
|
|
98
159
|
export function CubicEaseOut(a, b, t) {
|
|
99
160
|
// Allow extrapolation by not clamping t
|
|
100
161
|
return a + ((b - a) * (1 - Math.pow(1 - t, CUBIC)));
|
|
101
162
|
}
|
|
102
163
|
/**
|
|
103
|
-
* Cosine interpolation
|
|
104
|
-
* Provides natural easing similar to SmoothStep but using trigonometry
|
|
164
|
+
* Cosine interpolation — smooth curve using the cosine function.
|
|
165
|
+
* Provides natural easing similar to SmoothStep but using trigonometry.
|
|
166
|
+
*
|
|
167
|
+
* @param a - Start value (result when t = 0)
|
|
168
|
+
* @param b - End value (result when t = 1)
|
|
169
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
170
|
+
* @returns Interpolated value using cosine-based easing curve
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* CosineInterpolation(0, 10, 0) // 0
|
|
174
|
+
* CosineInterpolation(0, 10, 1) // 10
|
|
175
|
+
* CosineInterpolation(0, 10, 0.5) // 5 (same as LERP at midpoint; smooth near endpoints)
|
|
105
176
|
*/
|
|
106
177
|
export function CosineInterpolation(a, b, t) {
|
|
107
178
|
// Allow extrapolation by not clamping t
|
|
@@ -109,24 +180,54 @@ export function CosineInterpolation(a, b, t) {
|
|
|
109
180
|
return a + ((b - a) * cosT);
|
|
110
181
|
}
|
|
111
182
|
/**
|
|
112
|
-
* Sine ease-in interpolation
|
|
113
|
-
* Slow start with smooth acceleration
|
|
183
|
+
* Sine ease-in interpolation.
|
|
184
|
+
* Slow start with smooth sinusoidal acceleration.
|
|
185
|
+
*
|
|
186
|
+
* @param a - Start value (result when t = 0)
|
|
187
|
+
* @param b - End value (result when t = 1)
|
|
188
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
189
|
+
* @returns Interpolated value with sine-based acceleration from start
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* SineEaseIn(0, 10, 0) // 0
|
|
193
|
+
* SineEaseIn(0, 10, 1) // 10
|
|
194
|
+
* SineEaseIn(0, 10, 0.5) // ~2.93 (slower than LinearInterpolation's 5 at midpoint)
|
|
114
195
|
*/
|
|
115
196
|
export function SineEaseIn(a, b, t) {
|
|
116
197
|
// Allow extrapolation by not clamping t
|
|
117
198
|
return a + ((b - a) * (1 - Math.cos((t * Math.PI) / 2)));
|
|
118
199
|
}
|
|
119
200
|
/**
|
|
120
|
-
* Sine ease-out interpolation
|
|
121
|
-
*
|
|
201
|
+
* Sine ease-out interpolation.
|
|
202
|
+
* Fast start with smooth sinusoidal deceleration to the end.
|
|
203
|
+
*
|
|
204
|
+
* @param a - Start value (result when t = 0)
|
|
205
|
+
* @param b - End value (result when t = 1)
|
|
206
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
207
|
+
* @returns Interpolated value with sine-based deceleration toward end
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* SineEaseOut(0, 10, 0) // 0
|
|
211
|
+
* SineEaseOut(0, 10, 1) // 10
|
|
212
|
+
* SineEaseOut(0, 10, 0.5) // ~7.07 (faster than LinearInterpolation's 5 at midpoint)
|
|
122
213
|
*/
|
|
123
214
|
export function SineEaseOut(a, b, t) {
|
|
124
215
|
// Allow extrapolation by not clamping t
|
|
125
216
|
return a + ((b - a) * Math.sin((t * Math.PI) / 2));
|
|
126
217
|
}
|
|
127
218
|
/**
|
|
128
|
-
* Exponential ease-in interpolation
|
|
129
|
-
* Very slow start, then rapid acceleration
|
|
219
|
+
* Exponential ease-in interpolation (2^(10t−10)).
|
|
220
|
+
* Very slow start, then rapid exponential acceleration.
|
|
221
|
+
*
|
|
222
|
+
* @param a - Start value (result when t = 0)
|
|
223
|
+
* @param b - End value (result when t = 1)
|
|
224
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
225
|
+
* @returns Interpolated value with exponential acceleration from start
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ExponentialEaseIn(0, 10, 0) // 0
|
|
229
|
+
* ExponentialEaseIn(0, 10, 1) // 10
|
|
230
|
+
* ExponentialEaseIn(0, 10, 0.5) // ~0.31 (barely moved at midpoint)
|
|
130
231
|
*/
|
|
131
232
|
export function ExponentialEaseIn(a, b, t) {
|
|
132
233
|
// Allow extrapolation by not clamping t
|
|
@@ -134,8 +235,18 @@ export function ExponentialEaseIn(a, b, t) {
|
|
|
134
235
|
return a + ((b - a) * expT);
|
|
135
236
|
}
|
|
136
237
|
/**
|
|
137
|
-
* Exponential ease-out interpolation
|
|
138
|
-
* Rapid start, then very slow deceleration
|
|
238
|
+
* Exponential ease-out interpolation (1 − 2^(−10t)).
|
|
239
|
+
* Rapid start, then very slow exponential deceleration.
|
|
240
|
+
*
|
|
241
|
+
* @param a - Start value (result when t = 0)
|
|
242
|
+
* @param b - End value (result when t = 1)
|
|
243
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
244
|
+
* @returns Interpolated value with exponential deceleration toward end
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ExponentialEaseOut(0, 10, 0) // 0
|
|
248
|
+
* ExponentialEaseOut(0, 10, 1) // 10
|
|
249
|
+
* ExponentialEaseOut(0, 10, 0.5) // ~9.69 (nearly done at midpoint)
|
|
139
250
|
*/
|
|
140
251
|
export function ExponentialEaseOut(a, b, t) {
|
|
141
252
|
// Allow extrapolation by not clamping t
|
|
@@ -143,8 +254,18 @@ export function ExponentialEaseOut(a, b, t) {
|
|
|
143
254
|
return a + ((b - a) * expT);
|
|
144
255
|
}
|
|
145
256
|
/**
|
|
146
|
-
* Elastic ease-out
|
|
147
|
-
* Creates an overshoot effect that
|
|
257
|
+
* Elastic ease-out — bouncy spring-like motion.
|
|
258
|
+
* Creates an overshoot effect that oscillates before settling at the endpoint.
|
|
259
|
+
*
|
|
260
|
+
* @param a - Start value (result when t = 0)
|
|
261
|
+
* @param b - End value (result when t = 1)
|
|
262
|
+
* @param t - Interpolation parameter — clamped to [0, 1] at t=0 and t=1 boundaries
|
|
263
|
+
* @returns Interpolated value with elastic overshoot effect toward end
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ElasticEaseOut(0, 10, 0) // 0
|
|
267
|
+
* ElasticEaseOut(0, 10, 1) // 10
|
|
268
|
+
* ElasticEaseOut(0, 10, 0.8) // ~10.86 (overshoots target before settling)
|
|
148
269
|
*/
|
|
149
270
|
export function ElasticEaseOut(a, b, t) {
|
|
150
271
|
// Allow extrapolation by not clamping t
|
|
@@ -156,8 +277,18 @@ export function ElasticEaseOut(a, b, t) {
|
|
|
156
277
|
return a + ((b - a) * elasticT);
|
|
157
278
|
}
|
|
158
279
|
/**
|
|
159
|
-
* Back ease-out
|
|
160
|
-
* Creates a slight overshoot before settling
|
|
280
|
+
* Back ease-out — overshoots then settles.
|
|
281
|
+
* Creates a slight overshoot beyond the target before settling into place.
|
|
282
|
+
*
|
|
283
|
+
* @param a - Start value (result when t = 0)
|
|
284
|
+
* @param b - End value (result when t = 1)
|
|
285
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
286
|
+
* @returns Interpolated value with back overshoot effect toward end
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* BackEaseOut(0, 10, 0) // 0
|
|
290
|
+
* BackEaseOut(0, 10, 1) // 10
|
|
291
|
+
* BackEaseOut(0, 10, 0.75) // ~10.88 (overshoots before settling)
|
|
161
292
|
*/
|
|
162
293
|
export function BackEaseOut(a, b, t) {
|
|
163
294
|
// Allow extrapolation by not clamping t
|
|
@@ -167,8 +298,18 @@ export function BackEaseOut(a, b, t) {
|
|
|
167
298
|
return a + ((b - a) * backT);
|
|
168
299
|
}
|
|
169
300
|
/**
|
|
170
|
-
* Bounce ease-out
|
|
171
|
-
*
|
|
301
|
+
* Bounce ease-out — simulates a ball bouncing to rest.
|
|
302
|
+
* Produces a series of bounces with decreasing amplitude before settling at the endpoint.
|
|
303
|
+
*
|
|
304
|
+
* @param a - Start value (result when t = 0)
|
|
305
|
+
* @param b - End value (result when t = 1)
|
|
306
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
307
|
+
* @returns Interpolated value with bouncing effect toward end
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* BounceEaseOut(0, 10, 0) // 0
|
|
311
|
+
* BounceEaseOut(0, 10, 1) // 10
|
|
312
|
+
* BounceEaseOut(0, 10, 0.5) // ~7.65 (mid-bounce)
|
|
172
313
|
*/
|
|
173
314
|
export function BounceEaseOut(a, b, t) {
|
|
174
315
|
// Allow extrapolation by not clamping t
|
|
@@ -193,8 +334,20 @@ export function BounceEaseOut(a, b, t) {
|
|
|
193
334
|
return a + ((b - a) * bounceT);
|
|
194
335
|
}
|
|
195
336
|
/**
|
|
196
|
-
* Catmull-Rom spline interpolation between
|
|
197
|
-
*
|
|
337
|
+
* Catmull-Rom spline interpolation between four control points.
|
|
338
|
+
* Produces a smooth curve that passes through p1 and p2 with tangents influenced by p0 and p3.
|
|
339
|
+
*
|
|
340
|
+
* @param p0 - Previous control point (influences the tangent at p1)
|
|
341
|
+
* @param p1 - Start point (result when t = 0)
|
|
342
|
+
* @param p2 - End point (result when t = 1)
|
|
343
|
+
* @param p3 - Next control point (influences the tangent at p2)
|
|
344
|
+
* @param t - Interpolation parameter (typically [0, 1], supports extrapolation)
|
|
345
|
+
* @returns Smoothly interpolated value along the Catmull-Rom spline
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* CatmullRomInterpolation(0, 5, 10, 15, 0) // 5 (at p1)
|
|
349
|
+
* CatmullRomInterpolation(0, 5, 10, 15, 1) // 10 (at p2)
|
|
350
|
+
* CatmullRomInterpolation(0, 5, 10, 15, 0.5) // 7.5
|
|
198
351
|
*/
|
|
199
352
|
export function CatmullRomInterpolation(p0, p1, p2, p3, t) {
|
|
200
353
|
// Allow extrapolation by not clamping t
|
|
@@ -203,8 +356,20 @@ export function CatmullRomInterpolation(p0, p1, p2, p3, t) {
|
|
|
203
356
|
return CATMULL_HALF * ((2 * p1) + ((-p0 + p2) * t) + (((2 * p0) - (CATMULL_5 * p1) + (QUARTIC * p2) - p3) * t2) + ((-p0 + (CUBIC * p1) - (CUBIC * p2) + p3) * t3));
|
|
204
357
|
}
|
|
205
358
|
/**
|
|
206
|
-
* Hermite interpolation with tangent control
|
|
207
|
-
* Provides precise control over curve
|
|
359
|
+
* Hermite spline interpolation with explicit tangent control.
|
|
360
|
+
* Provides precise control over the curve's tangent at both the start and end points.
|
|
361
|
+
*
|
|
362
|
+
* @param p0 - Start point (result when t = 0)
|
|
363
|
+
* @param p1 - End point (result when t = 1)
|
|
364
|
+
* @param t0 - Tangent (velocity) at the start point
|
|
365
|
+
* @param t1 - Tangent (velocity) at the end point
|
|
366
|
+
* @param t - Interpolation parameter (typically [0, 1], supports extrapolation)
|
|
367
|
+
* @returns Interpolated value along the Hermite spline
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* HermiteInterpolation(0, 10, 0, 0, 0) // 0 (at start)
|
|
371
|
+
* HermiteInterpolation(0, 10, 0, 0, 1) // 10 (at end)
|
|
372
|
+
* HermiteInterpolation(0, 10, 0, 0, 0.5) // 5 (flat tangents → same as LERP at midpoint)
|
|
208
373
|
*/
|
|
209
374
|
export function HermiteInterpolation(p0, p1, t0, t1, t) {
|
|
210
375
|
// Allow extrapolation by not clamping t
|
|
@@ -217,24 +382,55 @@ export function HermiteInterpolation(p0, p1, t0, t1, t) {
|
|
|
217
382
|
return (h00 * p0) + (h10 * t0) + (h01 * p1) + (h11 * t1);
|
|
218
383
|
}
|
|
219
384
|
/**
|
|
220
|
-
* Circular ease-in interpolation
|
|
221
|
-
* Creates an accelerating curve based on quarter circle
|
|
385
|
+
* Circular ease-in interpolation (1 − √(1−t²)).
|
|
386
|
+
* Creates an accelerating curve based on the first quarter of a circle.
|
|
387
|
+
*
|
|
388
|
+
* @param a - Start value (result when t = 0)
|
|
389
|
+
* @param b - End value (result when t = 1)
|
|
390
|
+
* @param t - Interpolation parameter — clamped to [0, 1] for a valid circular arc
|
|
391
|
+
* @returns Interpolated value with circular acceleration from start
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* CircularEaseIn(0, 10, 0) // 0
|
|
395
|
+
* CircularEaseIn(0, 10, 1) // 10
|
|
396
|
+
* CircularEaseIn(0, 10, 0.5) // ~1.34 (very slow start along circular arc)
|
|
222
397
|
*/
|
|
223
398
|
export function CircularEaseIn(a, b, t) {
|
|
224
399
|
// Allow extrapolation by not clamping t
|
|
225
400
|
return a + ((b - a) * (1 - Math.sqrt(1 - (t * t))));
|
|
226
401
|
}
|
|
227
402
|
/**
|
|
228
|
-
* Circular ease-out interpolation
|
|
229
|
-
* Creates a decelerating curve based on quarter circle
|
|
403
|
+
* Circular ease-out interpolation (√(1−(t−1)²)).
|
|
404
|
+
* Creates a decelerating curve based on the first quarter of a circle.
|
|
405
|
+
*
|
|
406
|
+
* @param a - Start value (result when t = 0)
|
|
407
|
+
* @param b - End value (result when t = 1)
|
|
408
|
+
* @param t - Interpolation parameter — clamped to [0, 1] for a valid circular arc
|
|
409
|
+
* @returns Interpolated value with circular deceleration toward end
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* CircularEaseOut(0, 10, 0) // 0
|
|
413
|
+
* CircularEaseOut(0, 10, 1) // 10
|
|
414
|
+
* CircularEaseOut(0, 10, 0.5) // ~8.66 (very fast start along circular arc)
|
|
230
415
|
*/
|
|
231
416
|
export function CircularEaseOut(a, b, t) {
|
|
232
417
|
// Allow extrapolation by not clamping t
|
|
233
418
|
return a + ((b - a) * Math.sqrt(1 - Math.pow(t - 1, 2)));
|
|
234
419
|
}
|
|
235
420
|
/**
|
|
236
|
-
* Quadratic ease-in-out interpolation (2t² for t<0.5, 1−(−2t+2)²/2 for t≥0.5)
|
|
237
|
-
* Symmetrically accelerates at the start and decelerates at the end
|
|
421
|
+
* Quadratic ease-in-out interpolation (2t² for t < 0.5, 1 − (−2t+2)²/2 for t ≥ 0.5).
|
|
422
|
+
* Symmetrically accelerates at the start and decelerates at the end.
|
|
423
|
+
*
|
|
424
|
+
* @param a - Start value (result when t = 0)
|
|
425
|
+
* @param b - End value (result when t = 1)
|
|
426
|
+
* @param t - Interpolation parameter (typically [0, 1])
|
|
427
|
+
* @returns Interpolated value with quadratic symmetric easing
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* QuadraticEaseInOut(0, 10, 0) // 0
|
|
431
|
+
* QuadraticEaseInOut(0, 10, 1) // 10
|
|
432
|
+
* QuadraticEaseInOut(0, 10, 0.25) // 1.25 (slow start)
|
|
433
|
+
* QuadraticEaseInOut(0, 10, 0.75) // 8.75 (slow end)
|
|
238
434
|
*/
|
|
239
435
|
export function QuadraticEaseInOut(a, b, t) {
|
|
240
436
|
const smoothT = t < EASE_INOUT_HALF
|
|
@@ -243,8 +439,19 @@ export function QuadraticEaseInOut(a, b, t) {
|
|
|
243
439
|
return a + ((b - a) * smoothT);
|
|
244
440
|
}
|
|
245
441
|
/**
|
|
246
|
-
* Cubic ease-in-out interpolation (4t³ for t<0.5, 1−(−2t+2)³/2 for t≥0.5)
|
|
247
|
-
* More pronounced symmetrical acceleration/deceleration than quadratic
|
|
442
|
+
* Cubic ease-in-out interpolation (4t³ for t < 0.5, 1 − (−2t+2)³/2 for t ≥ 0.5).
|
|
443
|
+
* More pronounced symmetrical acceleration/deceleration than quadratic ease-in-out.
|
|
444
|
+
*
|
|
445
|
+
* @param a - Start value (result when t = 0)
|
|
446
|
+
* @param b - End value (result when t = 1)
|
|
447
|
+
* @param t - Interpolation parameter (typically [0, 1])
|
|
448
|
+
* @returns Interpolated value with cubic symmetric easing
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* CubicEaseInOut(0, 10, 0) // 0
|
|
452
|
+
* CubicEaseInOut(0, 10, 1) // 10
|
|
453
|
+
* CubicEaseInOut(0, 10, 0.25) // 0.625 (very slow start)
|
|
454
|
+
* CubicEaseInOut(0, 10, 0.75) // 9.375 (very slow end)
|
|
248
455
|
*/
|
|
249
456
|
export function CubicEaseInOut(a, b, t) {
|
|
250
457
|
const smoothT = t < EASE_INOUT_HALF
|
|
@@ -253,16 +460,36 @@ export function CubicEaseInOut(a, b, t) {
|
|
|
253
460
|
return a + ((b - a) * smoothT);
|
|
254
461
|
}
|
|
255
462
|
/**
|
|
256
|
-
* Sine ease-in-out interpolation (−(cos(πt)−1)/2)
|
|
257
|
-
* Smooth symmetric easing using cosine — gentle and natural feeling
|
|
463
|
+
* Sine ease-in-out interpolation (−(cos(πt) − 1) / 2).
|
|
464
|
+
* Smooth symmetric easing using cosine — gentle and natural feeling.
|
|
465
|
+
*
|
|
466
|
+
* @param a - Start value (result when t = 0)
|
|
467
|
+
* @param b - End value (result when t = 1)
|
|
468
|
+
* @param t - Interpolation parameter (typically [0, 1])
|
|
469
|
+
* @returns Interpolated value with sine-based symmetric easing
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* SineEaseInOut(0, 10, 0) // 0
|
|
473
|
+
* SineEaseInOut(0, 10, 1) // 10
|
|
474
|
+
* SineEaseInOut(0, 10, 0.5) // 5 (symmetric midpoint)
|
|
258
475
|
*/
|
|
259
476
|
export function SineEaseInOut(a, b, t) {
|
|
260
477
|
const smoothT = -(Math.cos(t * Math.PI) - 1) / 2;
|
|
261
478
|
return a + ((b - a) * smoothT);
|
|
262
479
|
}
|
|
263
480
|
/**
|
|
264
|
-
* Exponential ease-in-out interpolation
|
|
265
|
-
* Very slow at both ends
|
|
481
|
+
* Exponential ease-in-out interpolation.
|
|
482
|
+
* Very slow at both ends with an extremely rapid transition in the middle.
|
|
483
|
+
*
|
|
484
|
+
* @param a - Start value (result when t = 0)
|
|
485
|
+
* @param b - End value (result when t = 1)
|
|
486
|
+
* @param t - Interpolation parameter (typically [0, 1])
|
|
487
|
+
* @returns Interpolated value with exponential symmetric easing
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ExponentialEaseInOut(0, 10, 0) // 0
|
|
491
|
+
* ExponentialEaseInOut(0, 10, 1) // 10
|
|
492
|
+
* ExponentialEaseInOut(0, 10, 0.25) // ~0.16 (barely moving in the first quarter)
|
|
266
493
|
*/
|
|
267
494
|
export function ExponentialEaseInOut(a, b, t) {
|
|
268
495
|
if (t === 0)
|
|
@@ -275,8 +502,18 @@ export function ExponentialEaseInOut(a, b, t) {
|
|
|
275
502
|
return a + ((b - a) * expT);
|
|
276
503
|
}
|
|
277
504
|
/**
|
|
278
|
-
* Circular ease-in-out interpolation
|
|
279
|
-
* Smooth symmetric arc-based easing
|
|
505
|
+
* Circular ease-in-out interpolation.
|
|
506
|
+
* Smooth symmetric arc-based easing using a circular curve.
|
|
507
|
+
*
|
|
508
|
+
* @param a - Start value (result when t = 0)
|
|
509
|
+
* @param b - End value (result when t = 1)
|
|
510
|
+
* @param t - Interpolation parameter (typically [0, 1])
|
|
511
|
+
* @returns Interpolated value with circular symmetric easing
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* CircularEaseInOut(0, 10, 0) // 0
|
|
515
|
+
* CircularEaseInOut(0, 10, 1) // 10
|
|
516
|
+
* CircularEaseInOut(0, 10, 0.25) // ~0.67 (very slow circular start)
|
|
280
517
|
*/
|
|
281
518
|
export function CircularEaseInOut(a, b, t) {
|
|
282
519
|
const smoothT = t < EASE_INOUT_HALF
|
|
@@ -285,8 +522,18 @@ export function CircularEaseInOut(a, b, t) {
|
|
|
285
522
|
return a + ((b - a) * smoothT);
|
|
286
523
|
}
|
|
287
524
|
/**
|
|
288
|
-
* Elastic ease-in interpolation
|
|
289
|
-
* Spring-like acceleration from rest — starts with a
|
|
525
|
+
* Elastic ease-in interpolation.
|
|
526
|
+
* Spring-like acceleration from rest — starts with a backward oscillation then launches forward.
|
|
527
|
+
*
|
|
528
|
+
* @param a - Start value (result when t = 0)
|
|
529
|
+
* @param b - End value (result when t = 1)
|
|
530
|
+
* @param t - Interpolation parameter — clamped to [0, 1] at t=0 and t=1 boundaries
|
|
531
|
+
* @returns Interpolated value with elastic spring acceleration from start
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ElasticEaseIn(0, 10, 0) // 0
|
|
535
|
+
* ElasticEaseIn(0, 10, 1) // 10
|
|
536
|
+
* ElasticEaseIn(0, 10, 0.5) // ~-0.16 (backward oscillation at midpoint before launching)
|
|
290
537
|
*/
|
|
291
538
|
export function ElasticEaseIn(a, b, t) {
|
|
292
539
|
if (t === 0 || t === 1)
|
|
@@ -296,8 +543,18 @@ export function ElasticEaseIn(a, b, t) {
|
|
|
296
543
|
return a + ((b - a) * elasticT);
|
|
297
544
|
}
|
|
298
545
|
/**
|
|
299
|
-
* Elastic ease-in-out interpolation
|
|
300
|
-
* Spring-like oscillation at both the start and end
|
|
546
|
+
* Elastic ease-in-out interpolation.
|
|
547
|
+
* Spring-like oscillation at both the start and end of the motion.
|
|
548
|
+
*
|
|
549
|
+
* @param a - Start value (result when t = 0)
|
|
550
|
+
* @param b - End value (result when t = 1)
|
|
551
|
+
* @param t - Interpolation parameter — clamped to [0, 1] at t=0 and t=1 boundaries
|
|
552
|
+
* @returns Interpolated value with elastic oscillation at both ends
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ElasticEaseInOut(0, 10, 0) // 0
|
|
556
|
+
* ElasticEaseInOut(0, 10, 1) // 10
|
|
557
|
+
* ElasticEaseInOut(0, 10, 0.4) // ~-1.17 (backward oscillation before midpoint)
|
|
301
558
|
*/
|
|
302
559
|
export function ElasticEaseInOut(a, b, t) {
|
|
303
560
|
if (t === 0 || t === 1)
|
|
@@ -309,8 +566,18 @@ export function ElasticEaseInOut(a, b, t) {
|
|
|
309
566
|
return a + ((b - a) * elasticT);
|
|
310
567
|
}
|
|
311
568
|
/**
|
|
312
|
-
* Back ease-in interpolation (c3t³ − c1t²)
|
|
313
|
-
* Slight backward pull before launching forward
|
|
569
|
+
* Back ease-in interpolation (c3t³ − c1t²).
|
|
570
|
+
* Slight backward pull before launching forward — like winding up before a throw.
|
|
571
|
+
*
|
|
572
|
+
* @param a - Start value (result when t = 0)
|
|
573
|
+
* @param b - End value (result when t = 1)
|
|
574
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
575
|
+
* @returns Interpolated value with back overshoot at start
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* BackEaseIn(0, 10, 0) // 0
|
|
579
|
+
* BackEaseIn(0, 10, 1) // 10
|
|
580
|
+
* BackEaseIn(0, 10, 0.25) // ~-0.64 (dips below start before accelerating forward)
|
|
314
581
|
*/
|
|
315
582
|
export function BackEaseIn(a, b, t) {
|
|
316
583
|
const c1 = 1.70158;
|
|
@@ -319,8 +586,18 @@ export function BackEaseIn(a, b, t) {
|
|
|
319
586
|
return a + ((b - a) * backT);
|
|
320
587
|
}
|
|
321
588
|
/**
|
|
322
|
-
* Back ease-in-out interpolation
|
|
323
|
-
* Slight backward pull at both ends before and after the main motion
|
|
589
|
+
* Back ease-in-out interpolation.
|
|
590
|
+
* Slight backward pull at both ends before and after the main forward motion.
|
|
591
|
+
*
|
|
592
|
+
* @param a - Start value (result when t = 0)
|
|
593
|
+
* @param b - End value (result when t = 1)
|
|
594
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
595
|
+
* @returns Interpolated value with back overshoot at both start and end
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* BackEaseInOut(0, 10, 0) // 0
|
|
599
|
+
* BackEaseInOut(0, 10, 1) // 10
|
|
600
|
+
* BackEaseInOut(0, 10, 0.25) // ~-1.00 (dips backward at start)
|
|
324
601
|
*/
|
|
325
602
|
export function BackEaseInOut(a, b, t) {
|
|
326
603
|
const c1 = 1.70158;
|
|
@@ -331,15 +608,35 @@ export function BackEaseInOut(a, b, t) {
|
|
|
331
608
|
return a + ((b - a) * backT);
|
|
332
609
|
}
|
|
333
610
|
/**
|
|
334
|
-
* Bounce ease-in interpolation
|
|
335
|
-
* Bouncing ball effect
|
|
611
|
+
* Bounce ease-in interpolation.
|
|
612
|
+
* Bouncing ball effect at the start — multiple bounces before launching toward the target.
|
|
613
|
+
*
|
|
614
|
+
* @param a - Start value (result when t = 0)
|
|
615
|
+
* @param b - End value (result when t = 1)
|
|
616
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
617
|
+
* @returns Interpolated value with bounce effect at start
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* BounceEaseIn(0, 10, 0) // 0
|
|
621
|
+
* BounceEaseIn(0, 10, 1) // 10
|
|
622
|
+
* BounceEaseIn(0, 10, 0.5) // ~2.34 (still bouncing at midpoint)
|
|
336
623
|
*/
|
|
337
624
|
export function BounceEaseIn(a, b, t) {
|
|
338
625
|
return a + ((b - a) * (1 - BounceEaseOut(0, 1, 1 - t)));
|
|
339
626
|
}
|
|
340
627
|
/**
|
|
341
|
-
* Bounce ease-in-out interpolation
|
|
342
|
-
* Bouncing ball effect at both the start and the
|
|
628
|
+
* Bounce ease-in-out interpolation.
|
|
629
|
+
* Bouncing ball effect at both the start and end of the motion.
|
|
630
|
+
*
|
|
631
|
+
* @param a - Start value (result when t = 0)
|
|
632
|
+
* @param b - End value (result when t = 1)
|
|
633
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
634
|
+
* @returns Interpolated value with bounce effect at both start and end
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* BounceEaseInOut(0, 10, 0) // 0
|
|
638
|
+
* BounceEaseInOut(0, 10, 1) // 10
|
|
639
|
+
* BounceEaseInOut(0, 10, 0.25) // ~1.17 (bouncing at start quarter)
|
|
343
640
|
*/
|
|
344
641
|
export function BounceEaseInOut(a, b, t) {
|
|
345
642
|
const bounceT = t < EASE_INOUT_HALF
|
|
@@ -348,8 +645,20 @@ export function BounceEaseInOut(a, b, t) {
|
|
|
348
645
|
return a + ((b - a) * bounceT);
|
|
349
646
|
}
|
|
350
647
|
/**
|
|
351
|
-
* Step interpolation
|
|
352
|
-
*
|
|
648
|
+
* Step interpolation — instant transition at a configurable threshold.
|
|
649
|
+
* Returns `a` when `t` is below the threshold, and `b` at or above it.
|
|
650
|
+
* Useful for discrete state changes and on/off animations.
|
|
651
|
+
*
|
|
652
|
+
* @param a - Start value (returned when t < threshold)
|
|
653
|
+
* @param b - End value (returned when t ≥ threshold)
|
|
654
|
+
* @param t - Interpolation parameter (clamped to [0, 1])
|
|
655
|
+
* @param threshold - Normalized transition point (default: 0.5; clamped to [0, 1])
|
|
656
|
+
* @returns Either `a` or `b` depending on `t` relative to `threshold`
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* StepInterpolation(0, 10, 0.3) // 0 (below default threshold of 0.5)
|
|
660
|
+
* StepInterpolation(0, 10, 0.7) // 10 (at or above default threshold of 0.5)
|
|
661
|
+
* StepInterpolation(0, 10, 0.3, 0.25) // 10 (above custom threshold of 0.25)
|
|
353
662
|
*/
|
|
354
663
|
export function StepInterpolation(a, b, t, threshold = 0.5) {
|
|
355
664
|
const clampedT = Clamp(t, 0, 1);
|
|
@@ -357,9 +666,15 @@ export function StepInterpolation(a, b, t, threshold = 0.5) {
|
|
|
357
666
|
return clampedT < clampedThreshold ? a : b;
|
|
358
667
|
}
|
|
359
668
|
/**
|
|
360
|
-
* Spherical linear interpolation for scalar values
|
|
361
|
-
*
|
|
362
|
-
*
|
|
669
|
+
* Spherical linear interpolation for scalar values.
|
|
670
|
+
* For scalar inputs, this is mathematically equivalent to {@link LinearInterpolation}.
|
|
671
|
+
* For true spherical rotation interpolation, use `QuaternionSLERP` from the quaternions module.
|
|
672
|
+
*
|
|
673
|
+
* @param a - Start value (result when t = 0)
|
|
674
|
+
* @param b - End value (result when t = 1)
|
|
675
|
+
* @param t - Interpolation parameter — unclamped, allowing extrapolation
|
|
676
|
+
* @returns Linearly interpolated value (identical to `LinearInterpolation(a, b, t)`)
|
|
677
|
+
*
|
|
363
678
|
* @deprecated This function is identical to LinearInterpolation and is not a true spherical interpolation. For quaternion spherical interpolation, use QuaternionSLERP from the quaternions module.
|
|
364
679
|
*/
|
|
365
680
|
export function SphericalLinearInterpolation(a, b, t) {
|