@casual-simulation/aux-common 3.0.10 → 3.0.11

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 (46) hide show
  1. package/aux-format-2/AuxCausalTree2.js +40 -5
  2. package/aux-format-2/AuxCausalTree2.js.map +1 -1
  3. package/bots/Bot.d.ts +8 -0
  4. package/bots/Bot.js +10 -0
  5. package/bots/Bot.js.map +1 -1
  6. package/bots/BotCalculations.d.ts +46 -6
  7. package/bots/BotCalculations.js +171 -14
  8. package/bots/BotCalculations.js.map +1 -1
  9. package/bots/test/BotCalculationContextTests.js +58 -6
  10. package/bots/test/BotCalculationContextTests.js.map +1 -1
  11. package/bots/test/BotTestHelpers.d.ts +4 -0
  12. package/bots/test/BotTestHelpers.js +67 -0
  13. package/bots/test/BotTestHelpers.js.map +1 -1
  14. package/math/Quaternion.d.ts +94 -0
  15. package/math/Quaternion.js +128 -0
  16. package/math/Quaternion.js.map +1 -0
  17. package/math/Rotation.d.ts +274 -0
  18. package/math/Rotation.js +378 -0
  19. package/math/Rotation.js.map +1 -0
  20. package/math/Vector2.d.ts +251 -0
  21. package/math/Vector2.js +287 -0
  22. package/math/Vector2.js.map +1 -0
  23. package/math/Vector3.d.ts +318 -0
  24. package/math/Vector3.js +370 -0
  25. package/math/Vector3.js.map +1 -0
  26. package/math/index.d.ts +5 -0
  27. package/math/index.js +5 -0
  28. package/math/index.js.map +1 -0
  29. package/package.json +3 -3
  30. package/partitions/MemoryPartition.js +23 -4
  31. package/partitions/MemoryPartition.js.map +1 -1
  32. package/partitions/RemoteYjsPartition.js +8 -4
  33. package/partitions/RemoteYjsPartition.js.map +1 -1
  34. package/partitions/YjsPartition.js +8 -0
  35. package/partitions/YjsPartition.js.map +1 -1
  36. package/runtime/AuxLibrary.d.ts +15 -40
  37. package/runtime/AuxLibrary.js +165 -68
  38. package/runtime/AuxLibrary.js.map +1 -1
  39. package/runtime/AuxLibraryDefinitions.def +587 -10
  40. package/runtime/AuxRuntime.js +26 -1
  41. package/runtime/AuxRuntime.js.map +1 -1
  42. package/runtime/Utils.js +12 -4
  43. package/runtime/Utils.js.map +1 -1
  44. package/partitions/test/PartitionTests.d.ts +0 -8
  45. package/partitions/test/PartitionTests.js +0 -1548
  46. package/partitions/test/PartitionTests.js.map +0 -1
