@pawells/math-extended 1.0.4 → 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 +57 -35
- 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 +380 -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 +10 -2
- package/build/random.d.ts.map +1 -1
- package/build/random.js +25 -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
|
@@ -3,6 +3,8 @@ import { Clamp } from './clamp.js';
|
|
|
3
3
|
const CUBIC = 3; // t³ power used in cubic ease, smooth step, etc.
|
|
4
4
|
const QUARTIC = 4; // t⁴ power used in smoother step / catmull-rom
|
|
5
5
|
const QUINTIC = 5; // t⁵ power used in smoother step
|
|
6
|
+
// Perlin's smootherstep formula coefficients: 6t⁵ − 15t⁴ + 10t³
|
|
7
|
+
// These create a smooth curve with zero first and second derivatives at endpoints
|
|
6
8
|
const SMOOTHER_COEFF_A = 6; // 6t⁵ coefficient in SmootherStep
|
|
7
9
|
const SMOOTHER_COEFF_B = 15; // 15t⁴ coefficient in SmootherStep
|
|
8
10
|
const SMOOTHER_COEFF_C = 10; // 10t³ coefficient in SmootherStep
|
|
@@ -48,8 +50,18 @@ export function LinearInterpolation(a, b, t) {
|
|
|
48
50
|
return a + ((b - a) * t);
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
|
-
* Smooth step interpolation (3t²
|
|
52
|
-
* 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)
|
|
53
65
|
*/
|
|
54
66
|
export function SmoothStep(a, b, t) {
|
|
55
67
|
// Allow extrapolation by not clamping t
|
|
@@ -57,8 +69,19 @@ export function SmoothStep(a, b, t) {
|
|
|
57
69
|
return a + ((b - a) * smoothT);
|
|
58
70
|
}
|
|
59
71
|
/**
|
|
60
|
-
* Smoother step interpolation (6t⁵
|
|
61
|
-
* 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)
|
|
62
85
|
*/
|
|
63
86
|
export function SmootherStep(a, b, t) {
|
|
64
87
|
// Allow extrapolation by not clamping t
|
|
@@ -66,40 +89,90 @@ export function SmootherStep(a, b, t) {
|
|
|
66
89
|
return a + ((b - a) * smoothT);
|
|
67
90
|
}
|
|
68
91
|
/**
|
|
69
|
-
* Quadratic ease-in interpolation (t²)
|
|
70
|
-
* 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)
|
|
71
104
|
*/
|
|
72
105
|
export function QuadraticEaseIn(a, b, t) {
|
|
73
106
|
// Allow extrapolation by not clamping t
|
|
74
107
|
return a + ((b - a) * t * t);
|
|
75
108
|
}
|
|
76
109
|
/**
|
|
77
|
-
* Quadratic ease-out interpolation (1
|
|
78
|
-
* 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)
|
|
79
122
|
*/
|
|
80
123
|
export function QuadraticEaseOut(a, b, t) {
|
|
81
124
|
// Allow extrapolation by not clamping t
|
|
82
125
|
return a + ((b - a) * (1 - Math.pow(1 - t, 2)));
|
|
83
126
|
}
|
|
84
127
|
/**
|
|
85
|
-
* Cubic ease-in interpolation (t³)
|
|
86
|
-
* 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)
|
|
87
140
|
*/
|
|
88
141
|
export function CubicEaseIn(a, b, t) {
|
|
89
142
|
// Allow extrapolation by not clamping t
|
|
90
143
|
return a + ((b - a) * t * t * t);
|
|
91
144
|
}
|
|
92
145
|
/**
|
|
93
|
-
* Cubic ease-out interpolation (1
|
|
94
|
-
* 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)
|
|
95
158
|
*/
|
|
96
159
|
export function CubicEaseOut(a, b, t) {
|
|
97
160
|
// Allow extrapolation by not clamping t
|
|
98
161
|
return a + ((b - a) * (1 - Math.pow(1 - t, CUBIC)));
|
|
99
162
|
}
|
|
100
163
|
/**
|
|
101
|
-
* Cosine interpolation
|
|
102
|
-
* 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)
|
|
103
176
|
*/
|
|
104
177
|
export function CosineInterpolation(a, b, t) {
|
|
105
178
|
// Allow extrapolation by not clamping t
|
|
@@ -107,24 +180,54 @@ export function CosineInterpolation(a, b, t) {
|
|
|
107
180
|
return a + ((b - a) * cosT);
|
|
108
181
|
}
|
|
109
182
|
/**
|
|
110
|
-
* Sine ease-in interpolation
|
|
111
|
-
* 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)
|
|
112
195
|
*/
|
|
113
196
|
export function SineEaseIn(a, b, t) {
|
|
114
197
|
// Allow extrapolation by not clamping t
|
|
115
198
|
return a + ((b - a) * (1 - Math.cos((t * Math.PI) / 2)));
|
|
116
199
|
}
|
|
117
200
|
/**
|
|
118
|
-
* Sine ease-out interpolation
|
|
119
|
-
*
|
|
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)
|
|
120
213
|
*/
|
|
121
214
|
export function SineEaseOut(a, b, t) {
|
|
122
215
|
// Allow extrapolation by not clamping t
|
|
123
216
|
return a + ((b - a) * Math.sin((t * Math.PI) / 2));
|
|
124
217
|
}
|
|
125
218
|
/**
|
|
126
|
-
* Exponential ease-in interpolation
|
|
127
|
-
* 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)
|
|
128
231
|
*/
|
|
129
232
|
export function ExponentialEaseIn(a, b, t) {
|
|
130
233
|
// Allow extrapolation by not clamping t
|
|
@@ -132,8 +235,18 @@ export function ExponentialEaseIn(a, b, t) {
|
|
|
132
235
|
return a + ((b - a) * expT);
|
|
133
236
|
}
|
|
134
237
|
/**
|
|
135
|
-
* Exponential ease-out interpolation
|
|
136
|
-
* 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)
|
|
137
250
|
*/
|
|
138
251
|
export function ExponentialEaseOut(a, b, t) {
|
|
139
252
|
// Allow extrapolation by not clamping t
|
|
@@ -141,8 +254,18 @@ export function ExponentialEaseOut(a, b, t) {
|
|
|
141
254
|
return a + ((b - a) * expT);
|
|
142
255
|
}
|
|
143
256
|
/**
|
|
144
|
-
* Elastic ease-out
|
|
145
|
-
* 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)
|
|
146
269
|
*/
|
|
147
270
|
export function ElasticEaseOut(a, b, t) {
|
|
148
271
|
// Allow extrapolation by not clamping t
|
|
@@ -154,8 +277,18 @@ export function ElasticEaseOut(a, b, t) {
|
|
|
154
277
|
return a + ((b - a) * elasticT);
|
|
155
278
|
}
|
|
156
279
|
/**
|
|
157
|
-
* Back ease-out
|
|
158
|
-
* 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)
|
|
159
292
|
*/
|
|
160
293
|
export function BackEaseOut(a, b, t) {
|
|
161
294
|
// Allow extrapolation by not clamping t
|
|
@@ -165,8 +298,18 @@ export function BackEaseOut(a, b, t) {
|
|
|
165
298
|
return a + ((b - a) * backT);
|
|
166
299
|
}
|
|
167
300
|
/**
|
|
168
|
-
* Bounce ease-out
|
|
169
|
-
*
|
|
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)
|
|
170
313
|
*/
|
|
171
314
|
export function BounceEaseOut(a, b, t) {
|
|
172
315
|
// Allow extrapolation by not clamping t
|
|
@@ -191,8 +334,20 @@ export function BounceEaseOut(a, b, t) {
|
|
|
191
334
|
return a + ((b - a) * bounceT);
|
|
192
335
|
}
|
|
193
336
|
/**
|
|
194
|
-
* Catmull-Rom spline interpolation between
|
|
195
|
-
*
|
|
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
|
|
196
351
|
*/
|
|
197
352
|
export function CatmullRomInterpolation(p0, p1, p2, p3, t) {
|
|
198
353
|
// Allow extrapolation by not clamping t
|
|
@@ -201,8 +356,20 @@ export function CatmullRomInterpolation(p0, p1, p2, p3, t) {
|
|
|
201
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));
|
|
202
357
|
}
|
|
203
358
|
/**
|
|
204
|
-
* Hermite interpolation with tangent control
|
|
205
|
-
* 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)
|
|
206
373
|
*/
|
|
207
374
|
export function HermiteInterpolation(p0, p1, t0, t1, t) {
|
|
208
375
|
// Allow extrapolation by not clamping t
|
|
@@ -215,24 +382,55 @@ export function HermiteInterpolation(p0, p1, t0, t1, t) {
|
|
|
215
382
|
return (h00 * p0) + (h10 * t0) + (h01 * p1) + (h11 * t1);
|
|
216
383
|
}
|
|
217
384
|
/**
|
|
218
|
-
* Circular ease-in interpolation
|
|
219
|
-
* 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)
|
|
220
397
|
*/
|
|
221
398
|
export function CircularEaseIn(a, b, t) {
|
|
222
399
|
// Allow extrapolation by not clamping t
|
|
223
400
|
return a + ((b - a) * (1 - Math.sqrt(1 - (t * t))));
|
|
224
401
|
}
|
|
225
402
|
/**
|
|
226
|
-
* Circular ease-out interpolation
|
|
227
|
-
* 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)
|
|
228
415
|
*/
|
|
229
416
|
export function CircularEaseOut(a, b, t) {
|
|
230
417
|
// Allow extrapolation by not clamping t
|
|
231
418
|
return a + ((b - a) * Math.sqrt(1 - Math.pow(t - 1, 2)));
|
|
232
419
|
}
|
|
233
420
|
/**
|
|
234
|
-
* Quadratic ease-in-out interpolation (2t² for t<0.5, 1−(−2t+2)²/2 for t≥0.5)
|
|
235
|
-
* 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)
|
|
236
434
|
*/
|
|
237
435
|
export function QuadraticEaseInOut(a, b, t) {
|
|
238
436
|
const smoothT = t < EASE_INOUT_HALF
|
|
@@ -241,8 +439,19 @@ export function QuadraticEaseInOut(a, b, t) {
|
|
|
241
439
|
return a + ((b - a) * smoothT);
|
|
242
440
|
}
|
|
243
441
|
/**
|
|
244
|
-
* Cubic ease-in-out interpolation (4t³ for t<0.5, 1−(−2t+2)³/2 for t≥0.5)
|
|
245
|
-
* 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)
|
|
246
455
|
*/
|
|
247
456
|
export function CubicEaseInOut(a, b, t) {
|
|
248
457
|
const smoothT = t < EASE_INOUT_HALF
|
|
@@ -251,16 +460,36 @@ export function CubicEaseInOut(a, b, t) {
|
|
|
251
460
|
return a + ((b - a) * smoothT);
|
|
252
461
|
}
|
|
253
462
|
/**
|
|
254
|
-
* Sine ease-in-out interpolation (−(cos(πt)−1)/2)
|
|
255
|
-
* 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)
|
|
256
475
|
*/
|
|
257
476
|
export function SineEaseInOut(a, b, t) {
|
|
258
477
|
const smoothT = -(Math.cos(t * Math.PI) - 1) / 2;
|
|
259
478
|
return a + ((b - a) * smoothT);
|
|
260
479
|
}
|
|
261
480
|
/**
|
|
262
|
-
* Exponential ease-in-out interpolation
|
|
263
|
-
* 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)
|
|
264
493
|
*/
|
|
265
494
|
export function ExponentialEaseInOut(a, b, t) {
|
|
266
495
|
if (t === 0)
|
|
@@ -273,8 +502,18 @@ export function ExponentialEaseInOut(a, b, t) {
|
|
|
273
502
|
return a + ((b - a) * expT);
|
|
274
503
|
}
|
|
275
504
|
/**
|
|
276
|
-
* Circular ease-in-out interpolation
|
|
277
|
-
* 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)
|
|
278
517
|
*/
|
|
279
518
|
export function CircularEaseInOut(a, b, t) {
|
|
280
519
|
const smoothT = t < EASE_INOUT_HALF
|
|
@@ -283,8 +522,18 @@ export function CircularEaseInOut(a, b, t) {
|
|
|
283
522
|
return a + ((b - a) * smoothT);
|
|
284
523
|
}
|
|
285
524
|
/**
|
|
286
|
-
* Elastic ease-in interpolation
|
|
287
|
-
* 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)
|
|
288
537
|
*/
|
|
289
538
|
export function ElasticEaseIn(a, b, t) {
|
|
290
539
|
if (t === 0 || t === 1)
|
|
@@ -294,8 +543,18 @@ export function ElasticEaseIn(a, b, t) {
|
|
|
294
543
|
return a + ((b - a) * elasticT);
|
|
295
544
|
}
|
|
296
545
|
/**
|
|
297
|
-
* Elastic ease-in-out interpolation
|
|
298
|
-
* 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)
|
|
299
558
|
*/
|
|
300
559
|
export function ElasticEaseInOut(a, b, t) {
|
|
301
560
|
if (t === 0 || t === 1)
|
|
@@ -307,8 +566,18 @@ export function ElasticEaseInOut(a, b, t) {
|
|
|
307
566
|
return a + ((b - a) * elasticT);
|
|
308
567
|
}
|
|
309
568
|
/**
|
|
310
|
-
* Back ease-in interpolation (c3t³ − c1t²)
|
|
311
|
-
* 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)
|
|
312
581
|
*/
|
|
313
582
|
export function BackEaseIn(a, b, t) {
|
|
314
583
|
const c1 = 1.70158;
|
|
@@ -317,8 +586,18 @@ export function BackEaseIn(a, b, t) {
|
|
|
317
586
|
return a + ((b - a) * backT);
|
|
318
587
|
}
|
|
319
588
|
/**
|
|
320
|
-
* Back ease-in-out interpolation
|
|
321
|
-
* 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)
|
|
322
601
|
*/
|
|
323
602
|
export function BackEaseInOut(a, b, t) {
|
|
324
603
|
const c1 = 1.70158;
|
|
@@ -329,15 +608,35 @@ export function BackEaseInOut(a, b, t) {
|
|
|
329
608
|
return a + ((b - a) * backT);
|
|
330
609
|
}
|
|
331
610
|
/**
|
|
332
|
-
* Bounce ease-in interpolation
|
|
333
|
-
* 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)
|
|
334
623
|
*/
|
|
335
624
|
export function BounceEaseIn(a, b, t) {
|
|
336
625
|
return a + ((b - a) * (1 - BounceEaseOut(0, 1, 1 - t)));
|
|
337
626
|
}
|
|
338
627
|
/**
|
|
339
|
-
* Bounce ease-in-out interpolation
|
|
340
|
-
* 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)
|
|
341
640
|
*/
|
|
342
641
|
export function BounceEaseInOut(a, b, t) {
|
|
343
642
|
const bounceT = t < EASE_INOUT_HALF
|
|
@@ -346,8 +645,20 @@ export function BounceEaseInOut(a, b, t) {
|
|
|
346
645
|
return a + ((b - a) * bounceT);
|
|
347
646
|
}
|
|
348
647
|
/**
|
|
349
|
-
* Step interpolation
|
|
350
|
-
*
|
|
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)
|
|
351
662
|
*/
|
|
352
663
|
export function StepInterpolation(a, b, t, threshold = 0.5) {
|
|
353
664
|
const clampedT = Clamp(t, 0, 1);
|
|
@@ -355,9 +666,15 @@ export function StepInterpolation(a, b, t, threshold = 0.5) {
|
|
|
355
666
|
return clampedT < clampedThreshold ? a : b;
|
|
356
667
|
}
|
|
357
668
|
/**
|
|
358
|
-
* Spherical linear interpolation for scalar values
|
|
359
|
-
*
|
|
360
|
-
*
|
|
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
|
+
*
|
|
361
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.
|
|
362
679
|
*/
|
|
363
680
|
export function SphericalLinearInterpolation(a, b, t) {
|