@oliversalzburg/js-utils 0.0.13 → 0.0.15
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/_site/assets/navigation.js +1 -1
- package/_site/assets/search.js +1 -1
- package/_site/classes/AbstractError.html +47 -8
- package/_site/classes/Canvas.html +66 -26
- package/_site/classes/CanvasSandbox.html +76 -0
- package/_site/classes/Euler.html +217 -0
- package/_site/classes/InternalError.html +48 -9
- package/_site/classes/InvalidArgumentError.html +47 -8
- package/_site/classes/InvalidOperationError.html +47 -8
- package/_site/classes/Matrix3.html +167 -0
- package/_site/classes/NotImplementedError.html +47 -8
- package/_site/classes/PermissionViolationError.html +47 -8
- package/_site/classes/Quaternion.html +211 -0
- package/_site/classes/Random.html +60 -13
- package/_site/classes/RenderLoop.html +62 -20
- package/_site/classes/ResourceConflictError.html +47 -8
- package/_site/classes/Transformation.html +52 -0
- package/_site/classes/UnexpectedNilError.html +44 -5
- package/_site/classes/UnknownError.html +47 -8
- package/_site/classes/Vector2.html +80 -37
- package/_site/classes/Vector3.html +201 -15
- package/_site/classes/Vector4.html +156 -0
- package/_site/favicon.ico +0 -0
- package/_site/functions/addVector2.html +43 -4
- package/_site/functions/addVector3.html +44 -0
- package/_site/functions/blend.html +41 -2
- package/_site/functions/blendAdditive.html +41 -2
- package/_site/functions/blendSubtractive.html +41 -2
- package/_site/functions/clamp.html +41 -2
- package/_site/functions/coalesceOnRejection.html +48 -0
- package/_site/functions/cosDeg.html +41 -2
- package/_site/functions/crossVector3.html +44 -0
- package/_site/functions/deg2rad.html +41 -2
- package/_site/functions/difference.html +41 -2
- package/_site/functions/distance.html +41 -2
- package/_site/functions/dotVector3.html +44 -0
- package/_site/functions/errorToJSON.html +41 -2
- package/_site/functions/errorToRecord.html +41 -2
- package/_site/functions/errorToSimpleSerializable.html +41 -2
- package/_site/functions/filterType.html +41 -2
- package/_site/functions/formatString.html +41 -2
- package/_site/functions/formatStringTemplate.html +41 -2
- package/_site/functions/fromRGB.html +41 -2
- package/_site/functions/fromRGBA.html +41 -2
- package/_site/functions/getA.html +41 -2
- package/_site/functions/getB.html +41 -2
- package/_site/functions/getDocumentElementTypeById.html +41 -2
- package/_site/functions/getG.html +41 -2
- package/_site/functions/getR.html +41 -2
- package/_site/functions/intersect.html +41 -2
- package/_site/functions/is.html +41 -2
- package/_site/functions/isError.html +41 -2
- package/_site/functions/isInteger.html +41 -2
- package/_site/functions/isNil.html +41 -2
- package/_site/functions/isqrt.html +41 -2
- package/_site/functions/multiplyVector2.html +43 -4
- package/_site/functions/multiplyVector3.html +44 -0
- package/_site/functions/mustExist.html +41 -2
- package/_site/functions/nextPalette.html +42 -2
- package/_site/functions/prepareAsyncContext.html +46 -0
- package/_site/functions/putPixel32.html +47 -8
- package/_site/functions/putPixel32Add.html +47 -8
- package/_site/functions/putPixel32Sub.html +47 -8
- package/_site/functions/putSubPixel32.html +41 -2
- package/_site/functions/rad2deg.html +41 -2
- package/_site/functions/randomRange.html +41 -2
- package/_site/functions/safeRGBComponent.html +41 -2
- package/_site/functions/seedFromString.html +41 -2
- package/_site/functions/shuffleArray.html +41 -2
- package/_site/functions/sinDeg.html +41 -2
- package/_site/functions/sleep.html +41 -2
- package/_site/functions/somecolor.html +41 -2
- package/_site/functions/subtractVector2.html +43 -4
- package/_site/functions/subtractVector3.html +44 -0
- package/_site/functions/toGrayScale.html +41 -2
- package/_site/functions/unknownToError.html +41 -2
- package/_site/index.html +41 -2
- package/_site/interfaces/CanvasOptions.html +42 -3
- package/_site/interfaces/CanvasSandboxApplication.html +60 -0
- package/_site/interfaces/CanvasSandboxExpectedOptions.html +48 -0
- package/_site/interfaces/RenderLoopOptions.html +43 -4
- package/_site/modules.html +59 -3
- package/_site/types/AnyAsyncFunction.html +41 -0
- package/_site/types/AnyConstructor.html +41 -2
- package/_site/types/AnyFunction.html +41 -2
- package/_site/types/ConstructorOf.html +41 -2
- package/_site/types/FunctionReturning.html +41 -2
- package/_site/types/Maybe.html +41 -2
- package/_site/types/Mixin.html +41 -2
- package/_site/types/Nil.html +41 -2
- package/_site/types/RenderLoopCallback.html +41 -2
- package/_site/types/SerializedError.html +41 -2
- package/_site/variables/MS_PER_FRAME_60FPS.html +42 -0
- package/_site/variables/PALETTES.html +41 -2
- package/_site/variables/TWO_PI.html +41 -2
- package/_site/variables/random-1.html +41 -2
- package/docs/assets/favicon.ico +0 -0
- package/lib/Async.d.ts +3 -0
- package/lib/Async.js +17 -0
- package/lib/Async.js.map +1 -0
- package/lib/async.d.ts +24 -0
- package/lib/async.js +37 -0
- package/lib/async.js.map +1 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js.map +1 -1
- package/lib/graphics/canvas copy.d.ts +170 -0
- package/lib/graphics/canvas copy.js +300 -0
- package/lib/graphics/canvas copy.js.map +1 -0
- package/lib/graphics/canvas-sandbox.d.ts +206 -0
- package/lib/graphics/canvas-sandbox.js +272 -0
- package/lib/graphics/canvas-sandbox.js.map +1 -0
- package/lib/graphics/canvas-worker.d.ts +50 -0
- package/lib/graphics/canvas-worker.js +78 -0
- package/lib/graphics/canvas-worker.js.map +1 -0
- package/lib/graphics/canvas.d.ts +14 -9
- package/lib/graphics/canvas.js +53 -19
- package/lib/graphics/canvas.js.map +1 -1
- package/lib/graphics/core.d.ts +2 -1
- package/lib/graphics/core.js +2 -0
- package/lib/graphics/core.js.map +1 -1
- package/lib/graphics/index.d.ts +1 -0
- package/lib/graphics/index.js +1 -0
- package/lib/graphics/index.js.map +1 -1
- package/lib/graphics/render-loop.d.ts +6 -5
- package/lib/graphics/render-loop.js +18 -9
- package/lib/graphics/render-loop.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/math/euler.d.ts +19 -0
- package/lib/math/euler.js +23 -0
- package/lib/math/euler.js.map +1 -0
- package/lib/math/index.d.ts +5 -1
- package/lib/math/index.js +5 -1
- package/lib/math/index.js.map +1 -1
- package/lib/math/matrix3.d.ts +218 -0
- package/lib/math/matrix3.js +509 -0
- package/lib/math/matrix3.js.map +1 -0
- package/lib/math/quaternion.d.ts +120 -0
- package/lib/math/quaternion.js +272 -0
- package/lib/math/quaternion.js.map +1 -0
- package/lib/math/transformation.d.ts +27 -0
- package/lib/math/transformation.js +32 -0
- package/lib/math/transformation.js.map +1 -0
- package/lib/math/vector2.d.ts +19 -13
- package/lib/math/vector2.js +12 -4
- package/lib/math/vector2.js.map +1 -1
- package/lib/math/vector3.d.ts +256 -3
- package/lib/math/vector3.js +440 -1
- package/lib/math/vector3.js.map +1 -1
- package/lib/math/vector4.d.ts +183 -0
- package/lib/math/vector4.js +303 -0
- package/lib/math/vector4.js.map +1 -0
- package/lib/random.d.ts +12 -0
- package/lib/random.js +16 -0
- package/lib/random.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { Vector4 } from "./vector4.js";
|
|
2
|
+
/**
|
|
3
|
+
* A quaternion.
|
|
4
|
+
* @group Math
|
|
5
|
+
*/
|
|
6
|
+
export class Quaternion extends Vector4 {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new {@linkcode Quaternion}.
|
|
9
|
+
* @param x The X component.
|
|
10
|
+
* @param y The Y component.
|
|
11
|
+
* @param z The Z component.
|
|
12
|
+
* @param w The W component.
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
15
|
+
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
16
|
+
super(x, y, z, w);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new {@linkcode Quaternion} from a rotation matrix.
|
|
20
|
+
* @param matrix The matrix to construct the quaternion from.
|
|
21
|
+
* @returns A new quaternion.
|
|
22
|
+
*/
|
|
23
|
+
static fromMatrix3(matrix) {
|
|
24
|
+
return new Quaternion().setMatrix3(matrix);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new {@linkcode Quaternion} from a rotation in Euler angles.
|
|
28
|
+
* @param degrees The rotation in Euler angles.
|
|
29
|
+
* @returns A new quaternion.
|
|
30
|
+
*/
|
|
31
|
+
static fromEuler(degrees) {
|
|
32
|
+
return new Quaternion().setEuler(degrees);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new {@linkcode Quaternion} from a rotation around an axis.
|
|
36
|
+
* @param axis The axis around which to rotate.
|
|
37
|
+
* @param degrees The rotation in degrees.
|
|
38
|
+
* @returns A new quaternion.
|
|
39
|
+
*/
|
|
40
|
+
static fromVector3(axis, degrees) {
|
|
41
|
+
return new Quaternion().setVector3(axis, degrees);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new {@linkcode Quaternion} from a {@linkcode Vector4}.
|
|
45
|
+
* @param vector The vector to copy the components from.
|
|
46
|
+
* @returns A new quaternion.
|
|
47
|
+
*/
|
|
48
|
+
static fromVector4(vector) {
|
|
49
|
+
return new Quaternion().setVector4(vector);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new {@linkcode Quaternion} from another {@linkcode Quaternion}.
|
|
53
|
+
* @param quaternion The quaternion to copy.
|
|
54
|
+
* @returns A new quaternion.
|
|
55
|
+
*/
|
|
56
|
+
static fromQuaternion(quaternion) {
|
|
57
|
+
return new Quaternion().set(quaternion);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Sets the quaternion to the values of another quaternion.
|
|
61
|
+
* @param quaternion The quaternion to copy.
|
|
62
|
+
* @returns This instance.
|
|
63
|
+
*/
|
|
64
|
+
set(quaternion) {
|
|
65
|
+
this.x = quaternion.x;
|
|
66
|
+
this.y = quaternion.y;
|
|
67
|
+
this.z = quaternion.z;
|
|
68
|
+
this.w = quaternion.w;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sets all components of the quaternion to the given value.
|
|
73
|
+
* @param value The value to assign to the components of the quaternion.
|
|
74
|
+
* @returns This instance.
|
|
75
|
+
*/
|
|
76
|
+
setValue(value) {
|
|
77
|
+
this.x = value;
|
|
78
|
+
this.y = value;
|
|
79
|
+
this.z = value;
|
|
80
|
+
this.w = 1;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Sets the components of the quaternion to the given values.
|
|
85
|
+
* @param x The X component for the quaternion.
|
|
86
|
+
* @param y The Y component for the quaternion.
|
|
87
|
+
* @param z The Z component for the quaternion.
|
|
88
|
+
* @param w The W component for the quaternion.
|
|
89
|
+
* @returns This instance.
|
|
90
|
+
*/
|
|
91
|
+
setXYZW(x, y, z = 0, w = 1) {
|
|
92
|
+
this.x = x;
|
|
93
|
+
this.y = y;
|
|
94
|
+
this.z = z;
|
|
95
|
+
this.w = w;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Sets the quaternion to the rotation of the given matrix.
|
|
100
|
+
* @param matrix The matrix describing the rotation of the quaternion.
|
|
101
|
+
* @returns This instance.
|
|
102
|
+
*/
|
|
103
|
+
setMatrix3(matrix) {
|
|
104
|
+
const nxt = [1, 2, 0];
|
|
105
|
+
// check the diagonal
|
|
106
|
+
const tr = matrix.m00 + matrix.m11 + matrix.m22;
|
|
107
|
+
if (tr > 0) {
|
|
108
|
+
let s = Math.sqrt(tr + 1);
|
|
109
|
+
this.w = s / 2;
|
|
110
|
+
s = 0.5 / s;
|
|
111
|
+
this.x = (matrix.m21 - matrix.m12) * s;
|
|
112
|
+
this.y = (matrix.m02 - matrix.m20) * s;
|
|
113
|
+
this.z = (matrix.m10 - matrix.m01) * s;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
let h = 0;
|
|
117
|
+
if (matrix.m11 > matrix.m00)
|
|
118
|
+
h = 1;
|
|
119
|
+
if (matrix.m22 > matrix.m[h][h])
|
|
120
|
+
h = 2;
|
|
121
|
+
const i = nxt[h];
|
|
122
|
+
const j = nxt[i];
|
|
123
|
+
let s = Math.sqrt(matrix.m[h][h] - (matrix.m[i][i] + matrix.m[j][j]) + 1);
|
|
124
|
+
this.k[h] = s * 0.5;
|
|
125
|
+
if (s !== 0)
|
|
126
|
+
s = 0.5 / s;
|
|
127
|
+
this.w = (matrix.m[j][i] - matrix.m[i][j]) * s;
|
|
128
|
+
this.k[i] = (matrix.m[i][h] + matrix.m[h][i]) * s;
|
|
129
|
+
this.k[j] = (matrix.m[j][h] + matrix.m[h][j]) * s;
|
|
130
|
+
}
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Sets the quaternion to a rotation in Euler angles.
|
|
135
|
+
* @param degrees The rotation in Euler angles.
|
|
136
|
+
* @returns This instance.
|
|
137
|
+
*/
|
|
138
|
+
setEuler(degrees) {
|
|
139
|
+
const cr = Math.cos(degrees.x / 2);
|
|
140
|
+
const cp = Math.cos(degrees.y / 2);
|
|
141
|
+
const cy = Math.cos(degrees.z / 2);
|
|
142
|
+
const sr = Math.sin(degrees.x / 2);
|
|
143
|
+
const sp = Math.sin(degrees.y / 2);
|
|
144
|
+
const sy = Math.sin(degrees.z / 2);
|
|
145
|
+
const cpcy = cp * cy;
|
|
146
|
+
const spsy = sp * sy;
|
|
147
|
+
this.x = sr * cpcy - cr * spsy;
|
|
148
|
+
this.y = cr * sp * cy + sr * cp * sy;
|
|
149
|
+
this.z = cr * cp * sy - sr * sp * cy;
|
|
150
|
+
this.w = cr * cpcy + sr * spsy;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sets the quaternion to a rotation around an axis.
|
|
155
|
+
* @param axis The axis around which to rotate.
|
|
156
|
+
* @param degrees The rotation in degrees.
|
|
157
|
+
* @returns This instance.
|
|
158
|
+
*/
|
|
159
|
+
setVector3(axis, degrees) {
|
|
160
|
+
const si = Math.sin(degrees / 2);
|
|
161
|
+
this.x = axis.x * si;
|
|
162
|
+
this.y = axis.y * si;
|
|
163
|
+
this.z = axis.z * si;
|
|
164
|
+
this.w = Math.cos(degrees / 2);
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Sets the quaternion to the components of a {@linkcode Vector4}.
|
|
169
|
+
* @param vector The vector to copy.
|
|
170
|
+
* @returns This instance.
|
|
171
|
+
*/
|
|
172
|
+
setVector4(vector) {
|
|
173
|
+
this.x = vector.x;
|
|
174
|
+
this.y = vector.y;
|
|
175
|
+
this.z = vector.z;
|
|
176
|
+
this.w = vector.w;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Normalize the quaternion.
|
|
181
|
+
* @returns This instance.
|
|
182
|
+
*/
|
|
183
|
+
normalize() {
|
|
184
|
+
const l = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
|
|
185
|
+
if (l === 0)
|
|
186
|
+
return this;
|
|
187
|
+
this.x = this.x / l;
|
|
188
|
+
this.y = this.y / l;
|
|
189
|
+
this.z = this.z / l;
|
|
190
|
+
this.w = this.w / l;
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Invert the quaternion.
|
|
195
|
+
* @returns This instance.
|
|
196
|
+
*/
|
|
197
|
+
invert() {
|
|
198
|
+
this.x = -this.x;
|
|
199
|
+
this.y = -this.y;
|
|
200
|
+
this.z = -this.z;
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Multiply with another quaternion from the right.
|
|
205
|
+
* @param quaternion The quaternion to multiply with.
|
|
206
|
+
* @returns This instance.
|
|
207
|
+
*/
|
|
208
|
+
multiplyR(quaternion) {
|
|
209
|
+
const A = (this.w + this.x) * (quaternion.w + quaternion.x);
|
|
210
|
+
const B = (this.z - this.y) * (quaternion.y - quaternion.z);
|
|
211
|
+
const C = (this.x - this.w) * (quaternion.y - quaternion.z);
|
|
212
|
+
const D = (this.y + this.z) * (quaternion.x - quaternion.w);
|
|
213
|
+
const E = (this.x + this.z) * (quaternion.x + quaternion.y);
|
|
214
|
+
const F = (this.x - this.z) * (quaternion.x - quaternion.y);
|
|
215
|
+
const G = (this.w + this.y) * (quaternion.w - quaternion.z);
|
|
216
|
+
const H = (this.w - this.y) * (quaternion.w + quaternion.z);
|
|
217
|
+
this.w = B + (-E - F + G + H) / 2;
|
|
218
|
+
this.x = A - (E + F + G + H) / 2;
|
|
219
|
+
this.y = -C + (E - F + G - H) / 2;
|
|
220
|
+
this.z = -D + (E - F - G + H) / 2;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Performs spherical linear interpolation between two rotations, and sets this
|
|
225
|
+
* quaternion to the resulting rotation.
|
|
226
|
+
* @param q1 The initial rotation.
|
|
227
|
+
* @param q2 The target rotation.
|
|
228
|
+
* @param t The location on the scale from `0` to `1`.
|
|
229
|
+
* @returns This instance.
|
|
230
|
+
*/
|
|
231
|
+
slerp(q1, q2, t) {
|
|
232
|
+
const q2a = [0, 0, 0, 0];
|
|
233
|
+
let omega, sinom, scale0, scale1;
|
|
234
|
+
// calc cosine
|
|
235
|
+
let cosom = q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
|
|
236
|
+
// adjust signs (if necessary)
|
|
237
|
+
if (cosom < 0) {
|
|
238
|
+
cosom = -cosom;
|
|
239
|
+
q2a[0] = -q2.x;
|
|
240
|
+
q2a[1] = -q2.y;
|
|
241
|
+
q2a[2] = -q2.z;
|
|
242
|
+
q2a[3] = -q2.w;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
q2a[0] = q2.x;
|
|
246
|
+
q2a[1] = q2.y;
|
|
247
|
+
q2a[2] = q2.z;
|
|
248
|
+
q2a[3] = q2.w;
|
|
249
|
+
}
|
|
250
|
+
// Delta below only linear interpolation is done
|
|
251
|
+
if (1 - cosom > 0.0001) {
|
|
252
|
+
// standard case (slerp)
|
|
253
|
+
omega = Math.acos(cosom);
|
|
254
|
+
sinom = Math.sin(omega);
|
|
255
|
+
scale0 = Math.sin((1 - t) * omega) / sinom;
|
|
256
|
+
scale1 = Math.sin(t * omega) / sinom;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
// "from" and "to" quaternions are very close
|
|
260
|
+
// ... so we can do a linear interpolation
|
|
261
|
+
scale0 = 1 - t;
|
|
262
|
+
scale1 = t;
|
|
263
|
+
}
|
|
264
|
+
// calculate final values
|
|
265
|
+
this.x = scale0 * q1.x + scale1 * q2a[0];
|
|
266
|
+
this.y = scale0 * q1.y + scale1 * q2a[1];
|
|
267
|
+
this.z = scale0 * q1.z + scale1 * q2a[2];
|
|
268
|
+
this.w = scale0 * q1.w + scale1 * q2a[3];
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=quaternion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quaternion.js","sourceRoot":"","sources":["../../source/math/quaternion.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,OAAO;IACrC;;;;;;OAMG;IACH,qEAAqE;IACrE,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC;QACpC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,MAAyB;QAC1C,OAAO,IAAI,UAAU,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,OAAwB;QACvC,OAAO,IAAI,UAAU,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,M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ates an entire transformation, including rotation, position, and scale.
|
|
5
|
+
* @group Math
|
|
6
|
+
*/
|
|
7
|
+
export declare class Transformation {
|
|
8
|
+
/**
|
|
9
|
+
* The rotation to apply through this transformation.
|
|
10
|
+
*/
|
|
11
|
+
rotation: Matrix3;
|
|
12
|
+
/**
|
|
13
|
+
* The position to apply through this transformation.
|
|
14
|
+
*/
|
|
15
|
+
position: Vector3;
|
|
16
|
+
/**
|
|
17
|
+
* The scale to apply through this transformation.
|
|
18
|
+
*/
|
|
19
|
+
scale: Vector3;
|
|
20
|
+
/**
|
|
21
|
+
* Construct a new {@linkcode Transformation}.
|
|
22
|
+
* @param rotation The rotation to apply through the transformation.
|
|
23
|
+
* @param position The position to apply through the transformation.
|
|
24
|
+
* @param scale The scale to apply through the transformation.
|
|
25
|
+
*/
|
|
26
|
+
constructor(rotation: Readonly<Matrix3>, position: Readonly<Vector3>, scale: Readonly<Vector3>);
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Matrix3 } from "./matrix3.js";
|
|
2
|
+
import { Vector3 } from "./vector3.js";
|
|
3
|
+
/**
|
|
4
|
+
* Encapsulates an entire transformation, including rotation, position, and scale.
|
|
5
|
+
* @group Math
|
|
6
|
+
*/
|
|
7
|
+
export class Transformation {
|
|
8
|
+
/**
|
|
9
|
+
* The rotation to apply through this transformation.
|
|
10
|
+
*/
|
|
11
|
+
rotation;
|
|
12
|
+
/**
|
|
13
|
+
* The position to apply through this transformation.
|
|
14
|
+
*/
|
|
15
|
+
position;
|
|
16
|
+
/**
|
|
17
|
+
* The scale to apply through this transformation.
|
|
18
|
+
*/
|
|
19
|
+
scale;
|
|
20
|
+
/**
|
|
21
|
+
* Construct a new {@linkcode Transformation}.
|
|
22
|
+
* @param rotation The rotation to apply through the transformation.
|
|
23
|
+
* @param position The position to apply through the transformation.
|
|
24
|
+
* @param scale The scale to apply through the transformation.
|
|
25
|
+
*/
|
|
26
|
+
constructor(rotation, position, scale) {
|
|
27
|
+
this.rotation = Matrix3.fromMatrix3(rotation);
|
|
28
|
+
this.position = Vector3.fromVector3(position);
|
|
29
|
+
this.scale = Vector3.fromVector3(scale);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=transformation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation.js","sourceRoot":"","sources":["../../source/math/transformation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB;;OAEG;IACH,QAAQ,CAAU;IAElB;;OAEG;IACH,QAAQ,CAAU;IAElB;;OAEG;IACH,KAAK,CAAU;IAEf;;;;;OAKG;IACH,YAAY,QAA2B,EAAE,QAA2B,EAAE,KAAwB;QAC5F,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
package/lib/math/vector2.d.ts
CHANGED
|
@@ -17,12 +17,18 @@ export declare class Vector2 {
|
|
|
17
17
|
* @param y The Y component.
|
|
18
18
|
*/
|
|
19
19
|
constructor(x: number, y: number);
|
|
20
|
+
/**
|
|
21
|
+
* Creates a copy of another {@linkcode Vector2}.
|
|
22
|
+
* @param vector The vector to copy.
|
|
23
|
+
* @returns A new vector.
|
|
24
|
+
*/
|
|
25
|
+
static fromVector2(vector: Readonly<Vector2>): Vector2;
|
|
20
26
|
/**
|
|
21
27
|
* Sets the vector to new coordinates.
|
|
22
28
|
* @param vector The coordinates to set the vector to.
|
|
23
29
|
* @returns This instance.
|
|
24
30
|
*/
|
|
25
|
-
set(vector: Vector2): this;
|
|
31
|
+
set(vector: Readonly<Vector2>): this;
|
|
26
32
|
/**
|
|
27
33
|
* Sets the vector to new coordinates.
|
|
28
34
|
* @param x The new X component for the vector.
|
|
@@ -35,7 +41,7 @@ export declare class Vector2 {
|
|
|
35
41
|
* @param vector The vector to add to this vector.
|
|
36
42
|
* @returns This instance.
|
|
37
43
|
*/
|
|
38
|
-
add(vector: Vector2): this;
|
|
44
|
+
add(vector: Readonly<Vector2>): this;
|
|
39
45
|
/**
|
|
40
46
|
* Adds another vector to this vector.
|
|
41
47
|
* @param x The value to add to the X component.
|
|
@@ -49,7 +55,7 @@ export declare class Vector2 {
|
|
|
49
55
|
* @param scale The scaling to apply to the input vector.
|
|
50
56
|
* @returns This instance.
|
|
51
57
|
*/
|
|
52
|
-
addMultiply(vector: Vector2
|
|
58
|
+
addMultiply(vector: Readonly<Vector2>, scale: number): this;
|
|
53
59
|
/**
|
|
54
60
|
* Scales another vector and adds it to this vector.
|
|
55
61
|
* @param x The value to add to the X component.
|
|
@@ -59,13 +65,13 @@ export declare class Vector2 {
|
|
|
59
65
|
*/
|
|
60
66
|
addMultiplyXY(x: number, y: number, scale: number): this;
|
|
61
67
|
/**
|
|
62
|
-
* Subtracts another vector
|
|
68
|
+
* Subtracts another vector from this vector.
|
|
63
69
|
* @param vector The vector to subtract from this vector.
|
|
64
70
|
* @returns This instance.
|
|
65
71
|
*/
|
|
66
|
-
subtract(vector: Vector2): this;
|
|
72
|
+
subtract(vector: Readonly<Vector2>): this;
|
|
67
73
|
/**
|
|
68
|
-
* Subtracts another vector
|
|
74
|
+
* Subtracts another vector from this vector.
|
|
69
75
|
* @param x The value to subtract from the X component.
|
|
70
76
|
* @param y The value to subtract from the Y component.
|
|
71
77
|
* @returns This instance.
|
|
@@ -76,7 +82,7 @@ export declare class Vector2 {
|
|
|
76
82
|
* @param vector The vector to multiply with this vector.
|
|
77
83
|
* @returns This instance.
|
|
78
84
|
*/
|
|
79
|
-
multiply(vector: Vector2): this;
|
|
85
|
+
multiply(vector: Readonly<Vector2>): this;
|
|
80
86
|
/**
|
|
81
87
|
* Multiplies this vector by another vector.
|
|
82
88
|
* @param x The value to multiply with the X component.
|
|
@@ -95,7 +101,7 @@ export declare class Vector2 {
|
|
|
95
101
|
* @param vector The vector to divide this vector with.
|
|
96
102
|
* @returns This instance.
|
|
97
103
|
*/
|
|
98
|
-
divide(vector: Vector2): this;
|
|
104
|
+
divide(vector: Readonly<Vector2>): this;
|
|
99
105
|
/**
|
|
100
106
|
* Divides this vector by another vector.
|
|
101
107
|
* @param x The value to divide the X component with.
|
|
@@ -110,7 +116,7 @@ export declare class Vector2 {
|
|
|
110
116
|
*/
|
|
111
117
|
divideScale(scale: number): this;
|
|
112
118
|
/**
|
|
113
|
-
* Inverts the
|
|
119
|
+
* Inverts the direction of the vector.
|
|
114
120
|
* @returns This instance.
|
|
115
121
|
*/
|
|
116
122
|
invertAdd(): this;
|
|
@@ -160,7 +166,7 @@ export declare class Vector2 {
|
|
|
160
166
|
* @param vector The other vector.
|
|
161
167
|
* @returns The dot product between the two vectors.
|
|
162
168
|
*/
|
|
163
|
-
dot(vector: Vector2): number;
|
|
169
|
+
dot(vector: Readonly<Vector2>): number;
|
|
164
170
|
/**
|
|
165
171
|
* Returns the dot product between two vectors.
|
|
166
172
|
* @param x The X component of the other vector.
|
|
@@ -181,7 +187,7 @@ export declare class Vector2 {
|
|
|
181
187
|
* @returns A new {@linkcode Vector2}.
|
|
182
188
|
* @group Math
|
|
183
189
|
*/
|
|
184
|
-
export declare const addVector2: (a: Vector2
|
|
190
|
+
export declare const addVector2: (a: Readonly<Vector2>, b: Readonly<Vector2>) => Vector2;
|
|
185
191
|
/**
|
|
186
192
|
* Multiplies two vectors and returns a new vector with the result.
|
|
187
193
|
* @param a The first input vector.
|
|
@@ -189,7 +195,7 @@ export declare const addVector2: (a: Vector2, b: Vector2) => Vector2;
|
|
|
189
195
|
* @returns A new {@linkcode Vector2}.
|
|
190
196
|
* @group Math
|
|
191
197
|
*/
|
|
192
|
-
export declare const multiplyVector2: (a: Vector2
|
|
198
|
+
export declare const multiplyVector2: (a: Readonly<Vector2>, b: Readonly<Vector2>) => Vector2;
|
|
193
199
|
/**
|
|
194
200
|
* Subtracts two vectors and returns a new vector with the result.
|
|
195
201
|
* @param a The first input vector.
|
|
@@ -197,4 +203,4 @@ export declare const multiplyVector2: (a: Vector2, b: Vector2) => Vector2;
|
|
|
197
203
|
* @returns A new {@linkcode Vector2}.
|
|
198
204
|
* @group Math
|
|
199
205
|
*/
|
|
200
|
-
export declare const subtractVector2: (a: Vector2
|
|
206
|
+
export declare const subtractVector2: (a: Readonly<Vector2>, b: Readonly<Vector2>) => Vector2;
|
package/lib/math/vector2.js
CHANGED
|
@@ -20,6 +20,14 @@ export class Vector2 {
|
|
|
20
20
|
this.x = x;
|
|
21
21
|
this.y = y;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a copy of another {@linkcode Vector2}.
|
|
25
|
+
* @param vector The vector to copy.
|
|
26
|
+
* @returns A new vector.
|
|
27
|
+
*/
|
|
28
|
+
static fromVector2(vector) {
|
|
29
|
+
return new Vector2(vector.x, vector.y);
|
|
30
|
+
}
|
|
23
31
|
/**
|
|
24
32
|
* Sets the vector to new coordinates.
|
|
25
33
|
* @param vector The coordinates to set the vector to.
|
|
@@ -80,7 +88,7 @@ export class Vector2 {
|
|
|
80
88
|
return this;
|
|
81
89
|
}
|
|
82
90
|
/**
|
|
83
|
-
* Subtracts another vector
|
|
91
|
+
* Subtracts another vector from this vector.
|
|
84
92
|
* @param vector The vector to subtract from this vector.
|
|
85
93
|
* @returns This instance.
|
|
86
94
|
*/
|
|
@@ -88,7 +96,7 @@ export class Vector2 {
|
|
|
88
96
|
return this.subtractXY(vector.x, vector.y);
|
|
89
97
|
}
|
|
90
98
|
/**
|
|
91
|
-
* Subtracts another vector
|
|
99
|
+
* Subtracts another vector from this vector.
|
|
92
100
|
* @param x The value to subtract from the X component.
|
|
93
101
|
* @param y The value to subtract from the Y component.
|
|
94
102
|
* @returns This instance.
|
|
@@ -157,7 +165,7 @@ export class Vector2 {
|
|
|
157
165
|
return this;
|
|
158
166
|
}
|
|
159
167
|
/**
|
|
160
|
-
* Inverts the
|
|
168
|
+
* Inverts the direction of the vector.
|
|
161
169
|
* @returns This instance.
|
|
162
170
|
*/
|
|
163
171
|
invertAdd() {
|
|
@@ -230,7 +238,7 @@ export class Vector2 {
|
|
|
230
238
|
* @returns This instance.
|
|
231
239
|
*/
|
|
232
240
|
lerp(vector, t) {
|
|
233
|
-
const tn = 1
|
|
241
|
+
const tn = 1 - t;
|
|
234
242
|
this.x = this.x * tn + vector.x * t;
|
|
235
243
|
this.y = this.y * tn + vector.y * t;
|
|
236
244
|
return this;
|
package/lib/math/vector2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector2.js","sourceRoot":"","sources":["../../source/math/vector2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,OAAO;IAClB;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;;;OAIG;IACH,YAAY,CAAS,EAAE,CAAS;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"vector2.js","sourceRoot":"","sources":["../../source/math/vector2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,OAAO;IAClB;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;;;OAIG;IACH,YAAY,CAAS,EAAE,CAAS;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC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