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.
Files changed (203) hide show
  1. package/API.md +1605 -0
  2. package/LICENSE +21 -0
  3. package/README.md +197 -0
  4. package/dist/color/color.js +136 -0
  5. package/dist/color/color.js.map +1 -0
  6. package/dist/color/colorspace.js +43 -0
  7. package/dist/color/colorspace.js.map +1 -0
  8. package/dist/color/hsl.js +123 -0
  9. package/dist/color/hsl.js.map +1 -0
  10. package/dist/color/index.js +7 -0
  11. package/dist/color/index.js.map +1 -0
  12. package/dist/color/parse.js +276 -0
  13. package/dist/color/parse.js.map +1 -0
  14. package/dist/core/angle.js +43 -0
  15. package/dist/core/angle.js.map +1 -0
  16. package/dist/core/euler.js +212 -0
  17. package/dist/core/euler.js.map +1 -0
  18. package/dist/core/mat2.js +385 -0
  19. package/dist/core/mat2.js.map +1 -0
  20. package/dist/core/mat2d.js +422 -0
  21. package/dist/core/mat2d.js.map +1 -0
  22. package/dist/core/mat3.js +749 -0
  23. package/dist/core/mat3.js.map +1 -0
  24. package/dist/core/mat4.js +2197 -0
  25. package/dist/core/mat4.js.map +1 -0
  26. package/dist/core/polar.js +200 -0
  27. package/dist/core/polar.js.map +1 -0
  28. package/dist/core/quat.js +730 -0
  29. package/dist/core/quat.js.map +1 -0
  30. package/dist/core/quat2.js +883 -0
  31. package/dist/core/quat2.js.map +1 -0
  32. package/dist/core/scalar.js +112 -0
  33. package/dist/core/scalar.js.map +1 -0
  34. package/dist/core/spherical.js +248 -0
  35. package/dist/core/spherical.js.map +1 -0
  36. package/dist/core/vec2.js +597 -0
  37. package/dist/core/vec2.js.map +1 -0
  38. package/dist/core/vec3.js +916 -0
  39. package/dist/core/vec3.js.map +1 -0
  40. package/dist/core/vec4.js +573 -0
  41. package/dist/core/vec4.js.map +1 -0
  42. package/dist/geometry/circumcircle.js +39 -0
  43. package/dist/geometry/circumcircle.js.map +1 -0
  44. package/dist/geometry/index.js +6 -0
  45. package/dist/geometry/index.js.map +1 -0
  46. package/dist/geometry/polygon2-decompose.js +411 -0
  47. package/dist/geometry/polygon2-decompose.js.map +1 -0
  48. package/dist/geometry/polygon2-triangulate.js +222 -0
  49. package/dist/geometry/polygon2-triangulate.js.map +1 -0
  50. package/dist/geometry/quickhull2.js +123 -0
  51. package/dist/geometry/quickhull2.js.map +1 -0
  52. package/dist/geometry/quickhull3.js +605 -0
  53. package/dist/geometry/quickhull3.js.map +1 -0
  54. package/dist/ik/fabrik2.js +675 -0
  55. package/dist/ik/fabrik2.js.map +1 -0
  56. package/dist/ik/fabrik3.js +912 -0
  57. package/dist/ik/fabrik3.js.map +1 -0
  58. package/dist/ik/index.js +5 -0
  59. package/dist/ik/index.js.map +1 -0
  60. package/dist/index.js +27 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/noise/fractal.js +185 -0
  63. package/dist/noise/fractal.js.map +1 -0
  64. package/dist/noise/index.js +16 -0
  65. package/dist/noise/index.js.map +1 -0
  66. package/dist/noise/perlin2d.js +50 -0
  67. package/dist/noise/perlin2d.js.map +1 -0
  68. package/dist/noise/perlin3d.js +72 -0
  69. package/dist/noise/perlin3d.js.map +1 -0
  70. package/dist/noise/permutation.js +120 -0
  71. package/dist/noise/permutation.js.map +1 -0
  72. package/dist/noise/simplex2d.js +84 -0
  73. package/dist/noise/simplex2d.js.map +1 -0
  74. package/dist/noise/simplex3d.js +147 -0
  75. package/dist/noise/simplex3d.js.map +1 -0
  76. package/dist/noise/simplex4d.js +149 -0
  77. package/dist/noise/simplex4d.js.map +1 -0
  78. package/dist/noise/worley2d.js +50 -0
  79. package/dist/noise/worley2d.js.map +1 -0
  80. package/dist/noise/worley3d.js +61 -0
  81. package/dist/noise/worley3d.js.map +1 -0
  82. package/dist/random/index.js +9 -0
  83. package/dist/random/index.js.map +1 -0
  84. package/dist/random/isaac32.js +164 -0
  85. package/dist/random/isaac32.js.map +1 -0
  86. package/dist/random/isaac64.js +215 -0
  87. package/dist/random/isaac64.js.map +1 -0
  88. package/dist/random/mulberry32.js +48 -0
  89. package/dist/random/mulberry32.js.map +1 -0
  90. package/dist/random/random.js +120 -0
  91. package/dist/random/random.js.map +1 -0
  92. package/dist/shapes/box2.js +300 -0
  93. package/dist/shapes/box2.js.map +1 -0
  94. package/dist/shapes/box3.js +550 -0
  95. package/dist/shapes/box3.js.map +1 -0
  96. package/dist/shapes/circle.js +6 -0
  97. package/dist/shapes/circle.js.map +1 -0
  98. package/dist/shapes/frustum.js +662 -0
  99. package/dist/shapes/frustum.js.map +1 -0
  100. package/dist/shapes/index.js +25 -0
  101. package/dist/shapes/index.js.map +1 -0
  102. package/dist/shapes/obb3.js +557 -0
  103. package/dist/shapes/obb3.js.map +1 -0
  104. package/dist/shapes/plane3.js +267 -0
  105. package/dist/shapes/plane3.js.map +1 -0
  106. package/dist/shapes/polygon2.js +451 -0
  107. package/dist/shapes/polygon2.js.map +1 -0
  108. package/dist/shapes/raycast3.js +164 -0
  109. package/dist/shapes/raycast3.js.map +1 -0
  110. package/dist/shapes/segment2.js +82 -0
  111. package/dist/shapes/segment2.js.map +1 -0
  112. package/dist/shapes/sphere.js +23 -0
  113. package/dist/shapes/sphere.js.map +1 -0
  114. package/dist/shapes/triangle2.js +79 -0
  115. package/dist/shapes/triangle2.js.map +1 -0
  116. package/dist/shapes/triangle3.js +60 -0
  117. package/dist/shapes/triangle3.js.map +1 -0
  118. package/dist/src/color/color.d.ts +50 -0
  119. package/dist/src/color/colorspace.d.ts +15 -0
  120. package/dist/src/color/hsl.d.ts +28 -0
  121. package/dist/src/color/index.d.ts +5 -0
  122. package/dist/src/color/parse.d.ts +15 -0
  123. package/dist/src/core/angle.d.ts +29 -0
  124. package/dist/src/core/arrays.d.ts +4 -0
  125. package/dist/src/core/euler.d.ts +78 -0
  126. package/dist/src/core/index.d.ts +27 -0
  127. package/dist/src/core/mat2.d.ts +217 -0
  128. package/dist/src/core/mat2d.d.ts +218 -0
  129. package/dist/src/core/mat3.d.ts +295 -0
  130. package/dist/src/core/mat4.d.ts +667 -0
  131. package/dist/src/core/polar.d.ts +151 -0
  132. package/dist/src/core/quat.d.ts +370 -0
  133. package/dist/src/core/quat2.d.ts +344 -0
  134. package/dist/src/core/scalar.d.ts +75 -0
  135. package/dist/src/core/spherical.d.ts +165 -0
  136. package/dist/src/core/vec2.d.ts +403 -0
  137. package/dist/src/core/vec3.d.ts +493 -0
  138. package/dist/src/core/vec4.d.ts +336 -0
  139. package/dist/src/geometry/circumcircle.d.ts +9 -0
  140. package/dist/src/geometry/index.d.ts +5 -0
  141. package/dist/src/geometry/polygon2-decompose.d.ts +25 -0
  142. package/dist/src/geometry/polygon2-triangulate.d.ts +15 -0
  143. package/dist/src/geometry/quickhull2.d.ts +10 -0
  144. package/dist/src/geometry/quickhull3.d.ts +27 -0
  145. package/dist/src/ik/fabrik2.d.ts +314 -0
  146. package/dist/src/ik/fabrik3.d.ts +371 -0
  147. package/dist/src/ik/index.d.ts +2 -0
  148. package/dist/src/index.d.ts +1 -0
  149. package/dist/src/noise/fractal.d.ts +95 -0
  150. package/dist/src/noise/index.d.ts +9 -0
  151. package/dist/src/noise/perlin2d.d.ts +19 -0
  152. package/dist/src/noise/perlin3d.d.ts +20 -0
  153. package/dist/src/noise/permutation.d.ts +22 -0
  154. package/dist/src/noise/simplex2d.d.ts +19 -0
  155. package/dist/src/noise/simplex3d.d.ts +20 -0
  156. package/dist/src/noise/simplex4d.d.ts +24 -0
  157. package/dist/src/noise/worley2d.d.ts +22 -0
  158. package/dist/src/noise/worley3d.d.ts +23 -0
  159. package/dist/src/random/index.d.ts +8 -0
  160. package/dist/src/random/isaac32.d.ts +62 -0
  161. package/dist/src/random/isaac64.d.ts +75 -0
  162. package/dist/src/random/mulberry32.d.ts +43 -0
  163. package/dist/src/random/random.d.ts +67 -0
  164. package/dist/src/shapes/box2.d.ts +174 -0
  165. package/dist/src/shapes/box3.d.ts +213 -0
  166. package/dist/src/shapes/circle.d.ts +7 -0
  167. package/dist/src/shapes/frustum.d.ts +147 -0
  168. package/dist/src/shapes/index.d.ts +20 -0
  169. package/dist/src/shapes/obb3.d.ts +105 -0
  170. package/dist/src/shapes/plane3.d.ts +130 -0
  171. package/dist/src/shapes/polygon2.d.ts +155 -0
  172. package/dist/src/shapes/raycast3.d.ts +42 -0
  173. package/dist/src/shapes/segment2.d.ts +34 -0
  174. package/dist/src/shapes/sphere.d.ts +19 -0
  175. package/dist/src/shapes/triangle2.d.ts +53 -0
  176. package/dist/src/shapes/triangle3.d.ts +29 -0
  177. package/dist/src/time/easing.d.ts +21 -0
  178. package/dist/src/time/index.d.ts +6 -0
  179. package/dist/src/time/spring-core.d.ts +15 -0
  180. package/dist/src/time/spring.d.ts +36 -0
  181. package/dist/src/time/spring2.d.ts +11 -0
  182. package/dist/src/time/spring3.d.ts +11 -0
  183. package/dist/src/time/spring4.d.ts +11 -0
  184. package/dist/time/easing.js +24 -0
  185. package/dist/time/easing.js.map +1 -0
  186. package/dist/time/index.js +11 -0
  187. package/dist/time/index.js.map +1 -0
  188. package/dist/time/spring-core.js +48 -0
  189. package/dist/time/spring-core.js.map +1 -0
  190. package/dist/time/spring.js +62 -0
  191. package/dist/time/spring.js.map +1 -0
  192. package/dist/time/spring2.js +31 -0
  193. package/dist/time/spring2.js.map +1 -0
  194. package/dist/time/spring3.js +32 -0
  195. package/dist/time/spring3.js.map +1 -0
  196. package/dist/time/spring4.js +32 -0
  197. package/dist/time/spring4.js.map +1 -0
  198. package/package.json +90 -16
  199. package/skills/math/SKILL.md +140 -0
  200. package/AUTHORS +0 -1
  201. package/Cakefile +0 -28
  202. package/math.coffee +0 -112
  203. package/math.js +0 -141
