@casual-simulation/aux-common 3.0.9 → 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.
- package/aux-format-2/AuxCausalTree2.js +40 -5
- package/aux-format-2/AuxCausalTree2.js.map +1 -1
- package/bots/Bot.d.ts +8 -0
- package/bots/Bot.js +10 -0
- package/bots/Bot.js.map +1 -1
- package/bots/BotCalculations.d.ts +46 -6
- package/bots/BotCalculations.js +171 -14
- package/bots/BotCalculations.js.map +1 -1
- package/bots/BotEvents.d.ts +108 -22
- package/bots/BotEvents.js +56 -25
- package/bots/BotEvents.js.map +1 -1
- package/bots/test/BotCalculationContextTests.js +58 -6
- package/bots/test/BotCalculationContextTests.js.map +1 -1
- package/bots/test/BotTestHelpers.d.ts +4 -0
- package/bots/test/BotTestHelpers.js +67 -0
- package/bots/test/BotTestHelpers.js.map +1 -1
- package/math/Quaternion.d.ts +94 -0
- package/math/Quaternion.js +128 -0
- package/math/Quaternion.js.map +1 -0
- package/math/Rotation.d.ts +274 -0
- package/math/Rotation.js +378 -0
- package/math/Rotation.js.map +1 -0
- package/math/Vector2.d.ts +251 -0
- package/math/Vector2.js +287 -0
- package/math/Vector2.js.map +1 -0
- package/math/Vector3.d.ts +318 -0
- package/math/Vector3.js +370 -0
- package/math/Vector3.js.map +1 -0
- package/math/index.d.ts +5 -0
- package/math/index.js +5 -0
- package/math/index.js.map +1 -0
- package/package.json +4 -4
- package/partitions/MemoryPartition.js +23 -4
- package/partitions/MemoryPartition.js.map +1 -1
- package/partitions/RemoteYjsPartition.js +8 -4
- package/partitions/RemoteYjsPartition.js.map +1 -1
- package/partitions/YjsPartition.js +8 -0
- package/partitions/YjsPartition.js.map +1 -1
- package/runtime/AuxLibrary.d.ts +21 -44
- package/runtime/AuxLibrary.js +278 -95
- package/runtime/AuxLibrary.js.map +1 -1
- package/runtime/AuxLibraryDefinitions.def +642 -20
- package/runtime/AuxRuntime.js +26 -1
- package/runtime/AuxRuntime.js.map +1 -1
- package/runtime/Utils.js +12 -4
- package/runtime/Utils.js.map +1 -1
- package/partitions/test/PartitionTests.d.ts +0 -8
- package/partitions/test/PartitionTests.js +0 -1548
- package/partitions/test/PartitionTests.js.map +0 -1
package/math/Vector2.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a class that represents a 2D point in space.
|
|
3
|
+
*/
|
|
4
|
+
export class Vector2 {
|
|
5
|
+
/**
|
|
6
|
+
* Constructs a new 2D vector with the given X and Y values.
|
|
7
|
+
* @param x The X value of the vector.
|
|
8
|
+
* @param y The Y value of the vector.
|
|
9
|
+
*
|
|
10
|
+
* @example Create a new Vector2 object with the position (2, 3).
|
|
11
|
+
* let myVector = new Vector2(2, 3);
|
|
12
|
+
*
|
|
13
|
+
* os.toast(`X: ${myVector.x}, Y: ${myVector.y}`);
|
|
14
|
+
*
|
|
15
|
+
* @example Move this bot to (10, 15) in the home dimension.
|
|
16
|
+
* tags.homePosition = new Vector2(10, 15);
|
|
17
|
+
*/
|
|
18
|
+
constructor(x = 0, y = 0) {
|
|
19
|
+
this.x = x;
|
|
20
|
+
this.y = y;
|
|
21
|
+
Object.freeze(this);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a 2D vector with the given X and Y values that is normalized immediately upon creation.
|
|
25
|
+
* @param x The X value of the vector.
|
|
26
|
+
* @param y The Y value of the vector.
|
|
27
|
+
*
|
|
28
|
+
* @example Create a normalized vector
|
|
29
|
+
* const vector = Vector2.createNormalized(1, 2);
|
|
30
|
+
*/
|
|
31
|
+
static createNormalized(x, y) {
|
|
32
|
+
const length = Math.sqrt(x * x + y * y);
|
|
33
|
+
return new Vector2(x / length, y / length);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Calculates the angle between the two given vectors and returns the result in radians.
|
|
37
|
+
* @param first The first vector that should be used for comparision.
|
|
38
|
+
* @param second The second vector that should be used for comparision.
|
|
39
|
+
*
|
|
40
|
+
* @example Find the angle between two vectors.
|
|
41
|
+
* const first = new Vector2(
|
|
42
|
+
* Math.cos(Math.PI / 3),
|
|
43
|
+
* Math.sin(Math.PI / 3)
|
|
44
|
+
* ); // 60 degrees
|
|
45
|
+
* const second = new Vector2(
|
|
46
|
+
* Math.cos(Math.PI / 2),
|
|
47
|
+
* Math.sin(Math.PI / 2)
|
|
48
|
+
* ); // 90 degrees
|
|
49
|
+
*
|
|
50
|
+
* const angle = Vector2.angleBetween(first, second);
|
|
51
|
+
* os.toast(angle);
|
|
52
|
+
*/
|
|
53
|
+
static angleBetween(first, second) {
|
|
54
|
+
const dot = first.dot(second);
|
|
55
|
+
const l1 = first.length();
|
|
56
|
+
const l2 = second.length();
|
|
57
|
+
return Math.acos(dot / (l1 * l2));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Calculates the distance between the two given vectors and returns the result.
|
|
61
|
+
* @param first The first vector that should be used for comparision.
|
|
62
|
+
* @param second The second vector that should be used for comparision.
|
|
63
|
+
*
|
|
64
|
+
* @example Find the distance between two vectors.
|
|
65
|
+
* const first = new Vector2(5, 10);
|
|
66
|
+
* const second = new Vector2(9, 2);
|
|
67
|
+
* const distance = Vector2.distanceBetween(first, second);
|
|
68
|
+
*
|
|
69
|
+
* os.toast(`Distance: ${distance}`);
|
|
70
|
+
*/
|
|
71
|
+
static distanceBetween(first, second) {
|
|
72
|
+
const direction = second.subtract(first);
|
|
73
|
+
return direction.length();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Constructs a new vector that is the linear interpolation between the given start and end positions.
|
|
77
|
+
* The degree that the result is interpolated is determined by the given amount parameter.
|
|
78
|
+
* @param start The start position.
|
|
79
|
+
* @param finish The end position.
|
|
80
|
+
* @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.
|
|
81
|
+
*
|
|
82
|
+
* @example Find the position that is halfway 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.5);
|
|
86
|
+
*
|
|
87
|
+
* os.toast(halfway);
|
|
88
|
+
*
|
|
89
|
+
* @example Find the position that is 1/4 between two vectors.
|
|
90
|
+
* const start = new Vector2(5, 10);
|
|
91
|
+
* const finish = new Vector2(9, 2);
|
|
92
|
+
* const halfway = Vector2.interpolatePosition(start, finish, 0.25);
|
|
93
|
+
*
|
|
94
|
+
* os.toast(halfway);
|
|
95
|
+
*/
|
|
96
|
+
static interpolatePosition(start, finish, amount) {
|
|
97
|
+
const dir = finish.subtract(start);
|
|
98
|
+
const lerp = dir.multiplyScalar(amount);
|
|
99
|
+
return start.add(lerp);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Constructs a new vector that is the directional linear interpolation between the given start and end positions.
|
|
103
|
+
* The degree that the result is interpolated is determined by the given amount parameter.
|
|
104
|
+
*
|
|
105
|
+
* This function works similarly to interpolatePosition(), except the result is always a normalized vector.
|
|
106
|
+
*
|
|
107
|
+
* @param start The start position.
|
|
108
|
+
* @param finish The end position.
|
|
109
|
+
* @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.
|
|
110
|
+
*
|
|
111
|
+
* @example Find the direction that points halfway between the two vectors.
|
|
112
|
+
* const start = new Vector2(5, 10);
|
|
113
|
+
* const finish = new Vector2(9, 2);
|
|
114
|
+
* const halfway = Vector2.interpolatePosition(start, finish, 0.5);
|
|
115
|
+
*
|
|
116
|
+
* os.toast(halfway);
|
|
117
|
+
*/
|
|
118
|
+
static interpolateDirection(start, finish, amount) {
|
|
119
|
+
return Vector2.interpolatePosition(start, finish, amount).normalize();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Adds this vector with the other vector and returns the result.
|
|
123
|
+
* @param other The other vector to add with this vector.
|
|
124
|
+
*
|
|
125
|
+
* @example Add two vectors together.
|
|
126
|
+
* const first = new Vector2(1, 2);
|
|
127
|
+
* const second = new Vector2(3, 4);
|
|
128
|
+
* const added = first.add(second);
|
|
129
|
+
*
|
|
130
|
+
* os.toast(added); // Prints (4, 6)
|
|
131
|
+
*/
|
|
132
|
+
add(other) {
|
|
133
|
+
return new Vector2(this.x + other.x, this.y + other.y);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Subtracts the other vector from this vector and returns the result.
|
|
137
|
+
* @param other The other vector that should be subtracted from this vector.
|
|
138
|
+
*
|
|
139
|
+
* @example Subtract two vectors.
|
|
140
|
+
* const first = new Vector2(1, 2);
|
|
141
|
+
* const second = new Vector2(3, 4);
|
|
142
|
+
* const subtracted = first.subtract(second);
|
|
143
|
+
* os.toast(subtracted);
|
|
144
|
+
*
|
|
145
|
+
* @example Find the direction from one vector to another.
|
|
146
|
+
* const first = new Vector2(1, 2);
|
|
147
|
+
* const second = new Vector2(3, 4);
|
|
148
|
+
*
|
|
149
|
+
* const directionFromFirstToSecond = second.subtract(first);
|
|
150
|
+
* const directionFromSecondToFirst = first.subtract(second);
|
|
151
|
+
*
|
|
152
|
+
* os.toast(`first -> second = ${directionFromFirstToSecond}; second -> first = ${directionFromSecondToFirst}`);
|
|
153
|
+
*/
|
|
154
|
+
subtract(other) {
|
|
155
|
+
return new Vector2(this.x - other.x, this.y - other.y);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Multiplies each component of this vector by the given value and returns the result.
|
|
159
|
+
* @param scale The scale that should be applied to this vector.
|
|
160
|
+
*
|
|
161
|
+
* @example Scale a vector by 10.
|
|
162
|
+
* const myVector = new Vector2(1, 1);
|
|
163
|
+
* const scaled = myVector.multiplyScalar(10);
|
|
164
|
+
* os.toast(scaled); // Prints (10, 10)
|
|
165
|
+
*/
|
|
166
|
+
multiplyScalar(scale) {
|
|
167
|
+
return new Vector2(this.x * scale, this.y * scale);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Multiplies this vector by the given other vector and returns the result.
|
|
171
|
+
* @param other The other vector to multiply with this vector.
|
|
172
|
+
*
|
|
173
|
+
* @example Multiply two vectors together.
|
|
174
|
+
* const first = new Vector2(1, 2);
|
|
175
|
+
* const second = new Vector2(3, 4);
|
|
176
|
+
* const multiplied = first.multiply(second);
|
|
177
|
+
*
|
|
178
|
+
* os.toast(multiplied); // Prints (3, 8)
|
|
179
|
+
*/
|
|
180
|
+
multiply(other) {
|
|
181
|
+
return new Vector2(this.x * other.x, this.y * other.y);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Calculates the dot product of this vector compared to the given other vector.
|
|
185
|
+
* Returns a number that is positive if the vectors point in the same direction,
|
|
186
|
+
* negative if they point in opposite directions, and zero if they are perpendicular.
|
|
187
|
+
* For normalized vectors, this value is clamped to 1 and -1.
|
|
188
|
+
* @param other The other vector to calculate the dot product with.
|
|
189
|
+
*
|
|
190
|
+
* @example Determine how two vectors are pointing towards/away from the same direction.
|
|
191
|
+
* const first = new Vector2(1, 2);
|
|
192
|
+
* const second = new Vector2(3, 4);
|
|
193
|
+
*
|
|
194
|
+
* const dot = first.dot(second);
|
|
195
|
+
* if (dot < 0) {
|
|
196
|
+
* os.toast("Vectors are pointing away from each other!");
|
|
197
|
+
* } else if (dot === 0) {
|
|
198
|
+
* os.toast("Vectors 90 degrees away from each other!");
|
|
199
|
+
* } else {
|
|
200
|
+
* os.toast("Vectors are pointing towards from each other!");
|
|
201
|
+
* }
|
|
202
|
+
*/
|
|
203
|
+
dot(other) {
|
|
204
|
+
return this.x * other.x + this.y * other.y;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Calculates the length of this vector and returns the result.
|
|
208
|
+
*
|
|
209
|
+
* @example Get the length of the vector.
|
|
210
|
+
* const myVector = new Vector2(1, 2);
|
|
211
|
+
* const length = myVector.length();
|
|
212
|
+
*
|
|
213
|
+
* os.toast(`Vector is ${length} units long`);
|
|
214
|
+
*/
|
|
215
|
+
length() {
|
|
216
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Calculates the square length of this vector and returns the result.
|
|
220
|
+
* This is equivalent to length^2, but it is faster to calculate than length because it doesn't require
|
|
221
|
+
* calculating a square root.
|
|
222
|
+
*
|
|
223
|
+
* @example Get the square length of the vector.
|
|
224
|
+
* const myVector = new Vector2(1, 2);
|
|
225
|
+
* const length = myVector.squareLength();
|
|
226
|
+
*
|
|
227
|
+
* os.toast(`Vector is ${length}^2 units long`);
|
|
228
|
+
*/
|
|
229
|
+
squareLength() {
|
|
230
|
+
return this.x * this.x + this.y * this.y;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Calculates the normalized version of this vector and returns it.
|
|
234
|
+
* A normalized vector is a vector whose length equals 1.
|
|
235
|
+
*
|
|
236
|
+
* Normalizing a vector preserves its directionality while making the length (i.e. scale) of it 1.
|
|
237
|
+
*
|
|
238
|
+
* @example Normalize a vector.
|
|
239
|
+
* const myVector = new Vector2(1, 2);
|
|
240
|
+
* const normalized = myVector.normalize();
|
|
241
|
+
*
|
|
242
|
+
* os.toast(`Vector: ${myVector}, Normalized: ${normalized}`);
|
|
243
|
+
*/
|
|
244
|
+
normalize() {
|
|
245
|
+
const length = this.length();
|
|
246
|
+
return new Vector2(this.x / length, this.y / length);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Negates each component of this vector and returns a new vector that contains the result.
|
|
250
|
+
*
|
|
251
|
+
* @example Negate a vector.
|
|
252
|
+
* const myVector = new Vector2(1, 2);
|
|
253
|
+
* const negated = myVector.negate();
|
|
254
|
+
*
|
|
255
|
+
* os.toast(`Vector: ${myVector}, Negated: ${negated}`);
|
|
256
|
+
*/
|
|
257
|
+
negate() {
|
|
258
|
+
return new Vector2(-this.x, -this.y);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Converts this vector to a human-readable string representation.
|
|
262
|
+
*
|
|
263
|
+
* @example Get a string of a vector.
|
|
264
|
+
* const myVector = new Vector2(1, 2);
|
|
265
|
+
* const vectorString = myVector.toString();
|
|
266
|
+
*
|
|
267
|
+
* os.toast('My Vector: ' + vectorString);
|
|
268
|
+
*/
|
|
269
|
+
toString() {
|
|
270
|
+
return `Vector2(${this.x}, ${this.y})`;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Determines if this vector equals the other vector.
|
|
274
|
+
* @param other The other vector.
|
|
275
|
+
*
|
|
276
|
+
* @example Determine if two vectors represent the same value.
|
|
277
|
+
* const first = new Vector2(1, 2);
|
|
278
|
+
* const second = new Vector2(3, 4);
|
|
279
|
+
* const third = new Vector2(1, 2);
|
|
280
|
+
*
|
|
281
|
+
* os.toast(`first == second: ${first.equals(second)}; first == third: ${first.equals(third)}`)
|
|
282
|
+
*/
|
|
283
|
+
equals(other) {
|
|
284
|
+
return this.x === other.x && this.y === other.y;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=Vector2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Vector2.js","sourceRoot":"","sources":["Vector2.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,OAAO;IAWhB;;;;;;;;;;;;OAYG;IACH,YAAY,IAAY,CAAC,EAAE,IAAY,CAAC;QACpC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAS,EAAE,CAAS;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACxC,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MA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C,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM;QACF,OAAO,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;;OAQG;IACH,QAAQ;QACJ,OAAO,WAAW,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAc;QACjB,OAAO,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;CACJ"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { Vector2 } from './Vector2';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a class that represents a 3D point in space.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Vector3 {
|
|
6
|
+
/**
|
|
7
|
+
* The X value of this vector.
|
|
8
|
+
*/
|
|
9
|
+
x: number;
|
|
10
|
+
/**
|
|
11
|
+
* The Y value of this vector.
|
|
12
|
+
*/
|
|
13
|
+
y: number;
|
|
14
|
+
/**
|
|
15
|
+
* The Z value of this vector.
|
|
16
|
+
*/
|
|
17
|
+
z: number;
|
|
18
|
+
/**
|
|
19
|
+
* Gets a new Vector2 that contains this vector's X and Y components.
|
|
20
|
+
*/
|
|
21
|
+
get xy(): Vector2;
|
|
22
|
+
/**
|
|
23
|
+
* Gets a new Vector2 that contains this vector's X and Z components.
|
|
24
|
+
*/
|
|
25
|
+
get xz(): Vector2;
|
|
26
|
+
/**
|
|
27
|
+
* Gets a new Vector2 that contains this vector's Y and Z components.
|
|
28
|
+
*/
|
|
29
|
+
get yz(): Vector2;
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a new 3D vector with the given X and Y values.
|
|
32
|
+
* @param x The X value of the vector.
|
|
33
|
+
* @param y The Y value of the vector.
|
|
34
|
+
* @param z The Z value of the vector.
|
|
35
|
+
*
|
|
36
|
+
* @example Create a new Vector3 object with the position (2, 3, 4).
|
|
37
|
+
* let myVector = new Vector3(2, 3, 4);
|
|
38
|
+
*
|
|
39
|
+
* os.toast(`X: ${myVector.x}, Y: ${myVector.y}, Z: ${myVector.z}`);
|
|
40
|
+
*
|
|
41
|
+
* @example Move this bot to (1, 2, 3) in the home dimension.
|
|
42
|
+
* tags.homePosition = new Vector3(1, 2, 3);
|
|
43
|
+
*/
|
|
44
|
+
constructor(x?: number, y?: number, z?: number);
|
|
45
|
+
/**
|
|
46
|
+
* Creates a 3D vector with the given X and Y values that is normalized immediately upon creation.
|
|
47
|
+
* @param x The X value of the vector.
|
|
48
|
+
* @param y The Y value of the vector.
|
|
49
|
+
* @param z The Z value of the vector.
|
|
50
|
+
*
|
|
51
|
+
* @example Create a normalized vector
|
|
52
|
+
* const vector = Vector3.createNormalized(1, 2, 3);
|
|
53
|
+
*/
|
|
54
|
+
static createNormalized(x: number, y: number, z: number): Vector3;
|
|
55
|
+
/**
|
|
56
|
+
* Calculates the angle between the two given vectors and returns the result in radians.
|
|
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 angle between two vectors.
|
|
61
|
+
* const first = new Vector3(
|
|
62
|
+
* Math.cos(Math.PI / 3),
|
|
63
|
+
* Math.sin(Math.PI / 3),
|
|
64
|
+
* 0,
|
|
65
|
+
* ); // 60 degrees
|
|
66
|
+
* const second = new Vector3(
|
|
67
|
+
* Math.cos(Math.PI / 2),
|
|
68
|
+
* Math.sin(Math.PI / 2),
|
|
69
|
+
* 0
|
|
70
|
+
* ); // 90 degrees
|
|
71
|
+
*
|
|
72
|
+
* const angle = Vector3.angleBetween(first, second);
|
|
73
|
+
* os.toast(angle);
|
|
74
|
+
*/
|
|
75
|
+
static angleBetween(first: Vector3, second: Vector3): number;
|
|
76
|
+
/**
|
|
77
|
+
* Calculates the distance between the two given vectors and returns the result.
|
|
78
|
+
* @param first The first vector that should be used for comparision.
|
|
79
|
+
* @param second The second vector that should be used for comparision.
|
|
80
|
+
*
|
|
81
|
+
* @example Find the distance between two vectors.
|
|
82
|
+
* const first = new Vector3(5, 10, 3);
|
|
83
|
+
* const second = new Vector3(9, 2, 6);
|
|
84
|
+
* const distance = Vector3.distanceBetween(first, second);
|
|
85
|
+
*
|
|
86
|
+
* os.toast(`Distance: ${distance}`);
|
|
87
|
+
*/
|
|
88
|
+
static distanceBetween(first: Vector3, second: Vector3): number;
|
|
89
|
+
/**
|
|
90
|
+
* Constructs a new vector that is the linear interpolation between the given start and end positions.
|
|
91
|
+
* The degree that the result is interpolated is determined by the given amount parameter.
|
|
92
|
+
* @param start The start position.
|
|
93
|
+
* @param finish The end position.
|
|
94
|
+
* @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.
|
|
95
|
+
*
|
|
96
|
+
* @example Find the position that is halfway between two vectors.
|
|
97
|
+
* const start = new Vector3(5, 10, 15);
|
|
98
|
+
* const finish = new Vector3(9, 2, 6);
|
|
99
|
+
* const halfway = Vector3.interpolatePosition(start, finish, 0.5);
|
|
100
|
+
*
|
|
101
|
+
* os.toast(halfway);
|
|
102
|
+
*
|
|
103
|
+
* @example Find the position that is 1/4 between two vectors.
|
|
104
|
+
* const start = new Vector3(5, 10, 15);
|
|
105
|
+
* const finish = new Vector3(9, 2, 6);
|
|
106
|
+
* const halfway = Vector3.interpolatePosition(start, finish, 0.25);
|
|
107
|
+
*
|
|
108
|
+
* os.toast(halfway);
|
|
109
|
+
*/
|
|
110
|
+
static interpolatePosition(start: Vector3, finish: Vector3, amount: number): Vector3;
|
|
111
|
+
/**
|
|
112
|
+
* Constructs a new vector that is the directional linear interpolation between the given start and end positions.
|
|
113
|
+
* The degree that the result is interpolated is determined by the given amount parameter.
|
|
114
|
+
*
|
|
115
|
+
* This function works similarly to interpolatePosition(), except the result is always a normalized vector.
|
|
116
|
+
*
|
|
117
|
+
* @param start The start position.
|
|
118
|
+
* @param finish The end position.
|
|
119
|
+
* @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.
|
|
120
|
+
*
|
|
121
|
+
* @example Find the direction that points halfway between the two vectors.
|
|
122
|
+
* const start = new Vector3(5, 10, 16);
|
|
123
|
+
* const finish = new Vector3(9, 2, 6);
|
|
124
|
+
* const halfway = Vector3.interpolatePosition(start, finish, 0.5);
|
|
125
|
+
*
|
|
126
|
+
* os.toast(halfway);
|
|
127
|
+
*/
|
|
128
|
+
static interpolateDirection(start: Vector3, finish: Vector3, amount: number): Vector3;
|
|
129
|
+
/**
|
|
130
|
+
* Adds this vector with the other vector and returns the result.
|
|
131
|
+
* @param other The other vector to add with this vector.
|
|
132
|
+
*
|
|
133
|
+
* @example Add two vectors together.
|
|
134
|
+
* const first = new Vector3(1, 2, 3);
|
|
135
|
+
* const second = new Vector3(3, 4, 5);
|
|
136
|
+
* const added = first.add(second);
|
|
137
|
+
*
|
|
138
|
+
* os.toast(added); // Prints (4, 6, 8)
|
|
139
|
+
*/
|
|
140
|
+
add(other: Vector3): Vector3;
|
|
141
|
+
/**
|
|
142
|
+
* Subtracts the other vector from this vector and returns the result.
|
|
143
|
+
* @param other The other vector that should be subtracted from this vector.
|
|
144
|
+
*
|
|
145
|
+
* @example Subtract two vectors.
|
|
146
|
+
* const first = new Vector3(1, 2, 3);
|
|
147
|
+
* const second = new Vector3(3, 4, 5);
|
|
148
|
+
* const subtracted = first.subtract(second);
|
|
149
|
+
* os.toast(subtracted);
|
|
150
|
+
*
|
|
151
|
+
* @example Find the direction from one vector to another.
|
|
152
|
+
* const first = new Vector3(1, 2, 3);
|
|
153
|
+
* const second = new Vector3(3, 4, 5);
|
|
154
|
+
*
|
|
155
|
+
* const directionFromFirstToSecond = second.subtract(first);
|
|
156
|
+
* const directionFromSecondToFirst = first.subtract(second);
|
|
157
|
+
*
|
|
158
|
+
* os.toast(`first -> second = ${directionFromFirstToSecond}; second -> first = ${directionFromSecondToFirst}`);
|
|
159
|
+
*/
|
|
160
|
+
subtract(other: Vector3): Vector3;
|
|
161
|
+
/**
|
|
162
|
+
* Multiplies each component of this vector by the given value and returns the result.
|
|
163
|
+
* @param scale The scale that should be applied to this vector.
|
|
164
|
+
*
|
|
165
|
+
* @example Scale a vector by 10.
|
|
166
|
+
* const myVector = new Vector3(1, 1, 1);
|
|
167
|
+
* const scaled = myVector.multiplyScalar(10);
|
|
168
|
+
* os.toast(scaled); // Prints (10, 10, 10)
|
|
169
|
+
*/
|
|
170
|
+
multiplyScalar(scale: number): Vector3;
|
|
171
|
+
/**
|
|
172
|
+
* Multiplies this vector by the given other vector and returns the result.
|
|
173
|
+
* @param other The other vector to multiply with this vector.
|
|
174
|
+
*
|
|
175
|
+
* @example Multiply two vectors together.
|
|
176
|
+
* const first = new Vector3(1, 2, 3);
|
|
177
|
+
* const second = new Vector3(3, 4, 5);
|
|
178
|
+
* const multiplied = first.multiply(second);
|
|
179
|
+
*
|
|
180
|
+
* os.toast(multiplied); // Prints (3, 8, 15)
|
|
181
|
+
*/
|
|
182
|
+
multiply(other: Vector3): Vector3;
|
|
183
|
+
/**
|
|
184
|
+
* Calculates the dot product of this vector compared to the given other vector.
|
|
185
|
+
* Returns a number that is positive if the vectors point in the same direction,
|
|
186
|
+
* negative if they point in opposite directions, and zero if they are perpendicular.
|
|
187
|
+
* For normalized vectors, this value is clamped to 1 and -1.
|
|
188
|
+
* @param other The other vector to calculate the dot product with.
|
|
189
|
+
*
|
|
190
|
+
* @example Determine how two vectors are pointing towards/away from the same direction.
|
|
191
|
+
* const first = new Vector3(1, 2, 3);
|
|
192
|
+
* const second = new Vector3(3, 4, 5);
|
|
193
|
+
*
|
|
194
|
+
* const dot = first.dot(second);
|
|
195
|
+
* if (dot < 0) {
|
|
196
|
+
* os.toast("Vectors are pointing away from each other!");
|
|
197
|
+
* } else if (dot === 0) {
|
|
198
|
+
* os.toast("Vectors 90 degrees away from each other!");
|
|
199
|
+
* } else {
|
|
200
|
+
* os.toast("Vectors are pointing towards from each other!");
|
|
201
|
+
* }
|
|
202
|
+
*/
|
|
203
|
+
dot(other: Vector3): number;
|
|
204
|
+
/**
|
|
205
|
+
* Calculates the cross product of this vector with the given other vector.
|
|
206
|
+
* Returns a new vector that is perpendicular to both vectors.
|
|
207
|
+
* Note that the order of the vectors greatly matters. For example, (1, 0, 0).cross(0, 1, 0) === (0, 0, 1) but (0, 1, 0).cross(1, 0, 0) === (0, 0, -1).
|
|
208
|
+
* @param other The other vector to calculate the cross product with.
|
|
209
|
+
*
|
|
210
|
+
* @example Calculate a vector that is perpendicular to two vectors.
|
|
211
|
+
* const first = new Vector3(1, 0, 0);
|
|
212
|
+
* const second = new Vector3(0, 1, 0);
|
|
213
|
+
*
|
|
214
|
+
* const result = first.cross(second);
|
|
215
|
+
* os.toast(`Result: ${result}`); // Prints (0, 0, 1)
|
|
216
|
+
*/
|
|
217
|
+
cross(other: Vector3): Vector3;
|
|
218
|
+
/**
|
|
219
|
+
* Calculates the length of this vector and returns the result.
|
|
220
|
+
*
|
|
221
|
+
* @example Get the length of the vector.
|
|
222
|
+
* const myVector = new Vector3(1, 2, 3);
|
|
223
|
+
* const length = myVector.length();
|
|
224
|
+
*
|
|
225
|
+
* os.toast(`Vector is ${length} units long`);
|
|
226
|
+
*/
|
|
227
|
+
length(): number;
|
|
228
|
+
/**
|
|
229
|
+
* Calculates the square length of this vector and returns the result.
|
|
230
|
+
* This is equivalent to length^2, but it is faster to calculate than length because it doesn't require
|
|
231
|
+
* calculating a square root.
|
|
232
|
+
*
|
|
233
|
+
* @example Get the square length of the vector.
|
|
234
|
+
* const myVector = new Vector3(1, 2, 3);
|
|
235
|
+
* const length = myVector.squareLength();
|
|
236
|
+
*
|
|
237
|
+
* os.toast(`Vector is ${length}^2 units long`);
|
|
238
|
+
*/
|
|
239
|
+
squareLength(): number;
|
|
240
|
+
/**
|
|
241
|
+
* Calculates the normalized version of this vector and returns it.
|
|
242
|
+
* A normalized vector is a vector whose length equals 1.
|
|
243
|
+
*
|
|
244
|
+
* Normalizing a vector preserves its directionality while making the length (i.e. scale) of it 1.
|
|
245
|
+
*
|
|
246
|
+
* @example Normalize a vector.
|
|
247
|
+
* const myVector = new Vector3(1, 2, 3);
|
|
248
|
+
* const normalized = myVector.normalize();
|
|
249
|
+
*
|
|
250
|
+
* os.toast(`Vector: ${myVector}, Normalized: ${normalized}`);
|
|
251
|
+
*/
|
|
252
|
+
normalize(): Vector3;
|
|
253
|
+
/**
|
|
254
|
+
* Negates each component of this vector and returns a new vector that contains the result.
|
|
255
|
+
*
|
|
256
|
+
* @example Negate a vector.
|
|
257
|
+
* const myVector = new Vector3(1, 2, 3);
|
|
258
|
+
* const negated = myVector.negate();
|
|
259
|
+
*
|
|
260
|
+
* os.toast(`Vector: ${myVector}, Negated: ${negated}`);
|
|
261
|
+
*/
|
|
262
|
+
negate(): Vector3;
|
|
263
|
+
/**
|
|
264
|
+
* Converts this vector to a human-readable string representation.
|
|
265
|
+
*
|
|
266
|
+
* @example Get a string of a vector.
|
|
267
|
+
* const myVector = new Vector3(1, 2, 3);
|
|
268
|
+
* const vectorString = myVector.toString();
|
|
269
|
+
*
|
|
270
|
+
* os.toast('My Vector: ' + vectorString);
|
|
271
|
+
*/
|
|
272
|
+
toString(): string;
|
|
273
|
+
/**
|
|
274
|
+
* Determines if this vector equals the other vector.
|
|
275
|
+
* @param other The other value to compare to.
|
|
276
|
+
*
|
|
277
|
+
* @example Determine if two vectors represent the same value.
|
|
278
|
+
* const first = new Vector3(1, 2, 3);
|
|
279
|
+
* const second = new Vector3(3, 4, 5);
|
|
280
|
+
* const third = new Vector3(1, 2, 3);
|
|
281
|
+
*
|
|
282
|
+
* os.toast(`first == second: ${first.equals(second)}; first == third: ${first.equals(third)}`)
|
|
283
|
+
*/
|
|
284
|
+
equals(other: Vector3): boolean;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* A 3D vector that contains (0, 0, 0).
|
|
288
|
+
*/
|
|
289
|
+
export declare const ZERO: Vector3;
|
|
290
|
+
/**
|
|
291
|
+
* A 3D vector that contains (1, 1, 1).
|
|
292
|
+
*/
|
|
293
|
+
export declare const ONE: Vector3;
|
|
294
|
+
/**
|
|
295
|
+
* A 3D vector that contains (0, 1, 0).
|
|
296
|
+
*/
|
|
297
|
+
export declare const FORWARD: Vector3;
|
|
298
|
+
/**
|
|
299
|
+
* A 3D vector that contains (0, -1, 0).
|
|
300
|
+
*/
|
|
301
|
+
export declare const BACK: Vector3;
|
|
302
|
+
/**
|
|
303
|
+
* A 3D vector that contains (1, 0, 0).
|
|
304
|
+
*/
|
|
305
|
+
export declare const RIGHT: Vector3;
|
|
306
|
+
/**
|
|
307
|
+
* A 3D vector that contains (-1, 0, 0).
|
|
308
|
+
*/
|
|
309
|
+
export declare const LEFT: Vector3;
|
|
310
|
+
/**
|
|
311
|
+
* A 3D vector that contains (0, 0, 1).
|
|
312
|
+
*/
|
|
313
|
+
export declare const UP: Vector3;
|
|
314
|
+
/**
|
|
315
|
+
* A 3D vector that contains (0, 0, -1).
|
|
316
|
+
*/
|
|
317
|
+
export declare const DOWN: Vector3;
|
|
318
|
+
//# sourceMappingURL=Vector3.d.ts.map
|