@@ -0,0 +1,378 @@
1
+ import { Quaternion } from './Quaternion';
2
+ import { Vector3 } from './Vector3';
3
+ /**
4
+ * Defines a class that can represent geometric rotations.
5
+ */
6
+ export class Rotation {
7
+ /**
8
+ * Creates a new rotation using the given parameters.
9
+ * @param rotation The information that should be used to construct the rotation.
10
+ *
11
+ * @example Create a rotation from an axis and angle.
12
+ * const rotation = new Rotation({
13
+ * axis: new Vector3(0, 0, 1),
14
+ * angle: Math.PI / 2
15
+ * }); // 90 degree rotation around Z axis
16
+ *
17
+ * @example Create a rotation from two vectors.
18
+ * const rotation = new Rotation({
19
+ * from: new Vector3(1, 0, 0),
20
+ * to: new Vector3(0, 1, 0)
21
+ * }); // Rotation that rotates (1, 0, 0) to (0, 1, 0)
22
+ *
23
+ * @example Create a rotation that looks along the X axis.
24
+ * const rotation = new Rotation({
25
+ * direction: new Vector3(1, 0, 0),
26
+ * upwards: new Vector3(0, 0, 1),
27
+ * errorHandling: 'nudge'
28
+ * });
29
+ *
30
+ * @example Tilt this bot forwards in the home dimension.
31
+ * tags.homeRotation = new Rotation({
32
+ * axis: new Vector3(1, 0, 0),
33
+ * angle: Math.PI / 6 // 30 degrees
34
+ * });
35
+ */
36
+ constructor(rotation) {
37
+ var _a, _b;
38
+ if (!rotation) {
39
+ this._q = new Quaternion(0, 0, 0, 1);
40
+ }
41
+ else if ('axis' in rotation) {
42
+ this._q = Rotation.quaternionFromAxisAndAngle(rotation);
43
+ }
44
+ else if ('from' in rotation) {
45
+ this._q = Rotation.quaternionFromTo(rotation);
46
+ }
47
+ else if ('quaternion' in rotation) {
48
+ const q = rotation.quaternion;
49
+ this._q = new Quaternion(q.x, q.y, q.z, q.w).normalize();
50
+ }
51
+ else if ('sequence' in rotation) {
52
+ let q = new Quaternion(0, 0, 0, 1);
53
+ for (let r of rotation.sequence) {
54
+ q = r.quaternion.multiply(q);
55
+ }
56
+ this._q = q;
57
+ }
58
+ else if ('euler' in rotation) {
59
+ let q = new Quaternion(0, 0, 0, 1);
60
+ let order = (_a = rotation.euler.order) !== null && _a !== void 0 ? _a : 'XYZ';
61
+ let extrinsic = (_b = rotation.euler.extrinsic) !== null && _b !== void 0 ? _b : false;
62
+ function combine(q, rotation) {
63
+ if (extrinsic) {
64
+ return rotation.multiply(q);
65
+ }
66
+ else {
67
+ return q.multiply(rotation);
68
+ }
69
+ }
70
+ for (let char of order) {
71
+ if (char === 'X' || char === 'x') {
72
+ q = combine(q, Rotation.quaternionFromAxisAndAngle({
73
+ axis: new Vector3(1, 0, 0),
74
+ angle: rotation.euler.x,
75
+ }));
76
+ }
77
+ else if (char === 'Y' || char === 'y') {
78
+ q = combine(q, Rotation.quaternionFromAxisAndAngle({
79
+ axis: new Vector3(0, 1, 0),
80
+ angle: rotation.euler.y,
81
+ }));
82
+ }
83
+ else if (char === 'Z' || char === 'z') {
84
+ q = combine(q, Rotation.quaternionFromAxisAndAngle({
85
+ axis: new Vector3(0, 0, 1),
86
+ angle: rotation.euler.z,
87
+ }));
88
+ }
89
+ }
90
+ this._q = q;
91
+ }
92
+ else if ('direction' in rotation) {
93
+ this._q = Rotation.quaternionLook(rotation);
94
+ }
95
+ else if (rotation instanceof Quaternion) {
96
+ this._q = rotation.normalize();
97
+ }
98
+ else {
99
+ this._q = new Quaternion(0, 0, 0, 1);
100
+ }
101
+ }
102
+ /**
103
+ * The quaternion that this rotation uses.
104
+ */
105
+ get quaternion() {
106
+ return this._q;
107
+ }
108
+ /**
109
+ * Constructs a new Quaternion from the given axis and angle.
110
+ * @param axisAndAngle The object that contains the axis and angle values.
111
+ */
112
+ static quaternionFromAxisAndAngle(axisAndAngle) {
113
+ const normalizedAxis = axisAndAngle.axis.normalize();
114
+ const sinAngle = Math.sin(axisAndAngle.angle / 2);
115
+ const cosAngle = Math.cos(axisAndAngle.angle / 2);
116
+ return new Quaternion(normalizedAxis.x * sinAngle, normalizedAxis.y * sinAngle, normalizedAxis.z * sinAngle, cosAngle);
117
+ }
118
+ /**
119
+ * Constructs a new Quaternion from the given from/to rotation.
120
+ * This is equivalent to calculating the cross product and angle between the two vectors and constructing an axis/angle quaternion.
121
+ * @param fromToRotation The object that contains the from and to values.
122
+ */
123
+ static quaternionFromTo(fromToRotation) {
124
+ const normalizedFrom = fromToRotation.from.normalize();
125
+ const normalizedTo = fromToRotation.to.normalize();
126
+ const cross = normalizedFrom.cross(normalizedTo);
127
+ const angle = Vector3.angleBetween(normalizedFrom, normalizedTo);
128
+ return Rotation.quaternionFromAxisAndAngle({
129
+ axis: cross,
130
+ angle,
131
+ });
132
+ }
133
+ /**
134
+ * Constructs a new Quaternion from the given look rotation.
135
+ * @param look The object that contains the look rotation values.
136
+ */
137
+ static quaternionLook(look) {
138
+ if (look.errorHandling !== 'error' && look.errorHandling !== 'nudge') {
139
+ throw new Error('The errorHandling property must be provided. It must be a string that contains either "error" or "nudge".');
140
+ }
141
+ if (look.direction.squareLength() < 0.0001) {
142
+ return new Quaternion();
143
+ }
144
+ let direction = look.direction;
145
+ let up = look.upwards;
146
+ const lookUpDot = direction.dot(up);
147
+ if (look.errorHandling === 'error') {
148
+ if (lookUpDot > 0.9998) {
149
+ throw new Error(`The up and direction vectors must not be the same when constructing a look rotation.\nThis is because vectors that are parallel don't have a valid cross product. (i.e. There are infinite vectors that are perpendicular to both)`);
150
+ }
151
+ else if (lookUpDot < -0.9998) {
152
+ throw new Error(`The up and direction vectors must not be opposites when constructing a look rotation.\nThis is because vectors that are parallel don't have a valid cross product. (i.e. There are infinite vectors that are perpendicular to both)`);
153
+ }
154
+ }
155
+ else {
156
+ if (Math.abs(up.z) === 1) {
157
+ direction = new Vector3(direction.x, direction.y, direction.z + 0.00001);
158
+ }
159
+ else {
160
+ direction = new Vector3(direction.x + 0.00001, direction.y, direction.z);
161
+ }
162
+ }
163
+ // Matrix version from:
164
+ // https://www.euclideanspace.com/maths/algebra/vectors/lookat/index.htm
165
+ // with changed order to use Y-up coordinate system
166
+ const y = direction.normalize();
167
+ const x = y.cross(up).normalize();
168
+ const z = x.cross(y);
169
+ const m00 = x.x;
170
+ const m01 = y.x;
171
+ const m02 = z.x;
172
+ const m10 = x.y;
173
+ const m11 = y.y;
174
+ const m12 = z.y;
175
+ const m20 = x.z;
176
+ const m21 = y.z;
177
+ const m22 = z.z;
178
+ // https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
179
+ const qw = Math.sqrt(Math.max(0, 1 + m00 + m11 + m22)) / 2;
180
+ let qx = copySign(m21 - m12, Math.sqrt(Math.max(0, 1 + m00 - m11 - m22)) / 2);
181
+ let qy = copySign(m02 - m20, Math.sqrt(Math.max(0, 1 - m00 + m11 - m22)) / 2);
182
+ let qz = copySign(m10 - m01, Math.sqrt(Math.max(0, 1 - m00 - m11 + m22)) / 2);
183
+ return new Quaternion(qx, qy, qz, qw);
184
+ }
185
+ /**
186
+ * Determines the angle between the two given quaternions and returns the result in radians.
187
+ * @param first The first quaternion. Must be a quaterion that represents a rotation
188
+ * @param second The second quaternion.
189
+ */
190
+ static angleBetween(first, second) {
191
+ const delta = first.quaternion.invert().multiply(second.quaternion);
192
+ return 2 * Math.acos(delta.w);
193
+ }
194
+ /**
195
+ * Constructs a new rotation that is the spherical linear interpolation between the given first and second rotations.
196
+ * The degree that the result is interpolated is determined by the given amount parameter.
197
+ * @param first The first rotation.
198
+ * @param second The second rotation.
199
+ * @param amount The amount that the resulting rotation should be interpolated between the first and second rotations. Values near 0 indicate rotations close to the first and values near 1 indicate rotations close to the second.
200
+ */
201
+ static interpolate(first, second, amount) {
202
+ const q1 = first.quaternion;
203
+ const q2 = second.quaternion;
204
+ const cosHalfTheta = q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z;
205
+ // if angle beween is 0 then we can simply return the first rotation
206
+ if (cosHalfTheta >= 1 || cosHalfTheta <= -1) {
207
+ return new Rotation(new Quaternion(q1.x, q1.y, q1.z, q1.w));
208
+ }
209
+ const sinHalfTheta = Math.sqrt(1 - cosHalfTheta * cosHalfTheta);
210
+ // If angle between is 180, then we can choose either axis normal to first or second.
211
+ if (Math.abs(sinHalfTheta) <= 0.001) {
212
+ return new Rotation(new Quaternion(q1.x * 0.5 + q2.x * 0.5, q1.y * 0.5 + q2.y * 0.5, q1.z * 0.5 + q2.z * 0.5, q1.w * 0.5 + q2.w * 0.5));
213
+ }
214
+ const halfTheta = Math.acos(cosHalfTheta);
215
+ const ratioA = Math.sin((1 - amount) * halfTheta) / sinHalfTheta;
216
+ const ratioB = Math.sin(amount * halfTheta) / sinHalfTheta;
217
+ return new Rotation(new Quaternion(q1.x * ratioA + q2.x * ratioB, q1.y * ratioA + q2.y * ratioB, q1.z * ratioA + q2.z * ratioB, q1.w * ratioA + q2.w * ratioB));
218
+ }
219
+ /**
220
+ * Rotates the given Vector3 by this quaternion and returns a new vector containing the result.
221
+ * @param vector The 3D vector that should be rotated.
222
+ *
223
+ * @example Apply a rotation to a Vector3 object.
224
+ * const rotation = new Rotation({
225
+ * axis: new Vector3(1, 0, 0),
226
+ * angle: Math.PI / 4
227
+ * }); // 45 degree rotation around X axis
228
+ *
229
+ * const point = new Vector3(1, 2, 0);
230
+ * const rotated = rotation.rotateVector3(point);
231
+ * os.toast(rotated);
232
+ */
233
+ rotateVector3(vector) {
234
+ // Multiplied out version of (q * vector * q^-1)
235
+ const q = this.quaternion;
236
+ return new Vector3(q.w * q.w * vector.x +
237
+ 2 * q.y * q.w * vector.z -
238
+ 2 * q.z * q.w * vector.y +
239
+ q.x * q.x * vector.x +
240
+ 2 * q.y * q.x * vector.y +
241
+ 2 * q.z * q.x * vector.z -
242
+ q.z * q.z * vector.x -
243
+ q.y * q.y * vector.x, 2 * q.x * q.y * vector.x +
244
+ q.y * q.y * vector.y +
245
+ 2 * q.z * q.y * vector.z +
246
+ 2 * q.w * q.z * vector.x -
247
+ q.z * q.z * vector.y +
248
+ q.w * q.w * vector.y -
249
+ 2 * q.x * q.w * vector.z -
250
+ q.x * q.x * vector.y, 2 * q.x * q.z * vector.x +
251
+ 2 * q.y * q.z * vector.y +
252
+ q.z * q.z * vector.z -
253
+ 2 * q.w * q.y * vector.x -
254
+ q.y * q.y * vector.z +
255
+ 2 * q.w * q.x * vector.y -
256
+ q.x * q.x * vector.z +
257
+ q.w * q.w * vector.z);
258
+ }
259
+ /**
260
+ * Rotates the given Vector2 by this quaternion and returns a new vector containing the result.
261
+ * Note that rotations around any other axis than (0, 0, 1) or (0, 0, -1) can produce results that contain a Z component.
262
+ * @param vector The 2D vector that should be rotated.
263
+ *
264
+ * @example Apply a rotation to a Vector2 object.
265
+ * const rotation = new Rotation({
266
+ * axis: new Vector3(1, 0, 0),
267
+ * angle: Math.PI / 4
268
+ * }); // 45 degree rotation around X axis
269
+ *
270
+ * const point = new Vector2(1, 2);
271
+ * const rotated = rotation.rotateVector2(point);
272
+ * os.toast(rotated);
273
+ */
274
+ rotateVector2(vector) {
275
+ return this.rotateVector3(new Vector3(vector.x, vector.y));
276
+ }
277
+ /**
278
+ * Combines this rotation with the other rotation and returns a new rotation that represents the combination of the two.
279
+ * @param other The other rotation.
280
+ *
281
+ * @example Combine two rotations together.
282
+ * const first = new Rotation({
283
+ * axis: new Vector3(1, 0, 0),
284
+ * angle: Math.PI / 4
285
+ * }); // 45 degree rotation around X axis
286
+ * const second = new Rotation({
287
+ * axis: new Vector3(1, 0, 0),
288
+ * angle: Math.PI / 4
289
+ * }); // 45 degree rotation around X axis
290
+ *
291
+ * const third = first.combineWith(second); // 90 degree rotation around X
292
+ *
293
+ * os.toast(third);
294
+ */
295
+ combineWith(other) {
296
+ return new Rotation(other.quaternion.multiply(this.quaternion));
297
+ }
298
+ /**
299
+ * Calculates the inverse rotation of this rotation and returns a new rotation with the result.
300
+ *
301
+ * @example Calculate the inverse of a rotation.
302
+ * const first = new Rotation({
303
+ * axis: new Vector3(1, 0, 0),
304
+ * angle: Math.PI / 4
305
+ * }); // 45 degree rotation around X axis
306
+ * const inverse = first.inverse();
307
+ *
308
+ * const result = first.combineWith(inverse);
309
+ *
310
+ * os.toast(result);
311
+ */
312
+ invert() {
313
+ return new Rotation(this._q.invert());
314
+ }
315
+ /**
316
+ * Gets the axis and angle that this rotation rotates around.
317
+ */
318
+ axisAndAngle() {
319
+ const halfAngle = Math.acos(this.quaternion.w);
320
+ const sinHalfAngle = Math.sin(halfAngle);
321
+ const x = this.quaternion.x / sinHalfAngle;
322
+ const y = this.quaternion.y / sinHalfAngle;
323
+ const z = this.quaternion.z / sinHalfAngle;
324
+ const angle = halfAngle * 2;
325
+ return {
326
+ axis: new Vector3(x, y, z),
327
+ angle: angle,
328
+ };
329
+ }
330
+ /**
331
+ * Determines if this rotation equals the other rotation.
332
+ * @param other The rotation to check.
333
+ */
334
+ equals(other) {
335
+ return this._q.equals(other === null || other === void 0 ? void 0 : other._q);
336
+ }
337
+ /**
338
+ * Converts this rotation to a human-readable string representation.
339
+ *
340
+ * @example Get a string of a rotation.
341
+ * const myRotation = new Rotation({
342
+ * axis: new Vector3(1, 0, 0),
343
+ * angle: Math.PI / 4
344
+ * }); // 45 degree rotation around X axis
345
+ * const rotationString = myRotation.toString();
346
+ *
347
+ * os.toast('My Rotation: ' + rotationString);
348
+ */
349
+ toString() {
350
+ const { axis, angle } = this.axisAndAngle();
351
+ const angleWithoutPi = angle / Math.PI;
352
+ if (angle === 0) {
353
+ return `Rotation(identity)`;
354
+ }
355
+ return `Rotation(axis: ${axis}, angle: Math.PI * ${angleWithoutPi})`;
356
+ }
357
+ }
358
+ /**
359
+ * Defines a constant that contains a rotation that, when combined with a rotation, converts a rotation in AUX coordinates to THREE.js coordinates.
360
+ */
361
+ export const AUX_ROTATION_TO_THREEJS = new Rotation({
362
+ axis: new Vector3(1, 0, 0),
363
+ angle: -Math.PI / 2,
364
+ });
365
+ /**
366
+ * Copies the sign from signGiver onto signTaker and returns the result.
367
+ * @param signGiver The number whose sign should be given to the other number.
368
+ * @param signTaker The number whose sign should be set.
369
+ */
370
+ export function copySign(signGiver, signTaker) {
371
+ if (Math.sign(signGiver) === Math.sign(signTaker)) {
372
+ return signTaker;
373
+ }
374
+ else {
375
+ return signTaker * -1;
376
+ }
377
+ }
378
+ //# sourceMappingURL=Rotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rotation.js","sourceRoot":"","sources":["Rotation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,QAAQ;IAUjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,YACI,QAOkB;;QAElB,IAAI,CAAC,QAAQ,EAAE;YACX,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;SACxC;aAAM,IAAI,MAAM,IAAI,QAAQ,EAAE;YAC3B,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC;SAC3D;aAAM,IAAI,MAAM,IAAI,QAAQ,EAAE;YAC3B,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;SACjD;aAAM,IAAI,YAAY,IAAI,QAAQ,EAAE;YACjC,MAAM,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC;YAC9B,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;SAC5D;aAAM,IAAI,U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AG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5C,MAAM,cAAc,GAAG,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC;QACvC,IAAI,KAAK,KAAK,CAAC,EAAE;YACb,OAAO,oBAAoB,CAAC;SAC/B;QACD,OAAO,kBAAkB,IAAI,sBAAsB,cAAc,GAAG,CAAC;IACzE,CAAC;CACJ;AAkHD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,QAAQ,CAAC;IAChD,IAAI,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1B,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAiB,EAAE,SAAiB;IACzD,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QAC/C,OAAO,SAAS,CAAC;KACpB;SAAM;QACH,OAAO,SAAS,GAAG,CAAC,CAAC,CAAC;KACzB;AACL,CAAC"}
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Defines a class that represents a 2D point in space.
3
+ */
4
+ export declare class Vector2 {
5
+ /**
6
+ * The X value of this vector.
7
+ */
8
+ x: number;
9
+ /**
10
+ * The Y value of this vector.
11
+ */
12
+ y: number;
13
+ /**
14
+ * Constructs a new 2D vector with the given X and Y values.
15
+ * @param x The X value of the vector.
16
+ * @param y The Y value of the vector.
17
+ *
18
+ * @example Create a new Vector2 object with the position (2, 3).
19
+ * let myVector = new Vector2(2, 3);
20
+ *
21
+ * os.toast(`X: ${myVector.x}, Y: ${myVector.y}`);
22
+ *
23
+ * @example Move this bot to (10, 15) in the home dimension.
24
+ * tags.homePosition = new Vector2(10, 15);
25
+ */
26
+ constructor(x?: number, y?: number);
27
+ /**
28
+ * Creates a 2D vector with the given X and Y values that is normalized immediately upon creation.
29
+ * @param x The X value of the vector.
30
+ * @param y The Y value of the vector.
31
+ *
32
+ * @example Create a normalized vector
33
+ * const vector = Vector2.createNormalized(1, 2);
34
+ */
35
+ static createNormalized(x: number, y: number): Vector2;
36
+ /**
37
+ * Calculates the angle between the two given vectors and returns the result in radians.
38
+ * @param first The first vector that should be used for comparision.
39
+ * @param second The second vector that should be used for comparision.
40
+ *
41
+ * @example Find the angle between two vectors.
42
+ * const first = new Vector2(
43
+ * Math.cos(Math.PI / 3),
44
+ * Math.sin(Math.PI / 3)
45
+ * ); // 60 degrees
46
+ * const second = new Vector2(
47
+ * Math.cos(Math.PI / 2),
48
+ * Math.sin(Math.PI / 2)
49
+ * ); // 90 degrees
50
+ *
51
+ * const angle = Vector2.angleBetween(first, second);
52
+ * os.toast(angle);
53
+ */
54
+ static angleBetween(first: Vector2, second: Vector2): number;
55
+ /**
56
+ * Calculates the distance between the two given vectors and returns the result.
57
+ * @param first The first vector that should be used for comparision.
58
+ * @param second The second vector that should be used for comparision.
59
+ *
60
+ * @example Find the distance between two vectors.
61
+ * const first = new Vector2(5, 10);
62
+ * const second = new Vector2(9, 2);
63
+ * const distance = Vector2.distanceBetween(first, second);
64
+ *
65
+ * os.toast(`Distance: ${distance}`);
66
+ */
67
+ static distanceBetween(first: Vector2, second: Vector2): number;
68
+ /**
69
+ * Constructs a new vector that is the linear interpolation between the given start and end positions.
70
+ * The degree that the result is interpolated is determined by the given amount parameter.
71
+ * @param start The start position.
72
+ * @param finish The end position.
73
+ * @param amount The amount that the resulting position should be interpolated between the start and end positions. Values near 0 indicate rotations close to the first and values near 1 indicate rotations close to the second.
74
+ *
75
+ * @example Find the position that is halfway between two vectors.
76
+ * const start = new Vector2(5, 10);
77
+ * const finish = new Vector2(9, 2);
78
+ * const halfway = Vector2.interpolatePosition(start, finish, 0.5);
79
+ *
80
+ * os.toast(halfway);
81
+ *
82
+ * @example Find the position that is 1/4 between two vectors.
83
+ * const start = new Vector2(5, 10);
84
+ * const finish = new Vector2(9, 2);
85
+ * const halfway = Vector2.interpolatePosition(start, finish, 0.25);
86
+ *
87
+ * os.toast(halfway);
88
+ */
89
+ static interpolatePosition(start: Vector2, finish: Vector2, amount: number): Vector2;
90
+ /**
91
+ * Constructs a new vector that is the directional linear interpolation between the given start and end positions.
92
+ * The degree that the result is interpolated is determined by the given amount parameter.
93
+ *
94
+ * This function works similarly to interpolatePosition(), except the result is always a normalized vector.
95
+ *
96
+ * @param start The start position.
97
+ * @param finish The end position.
98
+ * @param amount The amount that the resulting position should be interpolated between the start and end positions. Values near 0 indicate rotations close to the first and values near 1 indicate rotations close to the second.
99
+ *
100
+ * @example Find the direction that points halfway between the two vectors.
101
+ * const start = new Vector2(5, 10);
102
+ * const finish = new Vector2(9, 2);
103
+ * const halfway = Vector2.interpolatePosition(start, finish, 0.5);
104
+ *
105
+ * os.toast(halfway);
106
+ */
107
+ static interpolateDirection(start: Vector2, finish: Vector2, amount: number): Vector2;
108
+ /**
109
+ * Adds this vector with the other vector and returns the result.
110
+ * @param other The other vector to add with this vector.
111
+ *
112
+ * @example Add two vectors together.
113
+ * const first = new Vector2(1, 2);
114
+ * const second = new Vector2(3, 4);
115
+ * const added = first.add(second);
116
+ *
117
+ * os.toast(added); // Prints (4, 6)
118
+ */
119
+ add(other: Vector2): Vector2;
120
+ /**
121
+ * Subtracts the other vector from this vector and returns the result.
122
+ * @param other The other vector that should be subtracted from this vector.
123
+ *
124
+ * @example Subtract two vectors.
125
+ * const first = new Vector2(1, 2);
126
+ * const second = new Vector2(3, 4);
127
+ * const subtracted = first.subtract(second);
128
+ * os.toast(subtracted);
129
+ *
130
+ * @example Find the direction from one vector to another.
131
+ * const first = new Vector2(1, 2);
132
+ * const second = new Vector2(3, 4);
133
+ *
134
+ * const directionFromFirstToSecond = second.subtract(first);
135
+ * const directionFromSecondToFirst = first.subtract(second);
136
+ *
137
+ * os.toast(`first -> second = ${directionFromFirstToSecond}; second -> first = ${directionFromSecondToFirst}`);
138
+ */
139
+ subtract(other: Vector2): Vector2;
140
+ /**
141
+ * Multiplies each component of this vector by the given value and returns the result.
142
+ * @param scale The scale that should be applied to this vector.
143
+ *
144
+ * @example Scale a vector by 10.
145
+ * const myVector = new Vector2(1, 1);
146
+ * const scaled = myVector.multiplyScalar(10);
147
+ * os.toast(scaled); // Prints (10, 10)
148
+ */
149
+ multiplyScalar(scale: number): Vector2;
150
+ /**
151
+ * Multiplies this vector by the given other vector and returns the result.
152
+ * @param other The other vector to multiply with this vector.
153
+ *
154
+ * @example Multiply two vectors together.
155
+ * const first = new Vector2(1, 2);
156
+ * const second = new Vector2(3, 4);
157
+ * const multiplied = first.multiply(second);
158
+ *
159
+ * os.toast(multiplied); // Prints (3, 8)
160
+ */
161
+ multiply(other: Vector2): Vector2;
162
+ /**
163
+ * Calculates the dot product of this vector compared to the given other vector.
164
+ * Returns a number that is positive if the vectors point in the same direction,
165
+ * negative if they point in opposite directions, and zero if they are perpendicular.
166
+ * For normalized vectors, this value is clamped to 1 and -1.
167
+ * @param other The other vector to calculate the dot product with.
168
+ *
169
+ * @example Determine how two vectors are pointing towards/away from the same direction.
170
+ * const first = new Vector2(1, 2);
171
+ * const second = new Vector2(3, 4);
172
+ *
173
+ * const dot = first.dot(second);
174
+ * if (dot < 0) {
175
+ * os.toast("Vectors are pointing away from each other!");
176
+ * } else if (dot === 0) {
177
+ * os.toast("Vectors 90 degrees away from each other!");
178
+ * } else {
179
+ * os.toast("Vectors are pointing towards from each other!");
180
+ * }
181
+ */
182
+ dot(other: Vector2): number;
183
+ /**
184
+ * Calculates the length of this vector and returns the result.
185
+ *
186
+ * @example Get the length of the vector.
187
+ * const myVector = new Vector2(1, 2);
188
+ * const length = myVector.length();
189
+ *
190
+ * os.toast(`Vector is ${length} units long`);
191
+ */
192
+ length(): number;
193
+ /**
194
+ * Calculates the square length of this vector and returns the result.
195
+ * This is equivalent to length^2, but it is faster to calculate than length because it doesn't require
196
+ * calculating a square root.
197
+ *
198
+ * @example Get the square length of the vector.
199
+ * const myVector = new Vector2(1, 2);
200
+ * const length = myVector.squareLength();
201
+ *
202
+ * os.toast(`Vector is ${length}^2 units long`);
203
+ */
204
+ squareLength(): number;
205
+ /**
206
+ * Calculates the normalized version of this vector and returns it.
207
+ * A normalized vector is a vector whose length equals 1.
208
+ *
209
+ * Normalizing a vector preserves its directionality while making the length (i.e. scale) of it 1.
210
+ *
211
+ * @example Normalize a vector.
212
+ * const myVector = new Vector2(1, 2);
213
+ * const normalized = myVector.normalize();
214
+ *
215
+ * os.toast(`Vector: ${myVector}, Normalized: ${normalized}`);
216
+ */
217
+ normalize(): Vector2;
218
+ /**
219
+ * Negates each component of this vector and returns a new vector that contains the result.
220
+ *
221
+ * @example Negate a vector.
222
+ * const myVector = new Vector2(1, 2);
223
+ * const negated = myVector.negate();
224
+ *
225
+ * os.toast(`Vector: ${myVector}, Negated: ${negated}`);
226
+ */
227
+ negate(): Vector2;
228
+ /**
229
+ * Converts this vector to a human-readable string representation.
230
+ *
231
+ * @example Get a string of a vector.
232
+ * const myVector = new Vector2(1, 2);
233
+ * const vectorString = myVector.toString();
234
+ *
235
+ * os.toast('My Vector: ' + vectorString);
236
+ */
237
+ toString(): string;
238
+ /**
239
+ * Determines if this vector equals the other vector.
240
+ * @param other The other vector.
241
+ *
242
+ * @example Determine if two vectors represent the same value.
243
+ * const first = new Vector2(1, 2);
244
+ * const second = new Vector2(3, 4);
245
+ * const third = new Vector2(1, 2);
246
+ *
247
+ * os.toast(`first == second: ${first.equals(second)}; first == third: ${first.equals(third)}`)
248
+ */
249
+ equals(other: Vector2): boolean;
250
+ }
251
+ //# sourceMappingURL=Vector2.d.ts.map