@flighthq/spring 0.2.1-next.459.fb59cc5 → 0.2.1-next.585.c7219b8
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/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/spring.d.ts +6 -0
- package/dist/spring.d.ts.map +1 -0
- package/dist/{updateSpring.js → spring.js} +28 -2
- package/dist/spring.js.map +1 -0
- package/dist/spring2D.d.ts.map +1 -1
- package/dist/spring2D.js +1 -3
- package/dist/spring2D.js.map +1 -1
- package/dist/spring3D.d.ts.map +1 -1
- package/dist/spring3D.js +1 -3
- package/dist/spring3D.js.map +1 -1
- package/package.json +3 -3
- package/src/{updateSpring.test.ts → spring.test.ts} +61 -5
- package/dist/createSpring.d.ts +0 -3
- package/dist/createSpring.d.ts.map +0 -1
- package/dist/createSpring.js +0 -7
- package/dist/createSpring.js.map +0 -1
- package/dist/isSpringSettled.d.ts +0 -3
- package/dist/isSpringSettled.d.ts.map +0 -1
- package/dist/isSpringSettled.js +0 -15
- package/dist/isSpringSettled.js.map +0 -1
- package/dist/resetSpring.d.ts +0 -3
- package/dist/resetSpring.d.ts.map +0 -1
- package/dist/resetSpring.js +0 -8
- package/dist/resetSpring.js.map +0 -1
- package/dist/updateSpring.d.ts +0 -3
- package/dist/updateSpring.d.ts.map +0 -1
- package/dist/updateSpring.js.map +0 -1
- package/src/createSpring.test.ts +0 -17
- package/src/isSpringSettled.test.ts +0 -39
- package/src/resetSpring.test.ts +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './isSpringSettled';
|
|
3
|
-
export * from './resetSpring';
|
|
1
|
+
export * from './spring';
|
|
4
2
|
export * from './spring2D';
|
|
5
3
|
export * from './spring3D';
|
|
6
4
|
export * from './springConfig';
|
|
7
|
-
export * from './updateSpring';
|
|
8
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './isSpringSettled';
|
|
3
|
-
export * from './resetSpring';
|
|
1
|
+
export * from './spring';
|
|
4
2
|
export * from './spring2D';
|
|
5
3
|
export * from './spring3D';
|
|
6
4
|
export * from './springConfig';
|
|
7
|
-
export * from './updateSpring';
|
|
8
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
package/dist/spring.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Spring, SpringConfig } from '@flighthq/types';
|
|
2
|
+
export declare function createSpring(value?: number, velocity?: number): Spring;
|
|
3
|
+
export declare function isSpringSettled(spring: Readonly<Spring>, target: number, positionEpsilon?: number, velocityEpsilon?: number): boolean;
|
|
4
|
+
export declare function resetSpring(spring: Spring, value: number, velocity?: number): void;
|
|
5
|
+
export declare function updateSpring(spring: Spring, target: number, config: Readonly<SpringConfig>, deltaTime: number): void;
|
|
6
|
+
//# sourceMappingURL=spring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring.d.ts","sourceRoot":"","sources":["../src/spring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK5D,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAE5E;AASD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,MAA8B,EAC/C,eAAe,GAAE,MAA8B,GAC9C,OAAO,CAET;AASD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,IAAI,CAGrF;AAmBD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CA+DpH"}
|
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
import { TAU } from '@flighthq/math';
|
|
1
|
+
import { approxEqual, approxZero, TAU } from '@flighthq/math';
|
|
2
|
+
// Allocate a scalar spring at `value` (default 0) with `velocity` (default 0). This is the only
|
|
3
|
+
// allocating function for scalar springs; `updateSpring`, `resetSpring`, and the settle query all
|
|
4
|
+
// write into or read an existing spring.
|
|
5
|
+
export function createSpring(value = 0, velocity = 0) {
|
|
6
|
+
return { value, velocity };
|
|
7
|
+
}
|
|
8
|
+
// Report whether `spring` has come to rest at `target`: its `value` is within `positionEpsilon` of
|
|
9
|
+
// the target AND its `velocity` is within `velocityEpsilon` of zero. Both conditions are required —
|
|
10
|
+
// a spring passing through the target at speed (an underdamped overshoot) is not settled.
|
|
11
|
+
//
|
|
12
|
+
// Settle is a property of position and velocity alone, independent of the `SpringConfig` that drove
|
|
13
|
+
// the motion, so no config is taken. Epsilons default to a UI-scale tolerance; pass tighter or
|
|
14
|
+
// looser values for the value's actual units.
|
|
15
|
+
export function isSpringSettled(spring, target, positionEpsilon = SPRING_SETTLE_EPSILON, velocityEpsilon = SPRING_SETTLE_EPSILON) {
|
|
16
|
+
return approxEqual(spring.value, target, positionEpsilon) && approxZero(spring.velocity, velocityEpsilon);
|
|
17
|
+
}
|
|
18
|
+
// Default position/velocity tolerance for settle detection: fine enough that motion has visually
|
|
19
|
+
// stopped for typical pixel/normalized values, loose enough not to wait on floating-point tails.
|
|
20
|
+
const SPRING_SETTLE_EPSILON = 1e-3;
|
|
21
|
+
// Snap `spring` to `value` with `velocity` (default 0), discarding its current motion. Use this to
|
|
22
|
+
// teleport a spring to a new state — e.g. initializing it at a target, or cutting a running spring
|
|
23
|
+
// dead. Unlike `updateSpring`, this applies no dynamics; the spring simply becomes what is passed.
|
|
24
|
+
export function resetSpring(spring, value, velocity = 0) {
|
|
25
|
+
spring.value = value;
|
|
26
|
+
spring.velocity = velocity;
|
|
27
|
+
}
|
|
2
28
|
// Advance `spring` one step of `deltaTime` seconds toward `target` under `config`, writing the new
|
|
3
29
|
// `value` and `velocity` back into `spring`. This is the scalar primitive; `updateSpring2D` and
|
|
4
30
|
// `updateSpring3D` call it once per component. The `target` is per-step, not stored on the spring,
|
|
@@ -78,4 +104,4 @@ export function updateSpring(spring, target, config, deltaTime) {
|
|
|
78
104
|
// over/under-damped closed forms divide by a vanishing root separation, so the critical form is both
|
|
79
105
|
// numerically safer and physically indistinguishable this close to 1.
|
|
80
106
|
const CRITICAL_BAND = 1e-4;
|
|
81
|
-
//# sourceMappingURL=
|
|
107
|
+
//# sourceMappingURL=spring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring.js","sourceRoot":"","sources":["../src/spring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,E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,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;QACtC,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;QAClC,UAAU,GAAG,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;QACnD,UAAU,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,EAAE,GAAG,UAAU,GAAG,QAAQ,CAAC;IAChE,MAAM,CAAC,QAAQ,GAAG,UAAU,GAAG,EAAE,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC5D,CAAC;AAED,4FAA4F;AAC5F,qGAAqG;AACrG,sEAAsE;AACtE,MAAM,aAAa,GAAG,IAAI,CAAC"}
|
package/dist/spring2D.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring2D.d.ts","sourceRoot":"","sources":["../src/spring2D.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"spring2D.d.ts","sourceRoot":"","sources":["../src/spring2D.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM9D,wBAAgB,cAAc,CAC5B,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,EAClB,SAAS,GAAE,MAAU,EACrB,SAAS,GAAE,MAAU,GACpB,QAAQ,CAEV;AAID,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,EACxB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAKT;AAKD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,SAAS,EAAE,MAAM,GAChB,IAAI,CAGN"}
|
package/dist/spring2D.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { createSpring } from './
|
|
2
|
-
import { isSpringSettled } from './isSpringSettled';
|
|
3
|
-
import { updateSpring } from './updateSpring';
|
|
1
|
+
import { createSpring, isSpringSettled, updateSpring } from './spring';
|
|
4
2
|
// Allocate a 2D spring as a pair of scalar springs, each at its `value*` (default 0) and `velocity*`
|
|
5
3
|
// (default 0).
|
|
6
4
|
export function createSpring2D(valueX = 0, valueY = 0, velocityX = 0, velocityY = 0) {
|
package/dist/spring2D.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring2D.js","sourceRoot":"","sources":["../src/spring2D.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"spring2D.js","sourceRoot":"","sources":["../src/spring2D.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvE,qGAAqG;AACrG,eAAe;AACf,MAAM,UAAU,cAAc,CAC5B,SAAiB,CAAC,EAClB,SAAiB,CAAC,EAClB,YAAoB,CAAC,EACrB,YAAoB,CAAC;IAErB,OAAO,EAAE,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;AACpF,CAAC;AAED,oGAAoG;AACpG,gGAAgG;AAChG,MAAM,UAAU,iBAAiB,CAC/B,QAA4B,EAC5B,OAAe,EACf,OAAe,EACf,eAAwB,EACxB,eAAwB;IAExB,OAAO,CACL,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,CAAC;QACtE,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,CAAC,CACvE,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,oGAAoG;AACpG,4CAA4C;AAC5C,MAAM,UAAU,cAAc,CAC5B,QAAkB,EAClB,OAAe,EACf,OAAe,EACf,MAA8B,EAC9B,SAAiB;IAEjB,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/spring3D.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring3D.d.ts","sourceRoot":"","sources":["../src/spring3D.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"spring3D.d.ts","sourceRoot":"","sources":["../src/spring3D.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM9D,wBAAgB,cAAc,CAC5B,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,EAClB,SAAS,GAAE,MAAU,EACrB,SAAS,GAAE,MAAU,EACrB,SAAS,GAAE,MAAU,GACpB,QAAQ,CAMV;AAID,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,EACxB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAMT;AAID,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,SAAS,EAAE,MAAM,GAChB,IAAI,CAIN"}
|
package/dist/spring3D.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { createSpring } from './
|
|
2
|
-
import { isSpringSettled } from './isSpringSettled';
|
|
3
|
-
import { updateSpring } from './updateSpring';
|
|
1
|
+
import { createSpring, isSpringSettled, updateSpring } from './spring';
|
|
4
2
|
// Allocate a 3D spring as three scalar springs, each at its `value*` (default 0) and `velocity*`
|
|
5
3
|
// (default 0).
|
|
6
4
|
export function createSpring3D(valueX = 0, valueY = 0, valueZ = 0, velocityX = 0, velocityY = 0, velocityZ = 0) {
|
package/dist/spring3D.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring3D.js","sourceRoot":"","sources":["../src/spring3D.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"spring3D.js","sourceRoot":"","sources":["../src/spring3D.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvE,iGAAiG;AACjG,eAAe;AACf,MAAM,UAAU,cAAc,CAC5B,SAAiB,CAAC,EAClB,SAAiB,CAAC,EAClB,SAAiB,CAAC,EAClB,YAAoB,CAAC,EACrB,YAAoB,CAAC,EACrB,YAAoB,CAAC;IAErB,OAAO;QACL,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;QAClC,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;QAClC,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;KACnC,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,uEAAuE;AACvE,MAAM,UAAU,iBAAiB,CAC/B,QAA4B,EAC5B,OAAe,EACf,OAAe,EACf,OAAe,EACf,eAAwB,EACxB,eAAwB;IAExB,OAAO,CACL,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,CAAC;QACtE,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,CAAC;QACtE,eAAe,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,CAAC,CACvE,CAAC;AACJ,CAAC;AAED,qGAAqG;AACrG,6EAA6E;AAC7E,MAAM,UAAU,cAAc,CAC5B,QAAkB,EAClB,OAAe,EACf,OAAe,EACf,OAAe,EACf,MAA8B,EAC9B,SAAiB;IAEjB,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/spring",
|
|
3
|
-
"version": "0.2.1-next.
|
|
3
|
+
"version": "0.2.1-next.585.c7219b8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/flighthq/flight.git",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@flighthq/math": "0.2.1-next.
|
|
36
|
-
"@flighthq/types": "0.2.1-next.
|
|
35
|
+
"@flighthq/math": "0.2.1-next.585.c7219b8",
|
|
36
|
+
"@flighthq/types": "0.2.1-next.585.c7219b8"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"typescript": "^5.3.0"
|
|
@@ -1,10 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { createSpring } from './createSpring';
|
|
4
|
-
import { isSpringSettled } from './isSpringSettled';
|
|
1
|
+
import { createSpring, isSpringSettled, resetSpring, updateSpring } from './spring';
|
|
5
2
|
import { createSpringConfig } from './springConfig';
|
|
6
|
-
import { updateSpring } from './updateSpring';
|
|
7
3
|
|
|
4
|
+
describe('createSpring', () => {
|
|
5
|
+
it('defaults value and velocity to 0', () => {
|
|
6
|
+
const spring = createSpring();
|
|
7
|
+
expect(spring.value).toBe(0);
|
|
8
|
+
expect(spring.velocity).toBe(0);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('sets the provided value and velocity', () => {
|
|
12
|
+
const spring = createSpring(5, -2);
|
|
13
|
+
expect(spring.value).toBe(5);
|
|
14
|
+
expect(spring.velocity).toBe(-2);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('isSpringSettled', () => {
|
|
18
|
+
it('is false while the spring is still moving toward the target', () => {
|
|
19
|
+
const spring = createSpring(0);
|
|
20
|
+
const config = createSpringConfig(1, 1);
|
|
21
|
+
updateSpring(spring, 10, config, 1 / 60);
|
|
22
|
+
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('is true once the spring rests at the target', () => {
|
|
26
|
+
const spring = createSpring(0);
|
|
27
|
+
const config = createSpringConfig(4, 1);
|
|
28
|
+
for (let i = 0; i < 600; i++) updateSpring(spring, 10, config, 1 / 60);
|
|
29
|
+
expect(isSpringSettled(spring, 10)).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('is false at the target when velocity is still high (mid overshoot)', () => {
|
|
33
|
+
// At the target position but moving fast is not settled.
|
|
34
|
+
const spring = createSpring(10, 50);
|
|
35
|
+
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('is false when at rest but away from the target', () => {
|
|
39
|
+
const spring = createSpring(3, 0);
|
|
40
|
+
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('honors custom epsilons', () => {
|
|
44
|
+
const spring = createSpring(10.4, 0.4);
|
|
45
|
+
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
46
|
+
expect(isSpringSettled(spring, 10, 0.5, 0.5)).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('resetSpring', () => {
|
|
50
|
+
it('snaps value and velocity, defaulting velocity to 0', () => {
|
|
51
|
+
const spring = createSpring(3, 9);
|
|
52
|
+
resetSpring(spring, 100);
|
|
53
|
+
expect(spring.value).toBe(100);
|
|
54
|
+
expect(spring.velocity).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('sets an explicit velocity', () => {
|
|
58
|
+
const spring = createSpring(0, 0);
|
|
59
|
+
resetSpring(spring, -5, 12);
|
|
60
|
+
expect(spring.value).toBe(-5);
|
|
61
|
+
expect(spring.velocity).toBe(12);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
8
64
|
describe('updateSpring', () => {
|
|
9
65
|
it('converges monotonically to the target with no overshoot when critically damped', () => {
|
|
10
66
|
const spring = createSpring(0);
|
package/dist/createSpring.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createSpring.d.ts","sourceRoot":"","sources":["../src/createSpring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK9C,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAE5E"}
|
package/dist/createSpring.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Allocate a scalar spring at `value` (default 0) with `velocity` (default 0). This is the only
|
|
2
|
-
// allocating function for scalar springs; `updateSpring`, `resetSpring`, and the settle query all
|
|
3
|
-
// write into or read an existing spring.
|
|
4
|
-
export function createSpring(value = 0, velocity = 0) {
|
|
5
|
-
return { value, velocity };
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=createSpring.js.map
|
package/dist/createSpring.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createSpring.js","sourceRoot":"","sources":["../src/createSpring.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,kGAAkG;AAClG,yCAAyC;AACzC,MAAM,UAAU,YAAY,CAAC,QAAgB,CAAC,EAAE,WAAmB,CAAC;IAClE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isSpringSettled.d.ts","sourceRoot":"","sources":["../src/isSpringSettled.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAS9C,wBAAgB,eAAe,CAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,MAA8B,EAC/C,eAAe,GAAE,MAA8B,GAC9C,OAAO,CAET"}
|
package/dist/isSpringSettled.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { approxEqual, approxZero } from '@flighthq/math';
|
|
2
|
-
// Report whether `spring` has come to rest at `target`: its `value` is within `positionEpsilon` of
|
|
3
|
-
// the target AND its `velocity` is within `velocityEpsilon` of zero. Both conditions are required —
|
|
4
|
-
// a spring passing through the target at speed (an underdamped overshoot) is not settled.
|
|
5
|
-
//
|
|
6
|
-
// Settle is a property of position and velocity alone, independent of the `SpringConfig` that drove
|
|
7
|
-
// the motion, so no config is taken. Epsilons default to a UI-scale tolerance; pass tighter or
|
|
8
|
-
// looser values for the value's actual units.
|
|
9
|
-
export function isSpringSettled(spring, target, positionEpsilon = SPRING_SETTLE_EPSILON, velocityEpsilon = SPRING_SETTLE_EPSILON) {
|
|
10
|
-
return approxEqual(spring.value, target, positionEpsilon) && approxZero(spring.velocity, velocityEpsilon);
|
|
11
|
-
}
|
|
12
|
-
// Default position/velocity tolerance for settle detection: fine enough that motion has visually
|
|
13
|
-
// stopped for typical pixel/normalized values, loose enough not to wait on floating-point tails.
|
|
14
|
-
const SPRING_SETTLE_EPSILON = 1e-3;
|
|
15
|
-
//# sourceMappingURL=isSpringSettled.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isSpringSettled.js","sourceRoot":"","sources":["../src/isSpringSettled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGzD,mGAAmG;AACnG,oGAAoG;AACpG,0FAA0F;AAC1F,EAAE;AACF,oGAAoG;AACpG,+FAA+F;AAC/F,8CAA8C;AAC9C,MAAM,UAAU,eAAe,CAC7B,MAAwB,EACxB,MAAc,EACd,kBAA0B,qBAAqB,EAC/C,kBAA0B,qBAAqB;IAE/C,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AAC5G,CAAC;AAED,iGAAiG;AACjG,iGAAiG;AACjG,MAAM,qBAAqB,GAAG,IAAI,CAAC"}
|
package/dist/resetSpring.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resetSpring.d.ts","sourceRoot":"","sources":["../src/resetSpring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK9C,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,IAAI,CAGrF"}
|
package/dist/resetSpring.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Snap `spring` to `value` with `velocity` (default 0), discarding its current motion. Use this to
|
|
2
|
-
// teleport a spring to a new state — e.g. initializing it at a target, or cutting a running spring
|
|
3
|
-
// dead. Unlike `updateSpring`, this applies no dynamics; the spring simply becomes what is passed.
|
|
4
|
-
export function resetSpring(spring, value, velocity = 0) {
|
|
5
|
-
spring.value = value;
|
|
6
|
-
spring.velocity = velocity;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=resetSpring.js.map
|
package/dist/resetSpring.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resetSpring.js","sourceRoot":"","sources":["../src/resetSpring.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,mGAAmG;AACnG,mGAAmG;AACnG,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,KAAa,EAAE,WAAmB,CAAC;IAC7E,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,CAAC"}
|
package/dist/updateSpring.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateSpring.d.ts","sourceRoot":"","sources":["../src/updateSpring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAmB5D,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CA+DpH"}
|
package/dist/updateSpring.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateSpring.js","sourceRoot":"","sources":["../src/updateSpring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBA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IAAI,CAAC;QACvC,+BAA+B;QAC/B,UAAU,GAAG,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,IAAI,CAAC;QACxD,UAAU,GAAG,QAAQ,GAAG,CAAC,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;IAC5D,CAAC;SAAM,CAAC;QACN,iGAAiG;QACjG,gGAAgG;QAChG,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,KAAK,GAAG,SAAS,CAAC;QAElC,UAAU,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;QACtC,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;QAClC,UAAU,GAAG,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;QACnD,UAAU,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,EAAE,GAAG,UAAU,GAAG,QAAQ,CAAC;IAChE,MAAM,CAAC,QAAQ,GAAG,UAAU,GAAG,EAAE,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC5D,CAAC;AAED,4FAA4F;AAC5F,qGAAqG;AACrG,sEAAsE;AACtE,MAAM,aAAa,GAAG,IAAI,CAAC"}
|
package/src/createSpring.test.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createSpring } from './createSpring';
|
|
4
|
-
|
|
5
|
-
describe('createSpring', () => {
|
|
6
|
-
it('defaults value and velocity to 0', () => {
|
|
7
|
-
const spring = createSpring();
|
|
8
|
-
expect(spring.value).toBe(0);
|
|
9
|
-
expect(spring.velocity).toBe(0);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('sets the provided value and velocity', () => {
|
|
13
|
-
const spring = createSpring(5, -2);
|
|
14
|
-
expect(spring.value).toBe(5);
|
|
15
|
-
expect(spring.velocity).toBe(-2);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createSpring } from './createSpring';
|
|
4
|
-
import { isSpringSettled } from './isSpringSettled';
|
|
5
|
-
import { createSpringConfig } from './springConfig';
|
|
6
|
-
import { updateSpring } from './updateSpring';
|
|
7
|
-
|
|
8
|
-
describe('isSpringSettled', () => {
|
|
9
|
-
it('is false while the spring is still moving toward the target', () => {
|
|
10
|
-
const spring = createSpring(0);
|
|
11
|
-
const config = createSpringConfig(1, 1);
|
|
12
|
-
updateSpring(spring, 10, config, 1 / 60);
|
|
13
|
-
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('is true once the spring rests at the target', () => {
|
|
17
|
-
const spring = createSpring(0);
|
|
18
|
-
const config = createSpringConfig(4, 1);
|
|
19
|
-
for (let i = 0; i < 600; i++) updateSpring(spring, 10, config, 1 / 60);
|
|
20
|
-
expect(isSpringSettled(spring, 10)).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('is false at the target when velocity is still high (mid overshoot)', () => {
|
|
24
|
-
// At the target position but moving fast is not settled.
|
|
25
|
-
const spring = createSpring(10, 50);
|
|
26
|
-
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('is false when at rest but away from the target', () => {
|
|
30
|
-
const spring = createSpring(3, 0);
|
|
31
|
-
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('honors custom epsilons', () => {
|
|
35
|
-
const spring = createSpring(10.4, 0.4);
|
|
36
|
-
expect(isSpringSettled(spring, 10)).toBe(false);
|
|
37
|
-
expect(isSpringSettled(spring, 10, 0.5, 0.5)).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
});
|
package/src/resetSpring.test.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createSpring } from './createSpring';
|
|
4
|
-
import { resetSpring } from './resetSpring';
|
|
5
|
-
|
|
6
|
-
describe('resetSpring', () => {
|
|
7
|
-
it('snaps value and velocity, defaulting velocity to 0', () => {
|
|
8
|
-
const spring = createSpring(3, 9);
|
|
9
|
-
resetSpring(spring, 100);
|
|
10
|
-
expect(spring.value).toBe(100);
|
|
11
|
-
expect(spring.velocity).toBe(0);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('sets an explicit velocity', () => {
|
|
15
|
-
const spring = createSpring(0, 0);
|
|
16
|
-
resetSpring(spring, -5, 12);
|
|
17
|
-
expect(spring.value).toBe(-5);
|
|
18
|
-
expect(spring.velocity).toBe(12);
|
|
19
|
-
});
|
|
20
|
-
});
|