@@ -0,0 +1,295 @@
1
+ import type { Mat2d } from './mat2d.js';
2
+ import type { Mat4 } from './mat4.js';
3
+ import type { Quat } from './quat.js';
4
+ import type { Vec2 } from './vec2.js';
5
+ /** A 3x3 matrix */
6
+ export type Mat3 = [e1: number, e2: number, e3: number, e4: number, e5: number, e6: number, e7: number, e8: number, e9: number];
7
+ /**
8
+ * Creates a new identity mat3
9
+ *
10
+ * @returns a new 3x3 matrix
11
+ */
12
+ export declare function create(): Mat3;
13
+ /**
14
+ * Copies the upper-left 3x3 values into the given mat3.
15
+ *
16
+ * @param out the receiving 3x3 matrix
17
+ * @param a the source 4x4 matrix
18
+ * @returns out
19
+ */
20
+ export declare function fromMat4(out: Mat3, a: Mat4): Mat3;
21
+ /**
22
+ * Creates a new mat3 initialized with values from an existing matrix
23
+ *
24
+ * @param a matrix to clone
25
+ * @returns a new 3x3 matrix
26
+ */
27
+ export declare function clone(a: Mat3): Mat3;
28
+ /**
29
+ * Copy the values from one mat3 to another
30
+ *
31
+ * @param out the receiving matrix
32
+ * @param a the source matrix
33
+ * @returns out
34
+ */
35
+ export declare function copy(out: Mat3, a: Mat3): Mat3;
36
+ /**
37
+ * Create a new mat3 with the given values
38
+ *
39
+ * @param m00 Component in column 0, row 0 position (index 0)
40
+ * @param m01 Component in column 0, row 1 position (index 1)
41
+ * @param m02 Component in column 0, row 2 position (index 2)
42
+ * @param m10 Component in column 1, row 0 position (index 3)
43
+ * @param m11 Component in column 1, row 1 position (index 4)
44
+ * @param m12 Component in column 1, row 2 position (index 5)
45
+ * @param m20 Component in column 2, row 0 position (index 6)
46
+ * @param m21 Component in column 2, row 1 position (index 7)
47
+ * @param m22 Component in column 2, row 2 position (index 8)
48
+ * @returns A new mat3
49
+ */
50
+ export declare function fromValues(m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Mat3;
51
+ /**
52
+ * Set the components of a mat3 to the given values
53
+ *
54
+ * @param out the receiving matrix
55
+ * @param m00 Component in column 0, row 0 position (index 0)
56
+ * @param m01 Component in column 0, row 1 position (index 1)
57
+ * @param m02 Component in column 0, row 2 position (index 2)
58
+ * @param m10 Component in column 1, row 0 position (index 3)
59
+ * @param m11 Component in column 1, row 1 position (index 4)
60
+ * @param m12 Component in column 1, row 2 position (index 5)
61
+ * @param m20 Component in column 2, row 0 position (index 6)
62
+ * @param m21 Component in column 2, row 1 position (index 7)
63
+ * @param m22 Component in column 2, row 2 position (index 8)
64
+ * @returns out
65
+ */
66
+ export declare function set(out: Mat3, m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Mat3;
67
+ /**
68
+ * Set a mat3 to the identity matrix
69
+ *
70
+ * @param out the receiving matrix
71
+ * @returns out
72
+ */
73
+ export declare function identity(out: Mat3): Mat3;
74
+ /**
75
+ * Set a mat3 to the zero matrix
76
+ *
77
+ * @param out the receiving matrix
78
+ * @returns out
79
+ */
80
+ export declare function zero(out: Mat3): Mat3;
81
+ /**
82
+ * Transpose the values of a mat3
83
+ *
84
+ * @param out the receiving matrix
85
+ * @param a the source matrix
86
+ * @returns out
87
+ */
88
+ export declare function transpose(out: Mat3, a: Mat3): Mat3;
89
+ /**
90
+ * Inverts a mat3
91
+ *
92
+ * @param out the receiving matrix
93
+ * @param a the source matrix
94
+ * @returns out
95
+ */
96
+ export declare function invert(out: Mat3, a: Mat3): Mat3 | null;
97
+ /**
98
+ * Calculates the adjugate of a mat3
99
+ *
100
+ * @param out the receiving matrix
101
+ * @param a the source matrix
102
+ * @returns out
103
+ */
104
+ export declare function adjoint(out: Mat3, a: Mat3): Mat3;
105
+ /**
106
+ * Calculates the determinant of a mat3
107
+ *
108
+ * @param a the source matrix
109
+ * @returns determinant of a
110
+ */
111
+ export declare function determinant(a: Mat3): number;
112
+ /**
113
+ * Multiplies two mat3's
114
+ *
115
+ * @param out the receiving matrix
116
+ * @param a the first operand
117
+ * @param b the second operand
118
+ * @returns out
119
+ */
120
+ export declare function multiply(out: Mat3, a: Mat3, b: Mat3): Mat3;
121
+ /**
122
+ * Translate a mat3 by the given vector
123
+ *
124
+ * @param out the receiving matrix
125
+ * @param a the matrix to translate
126
+ * @param v vector to translate by
127
+ * @returns out
128
+ */
129
+ export declare function translate(out: Mat3, a: Mat3, v: Vec2): Mat3;
130
+ /**
131
+ * Rotates a mat3 by the given angle
132
+ *
133
+ * @param out the receiving matrix
134
+ * @param a the matrix to rotate
135
+ * @param rad the angle to rotate the matrix by
136
+ * @returns out
137
+ */
138
+ export declare function rotate(out: Mat3, a: Mat3, rad: number): Mat3;
139
+ /**
140
+ * Scales the mat3 by the dimensions in the given vec2
141
+ *
142
+ * @param out the receiving matrix
143
+ * @param a the matrix to rotate
144
+ * @param v the vec2 to scale the matrix by
145
+ * @returns out
146
+ **/
147
+ export declare function scale(out: Mat3, a: Mat3, v: Vec2): Mat3;
148
+ /**
149
+ * Creates a matrix from a vector translation
150
+ * This is equivalent to (but much faster than):
151
+ *
152
+ * mat3.identity(dest);
153
+ * mat3.translate(dest, dest, vec);
154
+ *
155
+ * @param out mat3 receiving operation result
156
+ * @param v Translation vector
157
+ * @returns out
158
+ */
159
+ export declare function fromTranslation(out: Mat3, v: Vec2): Mat3;
160
+ /**
161
+ * Creates a matrix from a given angle
162
+ * This is equivalent to (but much faster than):
163
+ *
164
+ * mat3.identity(dest);
165
+ * mat3.rotate(dest, dest, rad);
166
+ *
167
+ * @param out mat3 receiving operation result
168
+ * @param rad the angle to rotate the matrix by
169
+ * @returns out
170
+ */
171
+ export declare function fromRotation(out: Mat3, rad: number): Mat3;
172
+ /**
173
+ * Creates a matrix from a vector scaling
174
+ * This is equivalent to (but much faster than):
175
+ *
176
+ * mat3.identity(dest);
177
+ * mat3.scale(dest, dest, vec);
178
+ *
179
+ * @param out mat3 receiving operation result
180
+ * @param v Scaling vector
181
+ * @returns out
182
+ */
183
+ export declare function fromScaling(out: Mat3, v: Vec2): Mat3;
184
+ /**
185
+ * Copies the values from a mat2d into a mat3
186
+ *
187
+ * @param out the receiving matrix
188
+ * @param a the matrix to copy
189
+ * @returns out
190
+ **/
191
+ export declare function fromMat2d(out: Mat3, a: Mat2d): Mat3;
192
+ /**
193
+ * Calculates a 3x3 matrix from the given quaternion
194
+ *
195
+ * @param out mat3 receiving operation result
196
+ * @param q Quaternion to create matrix from
197
+ *
198
+ * @returns out
199
+ */
200
+ export declare function fromQuat(out: Mat3, q: Quat): Mat3;
201
+ /**
202
+ * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
203
+ *
204
+ * @param out mat3 receiving operation result
205
+ * @param a Mat4 to derive the normal matrix from
206
+ *
207
+ * @returns out
208
+ */
209
+ export declare function normalFromMat4(out: Mat3, a: Mat4): Mat3 | null;
210
+ /**
211
+ * Generates a 2D projection matrix with the given bounds
212
+ *
213
+ * @param out mat3 frustum matrix will be written into
214
+ * @param width Width of your gl context
215
+ * @param height Height of gl context
216
+ * @returns out
217
+ */
218
+ export declare function projection(out: Mat3, width: number, height: number): Mat3;
219
+ /**
220
+ * Returns a string representation of a mat3
221
+ *
222
+ * @param a matrix to represent as a string
223
+ * @returns string representation of the matrix
224
+ */
225
+ export declare function str(a: Mat3): string;
226
+ /**
227
+ * Returns Frobenius norm of a mat3
228
+ *
229
+ * @param a the matrix to calculate Frobenius norm of
230
+ * @returns Frobenius norm
231
+ */
232
+ export declare function frob(a: Mat3): number;
233
+ /**
234
+ * Adds two mat3's
235
+ *
236
+ * @param out the receiving matrix
237
+ * @param a the first operand
238
+ * @param b the second operand
239
+ * @returns out
240
+ */
241
+ export declare function add(out: Mat3, a: Mat3, b: Mat3): Mat3;
242
+ /**
243
+ * Subtracts matrix b from matrix a
244
+ *
245
+ * @param out the receiving matrix
246
+ * @param a the first operand
247
+ * @param b the second operand
248
+ * @returns out
249
+ */
250
+ export declare function subtract(out: Mat3, a: Mat3, b: Mat3): Mat3;
251
+ /**
252
+ * Multiply each element of the matrix by a scalar.
253
+ *
254
+ * @param out the receiving matrix
255
+ * @param a the matrix to scale
256
+ * @param b amount to scale the matrix's elements by
257
+ * @returns out
258
+ */
259
+ export declare function multiplyScalar(out: Mat3, a: Mat3, b: number): Mat3;
260
+ /**
261
+ * Adds two mat3's after multiplying each element of the second operand by a scalar value.
262
+ *
263
+ * @param out the receiving vector
264
+ * @param a the first operand
265
+ * @param b the second operand
266
+ * @param scale the amount to scale b's elements by before adding
267
+ * @returns out
268
+ */
269
+ export declare function multiplyScalarAndAdd(out: Mat3, a: Mat3, b: Mat3, scale: number): Mat3;
270
+ /**
271
+ * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
272
+ *
273
+ * @param a The first matrix.
274
+ * @param b The second matrix.
275
+ * @returns True if the matrices are equal, false otherwise.
276
+ */
277
+ export declare function exactEquals(a: Mat3, b: Mat3): boolean;
278
+ /**
279
+ * Returns whether or not the matrices have approximately the same elements in the same position.
280
+ *
281
+ * @param a The first matrix.
282
+ * @param b The second matrix.
283
+ * @returns True if the matrices are equal, false otherwise.
284
+ */
285
+ export declare function equals(a: Mat3, b: Mat3): boolean;
286
+ /**
287
+ * Alias for {@link mat3.multiply}
288
+ * @function
289
+ */
290
+ export declare const mul: typeof multiply;
291
+ /**
292
+ * Alias for {@link mat3.subtract}
293
+ * @function
294
+ */
295
+ export declare const sub: typeof subtract;