math 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +1605 -0
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/dist/color/color.js +136 -0
- package/dist/color/color.js.map +1 -0
- package/dist/color/colorspace.js +43 -0
- package/dist/color/colorspace.js.map +1 -0
- package/dist/color/hsl.js +123 -0
- package/dist/color/hsl.js.map +1 -0
- package/dist/color/index.js +7 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/parse.js +276 -0
- package/dist/color/parse.js.map +1 -0
- package/dist/core/angle.js +43 -0
- package/dist/core/angle.js.map +1 -0
- package/dist/core/euler.js +212 -0
- package/dist/core/euler.js.map +1 -0
- package/dist/core/mat2.js +385 -0
- package/dist/core/mat2.js.map +1 -0
- package/dist/core/mat2d.js +422 -0
- package/dist/core/mat2d.js.map +1 -0
- package/dist/core/mat3.js +749 -0
- package/dist/core/mat3.js.map +1 -0
- package/dist/core/mat4.js +2197 -0
- package/dist/core/mat4.js.map +1 -0
- package/dist/core/polar.js +200 -0
- package/dist/core/polar.js.map +1 -0
- package/dist/core/quat.js +730 -0
- package/dist/core/quat.js.map +1 -0
- package/dist/core/quat2.js +883 -0
- package/dist/core/quat2.js.map +1 -0
- package/dist/core/scalar.js +112 -0
- package/dist/core/scalar.js.map +1 -0
- package/dist/core/spherical.js +248 -0
- package/dist/core/spherical.js.map +1 -0
- package/dist/core/vec2.js +597 -0
- package/dist/core/vec2.js.map +1 -0
- package/dist/core/vec3.js +916 -0
- package/dist/core/vec3.js.map +1 -0
- package/dist/core/vec4.js +573 -0
- package/dist/core/vec4.js.map +1 -0
- package/dist/geometry/circumcircle.js +39 -0
- package/dist/geometry/circumcircle.js.map +1 -0
- package/dist/geometry/index.js +6 -0
- package/dist/geometry/index.js.map +1 -0
- package/dist/geometry/polygon2-decompose.js +411 -0
- package/dist/geometry/polygon2-decompose.js.map +1 -0
- package/dist/geometry/polygon2-triangulate.js +222 -0
- package/dist/geometry/polygon2-triangulate.js.map +1 -0
- package/dist/geometry/quickhull2.js +123 -0
- package/dist/geometry/quickhull2.js.map +1 -0
- package/dist/geometry/quickhull3.js +605 -0
- package/dist/geometry/quickhull3.js.map +1 -0
- package/dist/ik/fabrik2.js +675 -0
- package/dist/ik/fabrik2.js.map +1 -0
- package/dist/ik/fabrik3.js +912 -0
- package/dist/ik/fabrik3.js.map +1 -0
- package/dist/ik/index.js +5 -0
- package/dist/ik/index.js.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/noise/fractal.js +185 -0
- package/dist/noise/fractal.js.map +1 -0
- package/dist/noise/index.js +16 -0
- package/dist/noise/index.js.map +1 -0
- package/dist/noise/perlin2d.js +50 -0
- package/dist/noise/perlin2d.js.map +1 -0
- package/dist/noise/perlin3d.js +72 -0
- package/dist/noise/perlin3d.js.map +1 -0
- package/dist/noise/permutation.js +120 -0
- package/dist/noise/permutation.js.map +1 -0
- package/dist/noise/simplex2d.js +84 -0
- package/dist/noise/simplex2d.js.map +1 -0
- package/dist/noise/simplex3d.js +147 -0
- package/dist/noise/simplex3d.js.map +1 -0
- package/dist/noise/simplex4d.js +149 -0
- package/dist/noise/simplex4d.js.map +1 -0
- package/dist/noise/worley2d.js +50 -0
- package/dist/noise/worley2d.js.map +1 -0
- package/dist/noise/worley3d.js +61 -0
- package/dist/noise/worley3d.js.map +1 -0
- package/dist/random/index.js +9 -0
- package/dist/random/index.js.map +1 -0
- package/dist/random/isaac32.js +164 -0
- package/dist/random/isaac32.js.map +1 -0
- package/dist/random/isaac64.js +215 -0
- package/dist/random/isaac64.js.map +1 -0
- package/dist/random/mulberry32.js +48 -0
- package/dist/random/mulberry32.js.map +1 -0
- package/dist/random/random.js +120 -0
- package/dist/random/random.js.map +1 -0
- package/dist/shapes/box2.js +300 -0
- package/dist/shapes/box2.js.map +1 -0
- package/dist/shapes/box3.js +550 -0
- package/dist/shapes/box3.js.map +1 -0
- package/dist/shapes/circle.js +6 -0
- package/dist/shapes/circle.js.map +1 -0
- package/dist/shapes/frustum.js +662 -0
- package/dist/shapes/frustum.js.map +1 -0
- package/dist/shapes/index.js +25 -0
- package/dist/shapes/index.js.map +1 -0
- package/dist/shapes/obb3.js +557 -0
- package/dist/shapes/obb3.js.map +1 -0
- package/dist/shapes/plane3.js +267 -0
- package/dist/shapes/plane3.js.map +1 -0
- package/dist/shapes/polygon2.js +451 -0
- package/dist/shapes/polygon2.js.map +1 -0
- package/dist/shapes/raycast3.js +164 -0
- package/dist/shapes/raycast3.js.map +1 -0
- package/dist/shapes/segment2.js +82 -0
- package/dist/shapes/segment2.js.map +1 -0
- package/dist/shapes/sphere.js +23 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/triangle2.js +79 -0
- package/dist/shapes/triangle2.js.map +1 -0
- package/dist/shapes/triangle3.js +60 -0
- package/dist/shapes/triangle3.js.map +1 -0
- package/dist/src/color/color.d.ts +50 -0
- package/dist/src/color/colorspace.d.ts +15 -0
- package/dist/src/color/hsl.d.ts +28 -0
- package/dist/src/color/index.d.ts +5 -0
- package/dist/src/color/parse.d.ts +15 -0
- package/dist/src/core/angle.d.ts +29 -0
- package/dist/src/core/arrays.d.ts +4 -0
- package/dist/src/core/euler.d.ts +78 -0
- package/dist/src/core/index.d.ts +27 -0
- package/dist/src/core/mat2.d.ts +217 -0
- package/dist/src/core/mat2d.d.ts +218 -0
- package/dist/src/core/mat3.d.ts +295 -0
- package/dist/src/core/mat4.d.ts +667 -0
- package/dist/src/core/polar.d.ts +151 -0
- package/dist/src/core/quat.d.ts +370 -0
- package/dist/src/core/quat2.d.ts +344 -0
- package/dist/src/core/scalar.d.ts +75 -0
- package/dist/src/core/spherical.d.ts +165 -0
- package/dist/src/core/vec2.d.ts +403 -0
- package/dist/src/core/vec3.d.ts +493 -0
- package/dist/src/core/vec4.d.ts +336 -0
- package/dist/src/geometry/circumcircle.d.ts +9 -0
- package/dist/src/geometry/index.d.ts +5 -0
- package/dist/src/geometry/polygon2-decompose.d.ts +25 -0
- package/dist/src/geometry/polygon2-triangulate.d.ts +15 -0
- package/dist/src/geometry/quickhull2.d.ts +10 -0
- package/dist/src/geometry/quickhull3.d.ts +27 -0
- package/dist/src/ik/fabrik2.d.ts +314 -0
- package/dist/src/ik/fabrik3.d.ts +371 -0
- package/dist/src/ik/index.d.ts +2 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/noise/fractal.d.ts +95 -0
- package/dist/src/noise/index.d.ts +9 -0
- package/dist/src/noise/perlin2d.d.ts +19 -0
- package/dist/src/noise/perlin3d.d.ts +20 -0
- package/dist/src/noise/permutation.d.ts +22 -0
- package/dist/src/noise/simplex2d.d.ts +19 -0
- package/dist/src/noise/simplex3d.d.ts +20 -0
- package/dist/src/noise/simplex4d.d.ts +24 -0
- package/dist/src/noise/worley2d.d.ts +22 -0
- package/dist/src/noise/worley3d.d.ts +23 -0
- package/dist/src/random/index.d.ts +8 -0
- package/dist/src/random/isaac32.d.ts +62 -0
- package/dist/src/random/isaac64.d.ts +75 -0
- package/dist/src/random/mulberry32.d.ts +43 -0
- package/dist/src/random/random.d.ts +67 -0
- package/dist/src/shapes/box2.d.ts +174 -0
- package/dist/src/shapes/box3.d.ts +213 -0
- package/dist/src/shapes/circle.d.ts +7 -0
- package/dist/src/shapes/frustum.d.ts +147 -0
- package/dist/src/shapes/index.d.ts +20 -0
- package/dist/src/shapes/obb3.d.ts +105 -0
- package/dist/src/shapes/plane3.d.ts +130 -0
- package/dist/src/shapes/polygon2.d.ts +155 -0
- package/dist/src/shapes/raycast3.d.ts +42 -0
- package/dist/src/shapes/segment2.d.ts +34 -0
- package/dist/src/shapes/sphere.d.ts +19 -0
- package/dist/src/shapes/triangle2.d.ts +53 -0
- package/dist/src/shapes/triangle3.d.ts +29 -0
- package/dist/src/time/easing.d.ts +21 -0
- package/dist/src/time/index.d.ts +6 -0
- package/dist/src/time/spring-core.d.ts +15 -0
- package/dist/src/time/spring.d.ts +36 -0
- package/dist/src/time/spring2.d.ts +11 -0
- package/dist/src/time/spring3.d.ts +11 -0
- package/dist/src/time/spring4.d.ts +11 -0
- package/dist/time/easing.js +24 -0
- package/dist/time/easing.js.map +1 -0
- package/dist/time/index.js +11 -0
- package/dist/time/index.js.map +1 -0
- package/dist/time/spring-core.js +48 -0
- package/dist/time/spring-core.js.map +1 -0
- package/dist/time/spring.js +62 -0
- package/dist/time/spring.js.map +1 -0
- package/dist/time/spring2.js +31 -0
- package/dist/time/spring2.js.map +1 -0
- package/dist/time/spring3.js +32 -0
- package/dist/time/spring3.js.map +1 -0
- package/dist/time/spring4.js +32 -0
- package/dist/time/spring4.js.map +1 -0
- package/package.json +90 -12
- package/skills/math/SKILL.md +140 -0
- package/math.coffee +0 -36
- package/math.js +0 -67
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Mat4 } from '../core/mat4.js';
|
|
2
|
+
import type { Vec3 } from '../core/vec3.js';
|
|
3
|
+
import type { Sphere } from './sphere.js';
|
|
4
|
+
/**
|
|
5
|
+
* A plane in 3D space
|
|
6
|
+
* normal - a unit length vector defining the normal of the plane.
|
|
7
|
+
* constant - the signed distance from the origin to the plane.
|
|
8
|
+
*/
|
|
9
|
+
export type Plane3 = {
|
|
10
|
+
normal: Vec3;
|
|
11
|
+
constant: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new plane with normal (0, 1, 0) and constant 0
|
|
15
|
+
* @returns A new plane
|
|
16
|
+
*/
|
|
17
|
+
export declare function create(): Plane3;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a plane from a normal and constant
|
|
20
|
+
* @param out - The output plane
|
|
21
|
+
* @param normal - The plane normal (should be unit length)
|
|
22
|
+
* @param constant - The signed distance from origin
|
|
23
|
+
* @returns The output plane
|
|
24
|
+
*/
|
|
25
|
+
export declare function fromNormalAndConstant(out: Plane3, normal: Vec3, constant: number): Plane3;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a plane from a normal and a point on the plane
|
|
28
|
+
* @param out - The output plane
|
|
29
|
+
* @param normal - The plane normal (should be unit length)
|
|
30
|
+
* @param point - A point on the plane
|
|
31
|
+
* @returns The output plane
|
|
32
|
+
*/
|
|
33
|
+
export declare function fromNormalAndPoint(out: Plane3, normal: Vec3, point: Vec3): Plane3;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a plane from three coplanar points
|
|
36
|
+
* @param out - The output plane
|
|
37
|
+
* @param a - First point
|
|
38
|
+
* @param b - Second point
|
|
39
|
+
* @param c - Third point
|
|
40
|
+
* @returns The output plane
|
|
41
|
+
*/
|
|
42
|
+
export declare function fromCoplanarPoints(out: Plane3, a: Vec3, b: Vec3, c: Vec3): Plane3;
|
|
43
|
+
/**
|
|
44
|
+
* Clones a plane
|
|
45
|
+
* @param plane - The plane to clone
|
|
46
|
+
* @returns A new plane
|
|
47
|
+
*/
|
|
48
|
+
export declare function clone(plane: Plane3): Plane3;
|
|
49
|
+
/**
|
|
50
|
+
* Copies one plane to another
|
|
51
|
+
* @param out - The output plane
|
|
52
|
+
* @param plane - The source plane
|
|
53
|
+
* @returns The output plane
|
|
54
|
+
*/
|
|
55
|
+
export declare function copy(out: Plane3, plane: Plane3): Plane3;
|
|
56
|
+
/**
|
|
57
|
+
* Normalizes a plane (ensures the normal vector is unit length)
|
|
58
|
+
* @param out - The output plane
|
|
59
|
+
* @param plane - The input plane
|
|
60
|
+
* @returns The normalized plane
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalize(out: Plane3, plane: Plane3): Plane3;
|
|
63
|
+
/**
|
|
64
|
+
* Negates a plane (flips the normal and constant)
|
|
65
|
+
* @param out - The output plane
|
|
66
|
+
* @param plane - The input plane
|
|
67
|
+
* @returns The negated plane
|
|
68
|
+
*/
|
|
69
|
+
export declare function negate(out: Plane3, plane: Plane3): Plane3;
|
|
70
|
+
/**
|
|
71
|
+
* Offsets a plane by a distance along its normal
|
|
72
|
+
* @param out - The output plane
|
|
73
|
+
* @param plane - The input plane
|
|
74
|
+
* @param distance - The distance to offset (positive = in direction of normal)
|
|
75
|
+
* @returns The offset plane
|
|
76
|
+
*/
|
|
77
|
+
export declare function offset(out: Plane3, plane: Plane3, distance: number): Plane3;
|
|
78
|
+
/**
|
|
79
|
+
* Calculates the signed distance from a point to the plane
|
|
80
|
+
* @param plane - The plane
|
|
81
|
+
* @param point - The point
|
|
82
|
+
* @returns The signed distance (positive = in direction of normal)
|
|
83
|
+
*/
|
|
84
|
+
export declare function distanceToPoint(plane: Plane3, point: Vec3): number;
|
|
85
|
+
/**
|
|
86
|
+
* Projects a point onto the plane
|
|
87
|
+
* @param out - The output point
|
|
88
|
+
* @param plane - The plane
|
|
89
|
+
* @param point - The point to project
|
|
90
|
+
* @returns The projected point
|
|
91
|
+
*/
|
|
92
|
+
export declare function projectPoint(out: Vec3, plane: Plane3, point: Vec3): Vec3;
|
|
93
|
+
/**
|
|
94
|
+
* Transforms a plane by a 4x4 matrix
|
|
95
|
+
* @param out - The output plane
|
|
96
|
+
* @param plane - The plane to transform
|
|
97
|
+
* @param matrix - The transformation matrix
|
|
98
|
+
* @returns The transformed plane
|
|
99
|
+
*/
|
|
100
|
+
export declare function transform(out: Plane3, plane: Plane3, matrix: Mat4): Plane3;
|
|
101
|
+
/**
|
|
102
|
+
* Tests if a sphere intersects the plane
|
|
103
|
+
* @param plane - The plane
|
|
104
|
+
* @param sphere - The sphere
|
|
105
|
+
* @returns True if they intersect
|
|
106
|
+
*/
|
|
107
|
+
export declare function intersectsSphere(plane: Plane3, sphere: Sphere): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Tests if two planes are exactly equal
|
|
110
|
+
* @param a - First plane
|
|
111
|
+
* @param b - Second plane
|
|
112
|
+
* @returns True if planes are exactly equal
|
|
113
|
+
*/
|
|
114
|
+
export declare function exactEquals(a: Plane3, b: Plane3): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Finds the intersection point of three planes
|
|
117
|
+
* @param out - The output point where the three planes intersect
|
|
118
|
+
* @param p1 - First plane
|
|
119
|
+
* @param p2 - Second plane
|
|
120
|
+
* @param p3 - Third plane
|
|
121
|
+
* @returns True if intersection exists, false if planes are degenerate or parallel
|
|
122
|
+
*/
|
|
123
|
+
export declare function intersect(out: Vec3, p1: Plane3, p2: Plane3, p3: Plane3): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Tests if two planes are equal
|
|
126
|
+
* @param a - First plane
|
|
127
|
+
* @param b - Second plane
|
|
128
|
+
* @returns True if planes are equal
|
|
129
|
+
*/
|
|
130
|
+
export declare function equals(a: Plane3, b: Plane3): boolean;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { Vec2 } from '../core/vec2.js';
|
|
2
|
+
import type { Box2 } from './box2.js';
|
|
3
|
+
/**
|
|
4
|
+
* A 2D polygon is represented as a flat array of vertex coordinates laid out as
|
|
5
|
+
* `[x0, y0, x1, y1, ...]`, together with an explicit vertex count `n`.
|
|
6
|
+
*
|
|
7
|
+
* The count is passed separately (rather than derived from `verts.length`) so a
|
|
8
|
+
* single scratch buffer can be reused across polygons of different sizes: only
|
|
9
|
+
* the first `n` vertices are read, and any trailing slots are ignored. Vertices
|
|
10
|
+
* are assumed to be ordered (clockwise or counter-clockwise) around the polygon.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns the signed area of the polygon using the shoelace formula.
|
|
14
|
+
* The result is positive when the vertices wind counter-clockwise and negative
|
|
15
|
+
* when they wind clockwise, so the sign can be used to determine winding order.
|
|
16
|
+
*
|
|
17
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
18
|
+
* @param n number of vertices to read from `vertices`
|
|
19
|
+
* @returns the signed area
|
|
20
|
+
*/
|
|
21
|
+
export declare function signedArea(vertices: number[], n: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the (non-negative) area of the polygon.
|
|
24
|
+
*
|
|
25
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
26
|
+
* @param n number of vertices to read from `vertices`
|
|
27
|
+
* @returns the absolute area
|
|
28
|
+
*/
|
|
29
|
+
export declare function area(vertices: number[], n: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Tests whether a point lies inside the polygon. Works for both convex and
|
|
32
|
+
* concave polygons. Points exactly on an edge or vertex are considered inside.
|
|
33
|
+
*
|
|
34
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
35
|
+
* @param n number of vertices to read from `vertices`
|
|
36
|
+
* @param point the point to test
|
|
37
|
+
* @returns true if the point is inside (or on the boundary of) the polygon
|
|
38
|
+
*/
|
|
39
|
+
export declare function containsPoint(vertices: number[], n: number, point: Vec2): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Computes the area-weighted centroid (center of mass) of the polygon.
|
|
42
|
+
* For a degenerate (zero-area) polygon this falls back to the average of the
|
|
43
|
+
* vertices.
|
|
44
|
+
*
|
|
45
|
+
* @param out the vector to store the centroid
|
|
46
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
47
|
+
* @param n number of vertices to read from `vertices`
|
|
48
|
+
* @returns out
|
|
49
|
+
*/
|
|
50
|
+
export declare function centroid(out: Vec2, vertices: number[], n: number): Vec2;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the perimeter (sum of edge lengths) of the polygon.
|
|
53
|
+
*
|
|
54
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
55
|
+
* @param n number of vertices to read from `vertices`
|
|
56
|
+
* @returns the perimeter
|
|
57
|
+
*/
|
|
58
|
+
export declare function perimeter(vertices: number[], n: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the winding order of the polygon from the sign of its signed area:
|
|
61
|
+
* `1` for counter-clockwise, `-1` for clockwise, and `0` for a degenerate
|
|
62
|
+
* (zero-area) polygon.
|
|
63
|
+
*
|
|
64
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
65
|
+
* @param n number of vertices to read from `vertices`
|
|
66
|
+
* @returns 1 (CCW), -1 (CW), or 0 (degenerate)
|
|
67
|
+
*/
|
|
68
|
+
export declare function winding(vertices: number[], n: number): number;
|
|
69
|
+
/**
|
|
70
|
+
* Tests whether the polygon is convex. Works for both winding orders. Assumes a
|
|
71
|
+
* simple (non-self-intersecting) polygon; collinear vertices are allowed.
|
|
72
|
+
*
|
|
73
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
74
|
+
* @param n number of vertices to read from `vertices`
|
|
75
|
+
* @returns true if the polygon is convex
|
|
76
|
+
*/
|
|
77
|
+
export declare function isConvex(vertices: number[], n: number): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Tests whether vertex `i` is a reflex (concave) vertex of the polygon — the
|
|
80
|
+
* interior angle at that vertex exceeds 180°. Assumes the polygon is wound
|
|
81
|
+
* counter-clockwise and that `0 <= i < n`.
|
|
82
|
+
*
|
|
83
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
84
|
+
* @param n number of vertices to read from `vertices`
|
|
85
|
+
* @param i index of the vertex to test
|
|
86
|
+
* @returns true if vertex `i` is reflex
|
|
87
|
+
*/
|
|
88
|
+
export declare function isReflexVertex(vertices: number[], n: number, i: number): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Reverses the winding order of the polygon, writing the result into `out`.
|
|
91
|
+
* `out` may be the same array as `vertices` to reverse in place.
|
|
92
|
+
*
|
|
93
|
+
* @param out the array to write the reversed polygon into
|
|
94
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
95
|
+
* @param n number of vertices to read from `vertices`
|
|
96
|
+
* @returns out
|
|
97
|
+
*/
|
|
98
|
+
export declare function reverse(out: number[], vertices: number[], n: number): number[];
|
|
99
|
+
/**
|
|
100
|
+
* Writes the axis-aligned bounding box of the polygon into `out` as a Box2
|
|
101
|
+
* `[minX, minY, maxX, maxY]`.
|
|
102
|
+
*
|
|
103
|
+
* @param out the box to store the result
|
|
104
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
105
|
+
* @param n number of vertices to read from `vertices`
|
|
106
|
+
* @returns out
|
|
107
|
+
*/
|
|
108
|
+
export declare function bounds(out: Box2, vertices: number[], n: number): Box2;
|
|
109
|
+
/**
|
|
110
|
+
* Finds the point on the polygon's boundary closest to `point` and writes it to
|
|
111
|
+
* `out`. `point` may lie inside, outside, or on the polygon; the result is
|
|
112
|
+
* always on an edge.
|
|
113
|
+
*
|
|
114
|
+
* @param out the vector to store the closest point
|
|
115
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
116
|
+
* @param n number of vertices to read from `vertices`
|
|
117
|
+
* @param point the query point
|
|
118
|
+
* @returns out
|
|
119
|
+
*/
|
|
120
|
+
export declare function closestPoint(out: Vec2, vertices: number[], n: number, point: Vec2): Vec2;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the distance from `point` to the polygon's boundary, signed so that
|
|
123
|
+
* points inside the polygon get a negative distance and points outside get a
|
|
124
|
+
* positive one.
|
|
125
|
+
*
|
|
126
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
127
|
+
* @param n number of vertices to read from `vertices`
|
|
128
|
+
* @param point the query point
|
|
129
|
+
* @returns the signed distance (negative inside, positive outside)
|
|
130
|
+
*/
|
|
131
|
+
export declare function signedDistance(vertices: number[], n: number, point: Vec2): number;
|
|
132
|
+
/**
|
|
133
|
+
* Tests whether two convex polygons overlap, using the separating axis theorem.
|
|
134
|
+
* Both polygons must be convex; results are undefined for concave input.
|
|
135
|
+
* Polygons that touch along an edge or vertex are considered overlapping.
|
|
136
|
+
*
|
|
137
|
+
* @param verticesA vertices of the first polygon `[x0, y0, x1, y1, ...]`
|
|
138
|
+
* @param numA number of vertices in the first polygon
|
|
139
|
+
* @param verticesB vertices of the second polygon `[x0, y0, x1, y1, ...]`
|
|
140
|
+
* @param numB number of vertices in the second polygon
|
|
141
|
+
* @returns true if the polygons overlap
|
|
142
|
+
*/
|
|
143
|
+
export declare function overlapConvex(verticesA: number[], numA: number, verticesB: number[], numB: number): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Tests whether the segment `a`-`b` intersects the polygon, i.e. it has an
|
|
146
|
+
* endpoint inside the polygon or crosses one of its edges. Works for convex and
|
|
147
|
+
* concave polygons.
|
|
148
|
+
*
|
|
149
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
150
|
+
* @param n number of vertices to read from `vertices`
|
|
151
|
+
* @param a start of the segment
|
|
152
|
+
* @param b end of the segment
|
|
153
|
+
* @returns true if the segment intersects the polygon
|
|
154
|
+
*/
|
|
155
|
+
export declare function intersectsSegment(vertices: number[], n: number, a: Vec2, b: Vec2): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Vec3 } from '../core/vec3.js';
|
|
2
|
+
import type { Box3 } from './box3.js';
|
|
3
|
+
/**
|
|
4
|
+
* Result of a ray-triangle intersection test
|
|
5
|
+
* @see createIntersectsTriangleResult
|
|
6
|
+
* @see intersectsTriangle
|
|
7
|
+
*/
|
|
8
|
+
export type IntersectsTriangleResult = {
|
|
9
|
+
fraction: number;
|
|
10
|
+
hit: boolean;
|
|
11
|
+
frontFacing: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new IntersectsTriangleResult with default values.
|
|
15
|
+
* @returns A new IntersectsTriangleResult.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createIntersectsTriangleResult(): IntersectsTriangleResult;
|
|
18
|
+
/**
|
|
19
|
+
* Ray-triangle intersection test.
|
|
20
|
+
* Based on https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
|
|
21
|
+
*
|
|
22
|
+
* @param out output object to store result (hit boolean, fraction, frontFacing)
|
|
23
|
+
* @param origin ray origin
|
|
24
|
+
* @param direction ray direction
|
|
25
|
+
* @param length ray length
|
|
26
|
+
* @param a first vertex of triangle
|
|
27
|
+
* @param b second vertex of triangle
|
|
28
|
+
* @param c third vertex of triangle
|
|
29
|
+
* @param backfaceCulling if true, backfaces will not be considered hits
|
|
30
|
+
*/
|
|
31
|
+
export declare function intersectsTriangle(out: IntersectsTriangleResult, origin: Vec3, direction: Vec3, length: number, a: Vec3, b: Vec3, c: Vec3, backfaceCulling: boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* Test if a ray intersects an axis-aligned bounding box.
|
|
34
|
+
* Uses slab-based algorithm that handles parallel rays correctly.
|
|
35
|
+
*
|
|
36
|
+
* @param origin ray origin
|
|
37
|
+
* @param direction ray direction
|
|
38
|
+
* @param length ray length
|
|
39
|
+
* @param aabb AABB to test against
|
|
40
|
+
* @returns true if ray intersects the AABB, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
export declare function intersectsBox3(origin: Vec3, direction: Vec3, length: number, aabb: Box3): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Vec2 } from '../core/vec2.js';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the closest point on a line segment to a given point
|
|
4
|
+
* @param out Output parameter for the closest point
|
|
5
|
+
* @param point The point
|
|
6
|
+
* @param a First endpoint of the segment
|
|
7
|
+
* @param b Second endpoint of the segment
|
|
8
|
+
*/
|
|
9
|
+
export declare function closestPoint(out: Vec2, point: Vec2, a: Vec2, b: Vec2): Vec2;
|
|
10
|
+
/**
|
|
11
|
+
* Tests whether the two closed segments a-b and c-d intersect. Collinear
|
|
12
|
+
* (overlapping) segments are treated as non-intersecting; touching at an
|
|
13
|
+
* endpoint counts as an intersection.
|
|
14
|
+
*
|
|
15
|
+
* @param a first endpoint of the first segment
|
|
16
|
+
* @param b second endpoint of the first segment
|
|
17
|
+
* @param c first endpoint of the second segment
|
|
18
|
+
* @param d second endpoint of the second segment
|
|
19
|
+
* @returns true if the segments intersect
|
|
20
|
+
*/
|
|
21
|
+
export declare function intersects(a: Vec2, b: Vec2, c: Vec2, d: Vec2): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Computes the intersection point of the two closed segments a-b and c-d,
|
|
24
|
+
* writing it to `out`. Returns `out` when the segments intersect, or `null`
|
|
25
|
+
* when they do not (including parallel/collinear segments).
|
|
26
|
+
*
|
|
27
|
+
* @param out output parameter for the intersection point
|
|
28
|
+
* @param a first endpoint of the first segment
|
|
29
|
+
* @param b second endpoint of the first segment
|
|
30
|
+
* @param c first endpoint of the second segment
|
|
31
|
+
* @param d second endpoint of the second segment
|
|
32
|
+
* @returns out if the segments intersect, otherwise null
|
|
33
|
+
*/
|
|
34
|
+
export declare function intersection(out: Vec2, a: Vec2, b: Vec2, c: Vec2, d: Vec2): Vec2 | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Vec3 } from '../core/vec3.js';
|
|
2
|
+
/** A sphere in 3D space */
|
|
3
|
+
export type Sphere = {
|
|
4
|
+
center: Vec3;
|
|
5
|
+
radius: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new sphere with a default center 0,0,0 and radius 1
|
|
9
|
+
* @returns A new sphere.
|
|
10
|
+
*/
|
|
11
|
+
export declare function create(): Sphere;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true if a point lies inside (or on the surface of) the sphere.
|
|
14
|
+
*
|
|
15
|
+
* @param sphere the sphere
|
|
16
|
+
* @param point the point to test
|
|
17
|
+
* @returns true if the point is within the sphere's radius
|
|
18
|
+
*/
|
|
19
|
+
export declare function containsPoint(sphere: Sphere, point: Vec3): boolean;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Vec2 } from '../core/vec2.js';
|
|
2
|
+
import type { Box2 } from './box2.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the signed area of the triangle (a, b, c). The result is positive when
|
|
5
|
+
* the vertices wind counter-clockwise, negative when they wind clockwise, and
|
|
6
|
+
* zero when the three points are collinear.
|
|
7
|
+
*
|
|
8
|
+
* @param a the first vertex of the triangle.
|
|
9
|
+
* @param b the second vertex of the triangle.
|
|
10
|
+
* @param c the third vertex of the triangle.
|
|
11
|
+
* @returns the signed area.
|
|
12
|
+
*/
|
|
13
|
+
export declare function signedArea(a: Vec2, b: Vec2, c: Vec2): number;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the (non-negative) area of the triangle (a, b, c).
|
|
16
|
+
*
|
|
17
|
+
* @param a the first vertex of the triangle.
|
|
18
|
+
* @param b the second vertex of the triangle.
|
|
19
|
+
* @param c the third vertex of the triangle.
|
|
20
|
+
* @returns the absolute area.
|
|
21
|
+
*/
|
|
22
|
+
export declare function area(a: Vec2, b: Vec2, c: Vec2): number;
|
|
23
|
+
/**
|
|
24
|
+
* Computes the centroid of the triangle (a, b, c).
|
|
25
|
+
*
|
|
26
|
+
* @param out the output vector to store the result.
|
|
27
|
+
* @param a the first vertex of the triangle.
|
|
28
|
+
* @param b the second vertex of the triangle.
|
|
29
|
+
* @param c the third vertex of the triangle.
|
|
30
|
+
* @returns out.
|
|
31
|
+
*/
|
|
32
|
+
export declare function centroid(out: Vec2, a: Vec2, b: Vec2, c: Vec2): Vec2;
|
|
33
|
+
/**
|
|
34
|
+
* Computes the axis-aligned bounding box of the triangle (a, b, c).
|
|
35
|
+
*
|
|
36
|
+
* @param out the output box to store the result.
|
|
37
|
+
* @param a the first vertex of the triangle.
|
|
38
|
+
* @param b the second vertex of the triangle.
|
|
39
|
+
* @param c the third vertex of the triangle.
|
|
40
|
+
* @returns out.
|
|
41
|
+
*/
|
|
42
|
+
export declare function bounds(out: Box2, a: Vec2, b: Vec2, c: Vec2): Box2;
|
|
43
|
+
/**
|
|
44
|
+
* Tests whether a point lies inside the triangle (a, b, c). Works for either
|
|
45
|
+
* winding order; points on an edge or vertex are considered inside.
|
|
46
|
+
*
|
|
47
|
+
* @param a the first vertex of the triangle.
|
|
48
|
+
* @param b the second vertex of the triangle.
|
|
49
|
+
* @param c the third vertex of the triangle.
|
|
50
|
+
* @param point the point to test.
|
|
51
|
+
* @returns true if the point is inside (or on the boundary of) the triangle.
|
|
52
|
+
*/
|
|
53
|
+
export declare function containsPoint(a: Vec2, b: Vec2, c: Vec2, point: Vec2): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Vec3 } from '../core/vec3.js';
|
|
2
|
+
import type { Box3 } from './box3.js';
|
|
3
|
+
/**
|
|
4
|
+
* Computes the axis-aligned bounding box of a triangle defined by three vertices.
|
|
5
|
+
* @param out the output box to store the result.
|
|
6
|
+
* @param a the first vertex of the triangle.
|
|
7
|
+
* @param b the second vertex of the triangle.
|
|
8
|
+
* @param c the third vertex of the triangle.
|
|
9
|
+
* @returns the output box containing the axis-aligned bounding box of the triangle.
|
|
10
|
+
*/
|
|
11
|
+
export declare function bounds(out: Box3, a: Vec3, b: Vec3, c: Vec3): Box3;
|
|
12
|
+
/**
|
|
13
|
+
* Computes the normal vector of a triangle defined by three vertices.
|
|
14
|
+
* @param out the output vector to store the result.
|
|
15
|
+
* @param a the first vertex of the triangle.
|
|
16
|
+
* @param b the second vertex of the triangle.
|
|
17
|
+
* @param c the third vertex of the triangle.
|
|
18
|
+
* @returns the output vector containing the normal of the triangle.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normal(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3;
|
|
21
|
+
/**
|
|
22
|
+
* Computes the centroid of a triangle defined by three vertices.
|
|
23
|
+
* @param out the output vector to store the result.
|
|
24
|
+
* @param a the first vertex of the triangle.
|
|
25
|
+
* @param b the second vertex of the triangle.
|
|
26
|
+
* @param c the third vertex of the triangle.
|
|
27
|
+
* @returns the output vector containing the centroid of the triangle.
|
|
28
|
+
*/
|
|
29
|
+
export declare function centroid(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const exp: (t: number) => number;
|
|
2
|
+
export declare const linear: (t: number) => number;
|
|
3
|
+
export declare const sineIn: (x: number) => number;
|
|
4
|
+
export declare const sineOut: (x: number) => number;
|
|
5
|
+
export declare const sineInOut: (x: number) => number;
|
|
6
|
+
export declare const cubicIn: (x: number) => number;
|
|
7
|
+
export declare const cubicOut: (x: number) => number;
|
|
8
|
+
export declare const cubicInOut: (x: number) => number;
|
|
9
|
+
export declare const quintIn: (x: number) => number;
|
|
10
|
+
export declare const quintOut: (x: number) => number;
|
|
11
|
+
export declare const quintInOut: (x: number) => number;
|
|
12
|
+
export declare const circIn: (x: number) => number;
|
|
13
|
+
export declare const circOut: (x: number) => number;
|
|
14
|
+
export declare const circInOut: (x: number) => number;
|
|
15
|
+
export declare const quartIn: (t: number) => number;
|
|
16
|
+
export declare const quartOut: (t: number) => number;
|
|
17
|
+
export declare const quartInOut: (t: number) => number;
|
|
18
|
+
export declare const expoIn: (x: number) => number;
|
|
19
|
+
export declare const expoOut: (x: number) => number;
|
|
20
|
+
export declare const expoInOut: (x: number) => number;
|
|
21
|
+
export declare const rsqw: (t: number, delta?: number, a?: number, f?: number) => number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spring state: a `value` and its `velocity`, of matching rank
|
|
3
|
+
* (`number`, `Vec2`, `Vec3`, or `Vec4`). Allocate once, mutate each frame.
|
|
4
|
+
*/
|
|
5
|
+
export type Spring<T> = {
|
|
6
|
+
value: T;
|
|
7
|
+
velocity: T;
|
|
8
|
+
};
|
|
9
|
+
export declare const coef: {
|
|
10
|
+
pp: number;
|
|
11
|
+
pv: number;
|
|
12
|
+
vp: number;
|
|
13
|
+
vv: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function coefficients(smoothTime: number, dampingRatio: number, delta: number): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Spring } from './spring-core.js';
|
|
2
|
+
/** Creates a scalar spring at `value`, at rest. */
|
|
3
|
+
export declare const create: (value?: number) => Spring<number>;
|
|
4
|
+
/**
|
|
5
|
+
* Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
6
|
+
*
|
|
7
|
+
* @param state spring state, mutated in place
|
|
8
|
+
* @param target goal value
|
|
9
|
+
* @param smoothTime approximate time to reach the target; smaller is faster
|
|
10
|
+
* @param dampingRatio 1 = critically damped (no overshoot), <1 bouncy, >1 sluggish
|
|
11
|
+
* @param delta frame delta, for refresh-rate independence
|
|
12
|
+
* @returns state
|
|
13
|
+
*/
|
|
14
|
+
export declare function update(state: Spring<number>, target: number, smoothTime: number, dampingRatio: number, delta: number): Spring<number>;
|
|
15
|
+
/**
|
|
16
|
+
* Critically-damped {@link update} (dampingRatio = 1): moves toward `target` as
|
|
17
|
+
* fast as possible without overshooting.
|
|
18
|
+
*/
|
|
19
|
+
export declare function damp(state: Spring<number>, target: number, smoothTime: number, delta: number): Spring<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Like {@link damp}, but takes the shortest angular path to `target` (radians),
|
|
22
|
+
* wrapping across the ±π seam rather than unwinding the long way around.
|
|
23
|
+
*/
|
|
24
|
+
export declare function dampAngle(state: Spring<number>, target: number, smoothTime: number, delta: number): Spring<number>;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a SwiftUI-style `response` — the spring's natural period, in seconds
|
|
27
|
+
* — to the `smoothTime` that `update`/`damp` consume. `dampingRatio` is the
|
|
28
|
+
* orthogonal second dial and is passed to `update` unchanged.
|
|
29
|
+
*
|
|
30
|
+
* Yields the same stiffness/damping as SwiftUI's `Spring(response:dampingFraction:)`:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* spring3.update(state, target, spring.fromResponse(0.5), 0.3, delta); // bouncy, ~0.5s period
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const fromResponse: (response: number) => number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Vec2 } from '../core/index.js';
|
|
2
|
+
import { type Spring } from './spring-core.js';
|
|
3
|
+
/** Creates a Vec2 spring at `value` (copied), at rest. */
|
|
4
|
+
export declare const create: (value?: Vec2) => Spring<Vec2>;
|
|
5
|
+
/**
|
|
6
|
+
* Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
7
|
+
* @param dampingRatio 1 = critically damped (no overshoot), <1 bouncy, >1 sluggish
|
|
8
|
+
*/
|
|
9
|
+
export declare function update(state: Spring<Vec2>, target: Vec2, smoothTime: number, dampingRatio: number, delta: number): Spring<Vec2>;
|
|
10
|
+
/** Critically-damped Vec2 spring (dampingRatio = 1). See {@link update}. */
|
|
11
|
+
export declare function damp(state: Spring<Vec2>, target: Vec2, smoothTime: number, delta: number): Spring<Vec2>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Vec3 } from '../core/index.js';
|
|
2
|
+
import { type Spring } from './spring-core.js';
|
|
3
|
+
/** Creates a Vec3 spring at `value` (copied), at rest. */
|
|
4
|
+
export declare const create: (value?: Vec3) => Spring<Vec3>;
|
|
5
|
+
/**
|
|
6
|
+
* Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
7
|
+
* @param dampingRatio 1 = critically damped (no overshoot), <1 bouncy, >1 sluggish
|
|
8
|
+
*/
|
|
9
|
+
export declare function update(state: Spring<Vec3>, target: Vec3, smoothTime: number, dampingRatio: number, delta: number): Spring<Vec3>;
|
|
10
|
+
/** Critically-damped Vec3 spring (dampingRatio = 1). See {@link update}. */
|
|
11
|
+
export declare function damp(state: Spring<Vec3>, target: Vec3, smoothTime: number, delta: number): Spring<Vec3>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Vec4 } from '../core/index.js';
|
|
2
|
+
import { type Spring } from './spring-core.js';
|
|
3
|
+
/** Creates a Vec4 spring at `value` (copied), at rest. */
|
|
4
|
+
export declare const create: (value?: Vec4) => Spring<Vec4>;
|
|
5
|
+
/**
|
|
6
|
+
* Springs `state.value` toward `target`, mutating `state` in place. Returns it.
|
|
7
|
+
* @param dampingRatio 1 = critically damped (no overshoot), <1 bouncy, >1 sluggish
|
|
8
|
+
*/
|
|
9
|
+
export declare function update(state: Spring<Vec4>, target: Vec4, smoothTime: number, dampingRatio: number, delta: number): Spring<Vec4>;
|
|
10
|
+
/** Critically-damped Vec4 spring (dampingRatio = 1). See {@link update}. */
|
|
11
|
+
export declare function damp(state: Spring<Vec4>, target: Vec4, smoothTime: number, delta: number): Spring<Vec4>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const exp = (t) => 1 / (1 + t + 0.48 * t * t + 0.235 * t * t * t);
|
|
2
|
+
const linear = (t) => t;
|
|
3
|
+
const sineIn = (x) => 1 - Math.cos((x * Math.PI) / 2);
|
|
4
|
+
const sineOut = (x) => Math.sin((x * Math.PI) / 2);
|
|
5
|
+
const sineInOut = (x) => -(Math.cos(Math.PI * x) - 1) / 2;
|
|
6
|
+
const cubicIn = (x) => x * x * x;
|
|
7
|
+
const cubicOut = (x) => 1 - (1 - x) ** 3;
|
|
8
|
+
const cubicInOut = (x) => (x < 0.5 ? 4 * x * x * x : 1 - (-2 * x + 2) ** 3 / 2);
|
|
9
|
+
const quintIn = (x) => x ** 5;
|
|
10
|
+
const quintOut = (x) => 1 - (1 - x) ** 5;
|
|
11
|
+
const quintInOut = (x) => (x < 0.5 ? 16 * x ** 5 : 1 - (-2 * x + 2) ** 5 / 2);
|
|
12
|
+
const circIn = (x) => 1 - Math.sqrt(1 - x * x);
|
|
13
|
+
const circOut = (x) => Math.sqrt(1 - (x - 1) * (x - 1));
|
|
14
|
+
const circInOut = (x) => x < 0.5 ? (1 - Math.sqrt(1 - 2 * x * (2 * x))) / 2 : (Math.sqrt(1 - (-2 * x + 2) * (-2 * x + 2)) + 1) / 2;
|
|
15
|
+
const quartIn = (t) => t * t * t * t;
|
|
16
|
+
const quartOut = (t) => 1 - --t * t * t * t;
|
|
17
|
+
const quartInOut = (t) => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t);
|
|
18
|
+
const expoIn = (x) => (x === 0 ? 0 : 2 ** (10 * x - 10));
|
|
19
|
+
const expoOut = (x) => (x === 1 ? 1 : 1 - 2 ** (-10 * x));
|
|
20
|
+
const expoInOut = (x) => x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? 2 ** (20 * x - 10) / 2 : (2 - 2 ** (-20 * x + 10)) / 2;
|
|
21
|
+
const rsqw = (t, delta = 0.01, a = 1, f = 1 / (2 * Math.PI)) => (a / Math.atan(1 / delta)) * Math.atan(Math.sin(2 * Math.PI * t * f) / delta);
|
|
22
|
+
|
|
23
|
+
export { circIn, circInOut, circOut, cubicIn, cubicInOut, cubicOut, exp, expoIn, expoInOut, expoOut, linear, quartIn, quartInOut, quartOut, quintIn, quintInOut, quintOut, rsqw, sineIn, sineInOut, sineOut };
|
|
24
|
+
//# sourceMappingURL=easing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easing.js","sources":["../../src/time/easing.ts"],"sourcesContent":["export const exp = (t: number) => 1 / (1 + t + 0.48 * t * t + 0.235 * t * t * t);\n\nexport const linear = (t: number) => t;\n\nexport const sineIn = (x: number) => 1 - Math.cos((x * Math.PI) / 2);\nexport const sineOut = (x: number) => Math.sin((x * Math.PI) / 2);\nexport const sineInOut = (x: number) => -(Math.cos(Math.PI * x) - 1) / 2;\n\nexport const cubicIn = (x: number) => x * x * x;\nexport const cubicOut = (x: number) => 1 - (1 - x) ** 3;\nexport const cubicInOut = (x: number) => (x < 0.5 ? 4 * x * x * x : 1 - (-2 * x + 2) ** 3 / 2);\n\nexport const quintIn = (x: number) => x ** 5;\nexport const quintOut = (x: number) => 1 - (1 - x) ** 5;\nexport const quintInOut = (x: number) => (x < 0.5 ? 16 * x ** 5 : 1 - (-2 * x + 2) ** 5 / 2);\n\nexport const circIn = (x: number) => 1 - Math.sqrt(1 - x * x);\nexport const circOut = (x: number) => Math.sqrt(1 - (x - 1) * (x - 1));\nexport const circInOut = (x: number) =>\n x < 0.5 ? (1 - Math.sqrt(1 - 2 * x * (2 * x))) / 2 : (Math.sqrt(1 - (-2 * x + 2) * (-2 * x + 2)) + 1) / 2;\n\nexport const quartIn = (t: number) => t * t * t * t;\nexport const quartOut = (t: number) => 1 - --t * t * t * t;\nexport const quartInOut = (t: number) => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t);\n\nexport const expoIn = (x: number) => (x === 0 ? 0 : 2 ** (10 * x - 10));\nexport const expoOut = (x: number) => (x === 1 ? 1 : 1 - 2 ** (-10 * x));\nexport const expoInOut = (x: number) =>\n x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? 2 ** (20 * x - 10) / 2 : (2 - 2 ** (-20 * x + 10)) / 2;\n\nexport const rsqw = (t: number, delta = 0.01, a = 1, f = 1 / (2 * Math.PI)) =>\n (a / Math.atan(1 / delta)) * Math.atan(Math.sin(2 * Math.PI * t * f) / delta);\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as easing from './easing.js';
|
|
2
|
+
export { easing };
|
|
3
|
+
import * as spring from './spring.js';
|
|
4
|
+
export { spring };
|
|
5
|
+
import * as spring2 from './spring2.js';
|
|
6
|
+
export { spring2 };
|
|
7
|
+
import * as spring3 from './spring3.js';
|
|
8
|
+
export { spring3 };
|
|
9
|
+
import * as spring4 from './spring4.js';
|
|
10
|
+
export { spring4 };
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|