math 0.0.3 → 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 -16
- package/skills/math/SKILL.md +140 -0
- package/AUTHORS +0 -1
- package/Cakefile +0 -28
- package/math.coffee +0 -112
- package/math.js +0 -141
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import type { MutableArrayLike } from './arrays.js';
|
|
2
|
+
import type { Mat4 } from './mat4.js';
|
|
3
|
+
import type { Quat } from './quat.js';
|
|
4
|
+
/** A 4D vector */
|
|
5
|
+
export type Vec4 = [x: number, y: number, z: number, w: number];
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new, empty vec4
|
|
8
|
+
*
|
|
9
|
+
* @returns a new 4D vector
|
|
10
|
+
*/
|
|
11
|
+
export declare function create(): Vec4;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new vec4 initialized with values from an existing vector
|
|
14
|
+
*
|
|
15
|
+
* @param a vector to clone
|
|
16
|
+
* @returns a new 4D vector
|
|
17
|
+
*/
|
|
18
|
+
export declare function clone(a: Vec4): Vec4;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new vec4 initialized with the given values
|
|
21
|
+
*
|
|
22
|
+
* @param x X component
|
|
23
|
+
* @param y Y component
|
|
24
|
+
* @param z Z component
|
|
25
|
+
* @param w W component
|
|
26
|
+
* @returns a new 4D vector
|
|
27
|
+
*/
|
|
28
|
+
export declare function fromValues(x: number, y: number, z: number, w: number): Vec4;
|
|
29
|
+
/**
|
|
30
|
+
* Copy the values from one vec4 to another
|
|
31
|
+
*
|
|
32
|
+
* @param out the receiving vector
|
|
33
|
+
* @param a the source vector
|
|
34
|
+
* @returns out
|
|
35
|
+
*/
|
|
36
|
+
export declare function copy(out: Vec4, a: Vec4): Vec4;
|
|
37
|
+
/**
|
|
38
|
+
* Set the components of a vec4 to the given values
|
|
39
|
+
*
|
|
40
|
+
* @param out the receiving vector
|
|
41
|
+
* @param x X component
|
|
42
|
+
* @param y Y component
|
|
43
|
+
* @param z Z component
|
|
44
|
+
* @param w W component
|
|
45
|
+
* @returns out
|
|
46
|
+
*/
|
|
47
|
+
export declare function set(out: Vec4, x: number, y: number, z: number, w: number): Vec4;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the components of a vec4 from a buffer
|
|
50
|
+
* @param out the receiving vector
|
|
51
|
+
* @param buffer the source buffer
|
|
52
|
+
* @param startIndex the starting index in the buffer
|
|
53
|
+
* @returns out
|
|
54
|
+
*/
|
|
55
|
+
export declare function fromBuffer(out: Vec4, buffer: ArrayLike<number>, startIndex: number): Vec4;
|
|
56
|
+
/**
|
|
57
|
+
* Writes the components of a vec4 to a buffer
|
|
58
|
+
* @param outBuffer The output buffer
|
|
59
|
+
* @param vec The source vector
|
|
60
|
+
* @param startIndex The starting index in the buffer
|
|
61
|
+
* @returns The output buffer
|
|
62
|
+
*/
|
|
63
|
+
export declare function toBuffer(outBuffer: MutableArrayLike<number>, vec: Vec4, startIndex: number): MutableArrayLike<number>;
|
|
64
|
+
/**
|
|
65
|
+
* Adds two vec4's
|
|
66
|
+
*
|
|
67
|
+
* @param out the receiving vector
|
|
68
|
+
* @param a the first operand
|
|
69
|
+
* @param b the second operand
|
|
70
|
+
* @returns out
|
|
71
|
+
*/
|
|
72
|
+
export declare function add(out: Vec4, a: Vec4, b: Vec4): Vec4;
|
|
73
|
+
/**
|
|
74
|
+
* Subtracts vector b from vector a
|
|
75
|
+
*
|
|
76
|
+
* @param out the receiving vector
|
|
77
|
+
* @param a the first operand
|
|
78
|
+
* @param b the second operand
|
|
79
|
+
* @returns out
|
|
80
|
+
*/
|
|
81
|
+
export declare function subtract(out: Vec4, a: Vec4, b: Vec4): Vec4;
|
|
82
|
+
/**
|
|
83
|
+
* Multiplies two vec4's
|
|
84
|
+
*
|
|
85
|
+
* @param out the receiving vector
|
|
86
|
+
* @param a the first operand
|
|
87
|
+
* @param b the second operand
|
|
88
|
+
* @returns out
|
|
89
|
+
*/
|
|
90
|
+
export declare function multiply(out: Vec4, a: Vec4, b: Vec4): Vec4;
|
|
91
|
+
/**
|
|
92
|
+
* Divides two vec4's
|
|
93
|
+
*
|
|
94
|
+
* @param out the receiving vector
|
|
95
|
+
* @param a the first operand
|
|
96
|
+
* @param b the second operand
|
|
97
|
+
* @returns out
|
|
98
|
+
*/
|
|
99
|
+
export declare function divide(out: Vec4, a: Vec4, b: Vec4): Vec4;
|
|
100
|
+
/**
|
|
101
|
+
* Math.ceil the components of a vec4
|
|
102
|
+
*
|
|
103
|
+
* @param out the receiving vector
|
|
104
|
+
* @param a vector to ceil
|
|
105
|
+
* @returns out
|
|
106
|
+
*/
|
|
107
|
+
export declare function ceil(out: Vec4, a: Vec4): Vec4;
|
|
108
|
+
/**
|
|
109
|
+
* Math.floor the components of a vec4
|
|
110
|
+
*
|
|
111
|
+
* @param out the receiving vector
|
|
112
|
+
* @param a vector to floor
|
|
113
|
+
* @returns out
|
|
114
|
+
*/
|
|
115
|
+
export declare function floor(out: Vec4, a: Vec4): Vec4;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the minimum of two vec4's
|
|
118
|
+
*
|
|
119
|
+
* @param out the receiving vector
|
|
120
|
+
* @param a the first operand
|
|
121
|
+
* @param b the second operand
|
|
122
|
+
* @returns out
|
|
123
|
+
*/
|
|
124
|
+
export declare function min(out: Vec4, a: Vec4, b: Vec4): Vec4;
|
|
125
|
+
/**
|
|
126
|
+
* Returns the maximum of two vec4's
|
|
127
|
+
*
|
|
128
|
+
* @param out the receiving vector
|
|
129
|
+
* @param a the first operand
|
|
130
|
+
* @param b the second operand
|
|
131
|
+
* @returns out
|
|
132
|
+
*/
|
|
133
|
+
export declare function max(out: Vec4, a: Vec4, b: Vec4): Vec4;
|
|
134
|
+
/**
|
|
135
|
+
* symmetric round the components of a vec4
|
|
136
|
+
*
|
|
137
|
+
* @param out the receiving vector
|
|
138
|
+
* @param a vector to round
|
|
139
|
+
* @returns out
|
|
140
|
+
*/
|
|
141
|
+
export declare function round(out: Vec4, a: Vec4): Vec4;
|
|
142
|
+
/**
|
|
143
|
+
* Scales a vec4 by a scalar number
|
|
144
|
+
*
|
|
145
|
+
* @param out the receiving vector
|
|
146
|
+
* @param a the vector to scale
|
|
147
|
+
* @param b amount to scale the vector by
|
|
148
|
+
* @returns out
|
|
149
|
+
*/
|
|
150
|
+
export declare function scale(out: Vec4, a: Vec4, b: number): Vec4;
|
|
151
|
+
/**
|
|
152
|
+
* Adds two vec4's after scaling the second operand by a scalar value
|
|
153
|
+
*
|
|
154
|
+
* @param out the receiving vector
|
|
155
|
+
* @param a the first operand
|
|
156
|
+
* @param b the second operand
|
|
157
|
+
* @param scale the amount to scale b by before adding
|
|
158
|
+
* @returns out
|
|
159
|
+
*/
|
|
160
|
+
export declare function scaleAndAdd(out: Vec4, a: Vec4, b: Vec4, scale: number): Vec4;
|
|
161
|
+
/**
|
|
162
|
+
* Calculates the euclidian distance between two vec4's
|
|
163
|
+
*
|
|
164
|
+
* @param a the first operand
|
|
165
|
+
* @param b the second operand
|
|
166
|
+
* @returns distance between a and b
|
|
167
|
+
*/
|
|
168
|
+
export declare function distance(a: Vec4, b: Vec4): number;
|
|
169
|
+
/**
|
|
170
|
+
* Calculates the squared euclidian distance between two vec4's
|
|
171
|
+
*
|
|
172
|
+
* @param a the first operand
|
|
173
|
+
* @param b the second operand
|
|
174
|
+
* @returns squared distance between a and b
|
|
175
|
+
*/
|
|
176
|
+
export declare function squaredDistance(a: Vec4, b: Vec4): number;
|
|
177
|
+
/**
|
|
178
|
+
* Calculates the length of a vec4
|
|
179
|
+
*
|
|
180
|
+
* @param a vector to calculate length of
|
|
181
|
+
* @returns length of a
|
|
182
|
+
*/
|
|
183
|
+
export declare function length(a: Vec4): number;
|
|
184
|
+
/**
|
|
185
|
+
* Calculates the squared length of a vec4
|
|
186
|
+
*
|
|
187
|
+
* @param a vector to calculate squared length of
|
|
188
|
+
* @returns squared length of a
|
|
189
|
+
*/
|
|
190
|
+
export declare function squaredLength(a: Vec4): number;
|
|
191
|
+
/**
|
|
192
|
+
* Negates the components of a vec4
|
|
193
|
+
*
|
|
194
|
+
* @param out the receiving vector
|
|
195
|
+
* @param a vector to negate
|
|
196
|
+
* @returns out
|
|
197
|
+
*/
|
|
198
|
+
export declare function negate(out: Vec4, a: Vec4): Vec4;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the inverse of the components of a vec4
|
|
201
|
+
*
|
|
202
|
+
* @param out the receiving vector
|
|
203
|
+
* @param a vector to invert
|
|
204
|
+
* @returns out
|
|
205
|
+
*/
|
|
206
|
+
export declare function inverse(out: Vec4, a: Vec4): Vec4;
|
|
207
|
+
/**
|
|
208
|
+
* Normalize a vec4
|
|
209
|
+
*
|
|
210
|
+
* @param out the receiving vector
|
|
211
|
+
* @param a vector to normalize
|
|
212
|
+
* @returns out
|
|
213
|
+
*/
|
|
214
|
+
export declare function normalize(out: Vec4, a: Vec4): Vec4;
|
|
215
|
+
/**
|
|
216
|
+
* Calculates the dot product of two vec4's
|
|
217
|
+
*
|
|
218
|
+
* @param a the first operand
|
|
219
|
+
* @param b the second operand
|
|
220
|
+
* @returns dot product of a and b
|
|
221
|
+
*/
|
|
222
|
+
export declare function dot(a: Vec4, b: Vec4): number;
|
|
223
|
+
/**
|
|
224
|
+
* Returns the cross-product of three vectors in a 4-dimensional space
|
|
225
|
+
*
|
|
226
|
+
* @param out the receiving vector
|
|
227
|
+
* @param u the first vector
|
|
228
|
+
* @param v the second vector
|
|
229
|
+
* @param w the third vector
|
|
230
|
+
* @returns result
|
|
231
|
+
*/
|
|
232
|
+
export declare function cross(out: Vec4, u: Vec4, v: Vec4, w: Vec4): Vec4;
|
|
233
|
+
/**
|
|
234
|
+
* Performs a linear interpolation between two vec4's
|
|
235
|
+
*
|
|
236
|
+
* @param out the receiving vector
|
|
237
|
+
* @param a the first operand
|
|
238
|
+
* @param b the second operand
|
|
239
|
+
* @param t interpolation amount, in the range [0-1], between the two inputs
|
|
240
|
+
* @returns out
|
|
241
|
+
*/
|
|
242
|
+
export declare function lerp(out: Vec4, a: Vec4, b: Vec4, t: number): Vec4;
|
|
243
|
+
/**
|
|
244
|
+
* Quadratic interpolation through three vectors using Lagrange interpolation.
|
|
245
|
+
* Passes through a at t=0, b at t=0.5, and c at t=1.
|
|
246
|
+
*
|
|
247
|
+
* @param out the receiving vector
|
|
248
|
+
* @param a vector at t=0
|
|
249
|
+
* @param b vector at t=0.5
|
|
250
|
+
* @param c vector at t=1
|
|
251
|
+
* @param t interpolation amount
|
|
252
|
+
* @returns out
|
|
253
|
+
*/
|
|
254
|
+
export declare function lagrange(out: Vec4, a: Vec4, b: Vec4, c: Vec4, t: number): Vec4;
|
|
255
|
+
/**
|
|
256
|
+
* Transforms the vec4 with a mat4.
|
|
257
|
+
*
|
|
258
|
+
* @param out the receiving vector
|
|
259
|
+
* @param a the vector to transform
|
|
260
|
+
* @param m matrix to transform with
|
|
261
|
+
* @returns out
|
|
262
|
+
*/
|
|
263
|
+
export declare function transformMat4(out: Vec4, a: Vec4, m: Mat4): Vec4;
|
|
264
|
+
/**
|
|
265
|
+
* Transforms the vec4 with a quat
|
|
266
|
+
*
|
|
267
|
+
* @param out the receiving vector
|
|
268
|
+
* @param a the vector to transform
|
|
269
|
+
* @param q quaternion to transform with
|
|
270
|
+
* @returns out
|
|
271
|
+
*/
|
|
272
|
+
export declare function transformQuat(out: Vec4, a: Vec4, q: Quat): Vec4;
|
|
273
|
+
/**
|
|
274
|
+
* Set the components of a vec4 to zero
|
|
275
|
+
*
|
|
276
|
+
* @param out the receiving vector
|
|
277
|
+
* @returns out
|
|
278
|
+
*/
|
|
279
|
+
export declare function zero(out: Vec4): Vec4;
|
|
280
|
+
/**
|
|
281
|
+
* Returns a string representation of a vector
|
|
282
|
+
*
|
|
283
|
+
* @param a vector to represent as a string
|
|
284
|
+
* @returns string representation of the vector
|
|
285
|
+
*/
|
|
286
|
+
export declare function str(a: Vec4): string;
|
|
287
|
+
/**
|
|
288
|
+
* Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
|
|
289
|
+
*
|
|
290
|
+
* @param a The first vector.
|
|
291
|
+
* @param b The second vector.
|
|
292
|
+
* @returns True if the vectors are equal, false otherwise.
|
|
293
|
+
*/
|
|
294
|
+
export declare function exactEquals(a: Vec4, b: Vec4): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Returns whether or not the vectors have approximately the same elements in the same position.
|
|
297
|
+
*
|
|
298
|
+
* @param a The first vector.
|
|
299
|
+
* @param b The second vector.
|
|
300
|
+
* @returns True if the vectors are equal, false otherwise.
|
|
301
|
+
*/
|
|
302
|
+
export declare function equals(a: Vec4, b: Vec4): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Returns whether or not the vector is finite
|
|
305
|
+
* @param a vector to test
|
|
306
|
+
* @returns whether or not the vector is finite
|
|
307
|
+
*/
|
|
308
|
+
export declare function finite(a: Vec4): boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Alias for {@link subtract}
|
|
311
|
+
*/
|
|
312
|
+
export declare const sub: typeof subtract;
|
|
313
|
+
/**
|
|
314
|
+
* Alias for {@link multiply}
|
|
315
|
+
*/
|
|
316
|
+
export declare const mul: typeof multiply;
|
|
317
|
+
/**
|
|
318
|
+
* Alias for {@link divide}
|
|
319
|
+
*/
|
|
320
|
+
export declare const div: typeof divide;
|
|
321
|
+
/**
|
|
322
|
+
* Alias for {@link distance}
|
|
323
|
+
*/
|
|
324
|
+
export declare const dist: typeof distance;
|
|
325
|
+
/**
|
|
326
|
+
* Alias for {@link squaredDistance}
|
|
327
|
+
*/
|
|
328
|
+
export declare const sqrDist: typeof squaredDistance;
|
|
329
|
+
/**
|
|
330
|
+
* Alias for {@link length}
|
|
331
|
+
*/
|
|
332
|
+
export declare const len: typeof length;
|
|
333
|
+
/**
|
|
334
|
+
* Alias for {@link squaredLength}
|
|
335
|
+
*/
|
|
336
|
+
export declare const sqrLen: typeof squaredLength;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Vec2 } from '../core/vec2.js';
|
|
2
|
+
import type { Circle } from '../shapes/circle.js';
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the circumcircle of three points and stores the center in the output parameter.
|
|
5
|
+
* @param out The circle to store the result in
|
|
6
|
+
* @param triangle The triangle defined by three points
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function circumcircle(out: Circle, a: Vec2, b: Vec2, c: Vec2): Circle;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decomposes a simple polygon into convex sub-polygons using Bayazit's fast
|
|
3
|
+
* approximate algorithm. Fast (~O(n²)) but may use more pieces than the
|
|
4
|
+
* minimum; may introduce new (Steiner) vertices. Input winding is normalised
|
|
5
|
+
* internally, so either winding is accepted.
|
|
6
|
+
*
|
|
7
|
+
* Implemented iteratively with an explicit worklist of sub-polygons rather than
|
|
8
|
+
* recursion.
|
|
9
|
+
*
|
|
10
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
11
|
+
* @param n number of vertices to read from `vertices`
|
|
12
|
+
* @returns an array of convex sub-polygons, each a flat `[x0, y0, ...]` array (CCW)
|
|
13
|
+
*/
|
|
14
|
+
export declare function decomposePolygon2Quick(vertices: number[], n: number): number[][];
|
|
15
|
+
/**
|
|
16
|
+
* Decomposes a simple polygon into the (near-)minimum number of convex
|
|
17
|
+
* sub-polygons. Produces fewer pieces than {@link decomposePolygon2Quick} but
|
|
18
|
+
* is much slower (~O(n⁴)) — use only for small polygons. Input winding is
|
|
19
|
+
* normalised internally, so either winding is accepted.
|
|
20
|
+
*
|
|
21
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
22
|
+
* @param n number of vertices to read from `vertices`
|
|
23
|
+
* @returns an array of convex sub-polygons, each a flat `[x0, y0, ...]` array (CCW)
|
|
24
|
+
*/
|
|
25
|
+
export declare function decomposePolygon2Quality(vertices: number[], n: number): number[][];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Triangulates a simple polygon by ear clipping, writing triangle indices into
|
|
3
|
+
* `out` as `[i0, i1, i2, i3, i4, i5, ...]`, where each index refers to a vertex
|
|
4
|
+
* of the input polygon. Either winding is accepted (normalised internally).
|
|
5
|
+
*
|
|
6
|
+
* `out` must have room for at least `3 * (n - 2)` indices. A complete
|
|
7
|
+
* triangulation returns exactly `n - 2` triangles; a smaller count indicates
|
|
8
|
+
* the polygon could not be fully triangulated (e.g. degenerate input).
|
|
9
|
+
*
|
|
10
|
+
* @param out output array of triangle indices
|
|
11
|
+
* @param vertices polygon vertices as a flat array `[x0, y0, x1, y1, ...]`
|
|
12
|
+
* @param n number of vertices to read from `vertices`
|
|
13
|
+
* @returns the number of triangles written
|
|
14
|
+
*/
|
|
15
|
+
export declare function triangulatePolygon2(out: number[], vertices: number[], n: number): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the convex hull of a set of 2D points using the QuickHull algorithm.
|
|
3
|
+
* The hull is returned as an array of indices in counter-clockwise order.
|
|
4
|
+
*
|
|
5
|
+
* Implementation of pseudocode from: https://en.wikipedia.org/wiki/Quickhull
|
|
6
|
+
*
|
|
7
|
+
* @param points flat array of 2D points: [x0, y0, x1, y1, ...]
|
|
8
|
+
* @returns indices of hull vertices in ccw order
|
|
9
|
+
*/
|
|
10
|
+
export declare function quickhull2(points: number[]): number[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incremental Convex Hull 3D implementation based on Three.js ConvexHull.
|
|
3
|
+
*
|
|
4
|
+
* This implements the QuickHull algorithm with an incremental approach that maintains
|
|
5
|
+
* a valid hull at each step using a half-edge data structure (DCEL - Doubly Connected
|
|
6
|
+
* Edge List) for O(1) face adjacency queries.
|
|
7
|
+
*
|
|
8
|
+
* The algorithm is based on John Lloyd's Java implementation and was ported to
|
|
9
|
+
* JavaScript by Mauricio Poppe (quickhull3d), then incorporated into Three.js.
|
|
10
|
+
*
|
|
11
|
+
* References:
|
|
12
|
+
* - Three.js ConvexHull: https://github.com/mrdoob/three.js/blob/dev/examples/jsm/math/ConvexHull.js
|
|
13
|
+
* - quickhull3d by Mauricio Poppe: https://github.com/maurizzzio/quickhull3d/
|
|
14
|
+
* - Original Java by John Lloyd: http://www.cs.ubc.ca/~lloyd/java/quickhull3d.html
|
|
15
|
+
* - Dirk Gregorius presentation: https://archive.org/details/GDC2014Gregorius
|
|
16
|
+
*
|
|
17
|
+
* Algorithm: QuickHull (incremental variant)
|
|
18
|
+
* Time complexity: O(n log n) average, O(n²) worst case
|
|
19
|
+
* Space complexity: O(n + f + e) where f=faces, e=edges (~3x more than basic)
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Computes the convex hull of a set of 3D points using an incremental QuickHull algorithm.
|
|
23
|
+
*
|
|
24
|
+
* @param points An array of numbers representing the 3D points (x1, y1, z1, x2, y2, z2, ...)
|
|
25
|
+
* @returns An array of indices representing the triangles of the convex hull (i1, j1, k1, i2, j2, k2, ...).
|
|
26
|
+
*/
|
|
27
|
+
export declare function quickhull3(points: number[]): number[];
|