@flighthq/geometry 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aabb.d.ts +88 -0
- package/dist/aabb.d.ts.map +1 -0
- package/dist/aabb.js +230 -0
- package/dist/aabb.js.map +1 -0
- package/dist/boundingSphere.d.ts +62 -0
- package/dist/boundingSphere.d.ts.map +1 -0
- package/dist/boundingSphere.js +188 -0
- package/dist/boundingSphere.js.map +1 -0
- package/dist/capsule.d.ts +38 -0
- package/dist/capsule.d.ts.map +1 -0
- package/dist/capsule.js +215 -0
- package/dist/capsule.js.map +1 -0
- package/dist/frustum.d.ts +49 -0
- package/dist/frustum.d.ts.map +1 -0
- package/dist/frustum.js +149 -0
- package/dist/frustum.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/matrix.d.ts +152 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +488 -0
- package/dist/matrix.js.map +1 -0
- package/dist/matrix3.d.ts +63 -0
- package/dist/matrix3.d.ts.map +1 -0
- package/dist/matrix3.js +408 -0
- package/dist/matrix3.js.map +1 -0
- package/dist/matrix3Pool.d.ts +6 -0
- package/dist/matrix3Pool.d.ts.map +1 -0
- package/dist/matrix3Pool.js +26 -0
- package/dist/matrix3Pool.js.map +1 -0
- package/dist/matrix4.d.ts +238 -0
- package/dist/matrix4.d.ts.map +1 -0
- package/dist/matrix4.js +931 -0
- package/dist/matrix4.js.map +1 -0
- package/dist/matrix4Pool.d.ts +6 -0
- package/dist/matrix4Pool.d.ts.map +1 -0
- package/dist/matrix4Pool.js +26 -0
- package/dist/matrix4Pool.js.map +1 -0
- package/dist/matrixPool.d.ts +6 -0
- package/dist/matrixPool.d.ts.map +1 -0
- package/dist/matrixPool.js +26 -0
- package/dist/matrixPool.js.map +1 -0
- package/dist/obb.d.ts +44 -0
- package/dist/obb.d.ts.map +1 -0
- package/dist/obb.js +248 -0
- package/dist/obb.js.map +1 -0
- package/dist/plane.d.ts +66 -0
- package/dist/plane.d.ts.map +1 -0
- package/dist/plane.js +140 -0
- package/dist/plane.js.map +1 -0
- package/dist/quaternion.d.ts +128 -0
- package/dist/quaternion.d.ts.map +1 -0
- package/dist/quaternion.js +508 -0
- package/dist/quaternion.js.map +1 -0
- package/dist/quaternionPool.d.ts +6 -0
- package/dist/quaternionPool.d.ts.map +1 -0
- package/dist/quaternionPool.js +29 -0
- package/dist/quaternionPool.js.map +1 -0
- package/dist/ray3d.d.ts +69 -0
- package/dist/ray3d.d.ts.map +1 -0
- package/dist/ray3d.js +264 -0
- package/dist/ray3d.js.map +1 -0
- package/dist/rectangle.d.ts +56 -0
- package/dist/rectangle.d.ts.map +1 -0
- package/dist/rectangle.js +235 -0
- package/dist/rectangle.js.map +1 -0
- package/dist/rectanglePool.d.ts +6 -0
- package/dist/rectanglePool.d.ts.map +1 -0
- package/dist/rectanglePool.js +29 -0
- package/dist/rectanglePool.js.map +1 -0
- package/dist/typedarray.d.ts +4 -0
- package/dist/typedarray.d.ts.map +1 -0
- package/dist/typedarray.js +25 -0
- package/dist/typedarray.js.map +1 -0
- package/dist/vector2.d.ts +130 -0
- package/dist/vector2.d.ts.map +1 -0
- package/dist/vector2.js +250 -0
- package/dist/vector2.js.map +1 -0
- package/dist/vector2Pool.d.ts +6 -0
- package/dist/vector2Pool.d.ts.map +1 -0
- package/dist/vector2Pool.js +20 -0
- package/dist/vector2Pool.js.map +1 -0
- package/dist/vector3.d.ts +220 -0
- package/dist/vector3.d.ts.map +1 -0
- package/dist/vector3.js +380 -0
- package/dist/vector3.js.map +1 -0
- package/dist/vector3Pool.d.ts +6 -0
- package/dist/vector3Pool.d.ts.map +1 -0
- package/dist/vector3Pool.js +28 -0
- package/dist/vector3Pool.js.map +1 -0
- package/dist/vector4.d.ts +180 -0
- package/dist/vector4.d.ts.map +1 -0
- package/dist/vector4.js +333 -0
- package/dist/vector4.js.map +1 -0
- package/dist/vector4Pool.d.ts +6 -0
- package/dist/vector4Pool.d.ts.map +1 -0
- package/dist/vector4Pool.js +29 -0
- package/dist/vector4Pool.js.map +1 -0
- package/package.json +38 -0
- package/src/aabb.test.ts +341 -0
- package/src/boundingSphere.test.ts +247 -0
- package/src/capsule.test.ts +157 -0
- package/src/frustum.test.ts +160 -0
- package/src/matrix.test.ts +1111 -0
- package/src/matrix3.test.ts +752 -0
- package/src/matrix3Pool.test.ts +73 -0
- package/src/matrix4.test.ts +1627 -0
- package/src/matrix4Pool.test.ts +71 -0
- package/src/matrixPool.test.ts +69 -0
- package/src/obb.test.ts +183 -0
- package/src/plane.test.ts +225 -0
- package/src/quaternion.test.ts +531 -0
- package/src/quaternionPool.test.ts +64 -0
- package/src/ray3d.test.ts +297 -0
- package/src/rectangle.test.ts +982 -0
- package/src/rectanglePool.test.ts +71 -0
- package/src/typedarray.test.ts +118 -0
- package/src/vector2.test.ts +958 -0
- package/src/vector2Pool.test.ts +65 -0
- package/src/vector3.test.ts +749 -0
- package/src/vector3Pool.test.ts +68 -0
- package/src/vector4.test.ts +660 -0
- package/src/vector4Pool.test.ts +71 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { Vector2Like, Vector3, Vector3Like, Vector4Like } from '@flighthq/types';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the x, y and z components of two vector objects
|
|
4
|
+
* and writes to out.
|
|
5
|
+
*/
|
|
6
|
+
export declare function addVector3(out: Vector3Like, a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): void;
|
|
7
|
+
/**
|
|
8
|
+
* Clamps each component of a Vector3Like independently to [min, max].
|
|
9
|
+
*
|
|
10
|
+
* Safe when `out` aliases `value`, `min`, or `max`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function clampVector3(out: Vector3Like, value: Readonly<Vector3Like>, min: Readonly<Vector3Like>, max: Readonly<Vector3Like>): void;
|
|
13
|
+
export declare function cloneVector3(source: Readonly<Vector3Like>): Vector3;
|
|
14
|
+
/**
|
|
15
|
+
* Copies the x, y and z components of a vector.
|
|
16
|
+
*/
|
|
17
|
+
export declare function copyVector3(out: Vector3Like, source: Readonly<Vector3Like>): void;
|
|
18
|
+
/**
|
|
19
|
+
* The Vector3Like class represents a point or a location in the three-dimensional space using
|
|
20
|
+
* the Cartesian coordinates x, y, and z. As in a two-dimensional space, the `x` property
|
|
21
|
+
* represents the horizontal axis and the `y` property represents the vertical axis. In
|
|
22
|
+
* three-dimensional space, the `z` property represents depth. The value of the `x` property increases as the object moves to the right. The value of the `y` property
|
|
23
|
+
* increases as the object moves down. The `z` property increases as the object moves
|
|
24
|
+
* farther from the point of view. Using perspective projection and scaling, the object is
|
|
25
|
+
* seen to be bigger when near and smaller when farther away from the screen. As in a
|
|
26
|
+
* right-handed three-dimensional coordinate system, the positive z-axis points away from
|
|
27
|
+
* the viewer and the value of the `z` property increases as the object moves away from the
|
|
28
|
+
* viewer's eye. The origin point (0,0,0) of the global space is the upper-left corner of
|
|
29
|
+
* the stage.
|
|
30
|
+
*
|
|
31
|
+
* Invariants:
|
|
32
|
+
*
|
|
33
|
+
* - `X_AXIS = new Vector3Like(1, 0, 0);`
|
|
34
|
+
* - `Y_AXIS = new Vector3Like(0, 1, 0);`
|
|
35
|
+
* - `Z_AXIS = new Vector3Like(0, 0, 1);`
|
|
36
|
+
* - `length = Math.sqrt(x ** 2 + y ** 2 + z ** 2);`
|
|
37
|
+
* - `lengthSquared = x ** 2 + y ** 2 + z ** 2;`
|
|
38
|
+
*/
|
|
39
|
+
export declare function createVector3(x?: number, y?: number, z?: number): Vector3;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a Vector3 from spherical coordinates (physics convention: radius, inclination θ from
|
|
42
|
+
* +Y axis, azimuth φ from +X axis in the XZ plane).
|
|
43
|
+
*
|
|
44
|
+
* - `theta` is the polar angle measured from the +Y axis (0 = north pole, π = south pole).
|
|
45
|
+
* - `phi` is the azimuthal angle measured from the +X axis in the XZ plane.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createVector3FromSpherical(radius: number, theta: number, phi: number): Vector3;
|
|
48
|
+
/**
|
|
49
|
+
* Writes a Vector3Like object that is perpendicular (at a right angle) to the
|
|
50
|
+
* current Vector3Like and another Vector3Like object. If the returned Vector3Like object's
|
|
51
|
+
* coordinates are (0,0,0), then the two Vector3Like objects are parallel to each other.
|
|
52
|
+
**/
|
|
53
|
+
export declare function crossVector3(out: Vector3Like, source: Readonly<Vector3Like>, other: Readonly<Vector3Like>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Component-wise division of two vectors (Hadamard division). Each component of
|
|
56
|
+
* `source` is divided by the corresponding component of `divisor`. Components with a
|
|
57
|
+
* zero divisor produce `0` in the output.
|
|
58
|
+
*
|
|
59
|
+
* Safe when `out` aliases `source` or `divisor`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function divideVector3(out: Vector3Like, source: Readonly<Vector3Like>, divisor: Readonly<Vector3Like>): void;
|
|
62
|
+
export declare function equalsVector3(a: Readonly<Vector3Like> | null | undefined, b: Readonly<Vector3Like> | null | undefined): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the angle in radians between two vectors. The returned angle is the
|
|
65
|
+
* smallest radian the first Vector3Like object rotates until it aligns with the
|
|
66
|
+
* second Vector3Like object.
|
|
67
|
+
**/
|
|
68
|
+
export declare function getVector3AngleBetween(a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): number;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the distance between two Vector3Like objects.
|
|
71
|
+
**/
|
|
72
|
+
export declare function getVector3Distance(a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the distance (squared) between two Vector3Like objects.
|
|
75
|
+
*
|
|
76
|
+
* This avoids Math.sqrt for better performance.
|
|
77
|
+
**/
|
|
78
|
+
export declare function getVector3DistanceSquared(a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): number;
|
|
79
|
+
/**
|
|
80
|
+
* If the current Vector3Like object and the one specified as the parameter are unit
|
|
81
|
+
* vertices, this method returns the cosine of the angle between the two vertices.
|
|
82
|
+
* Unit vertices are vertices that point to the same direction but their length is
|
|
83
|
+
* one. They remove the length of the vector as a factor in the result. You can use
|
|
84
|
+
* the `normalize()` method to convert a vector to a unit vector.
|
|
85
|
+
**/
|
|
86
|
+
export declare function getVector3Dot(a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): number;
|
|
87
|
+
/**
|
|
88
|
+
* The length, magnitude, of the current Vector3Like object from the origin (0,0,0) to
|
|
89
|
+
* the object's x, y, and z coordinates. The `w` property is ignored. A unit vector has
|
|
90
|
+
* a length or magnitude of one.
|
|
91
|
+
**/
|
|
92
|
+
export declare function getVector3Length(source: Readonly<Vector3Like>): number;
|
|
93
|
+
/**
|
|
94
|
+
* The square of the length of the current Vector3Like object, calculated using the `x`,
|
|
95
|
+
* `y`, and `z` properties. The `w` property is ignored. Use the `lengthSquared()`
|
|
96
|
+
* method whenever possible instead of the slower `Math.sqrt()` method call of the
|
|
97
|
+
* `Vector3Like.length()` method.
|
|
98
|
+
**/
|
|
99
|
+
export declare function getVector3LengthSquared(source: Readonly<Vector3Like>): number;
|
|
100
|
+
/**
|
|
101
|
+
* Reads the spherical coordinates (radius, theta, phi) from a Vector3Like. Uses the same
|
|
102
|
+
* convention as `setVector3FromSpherical` / `createVector3FromSpherical`:
|
|
103
|
+
* - `theta` is the polar angle from the +Y axis (0 = north pole, π = south pole).
|
|
104
|
+
* - `phi` is the azimuthal angle from the +X axis in the XZ plane.
|
|
105
|
+
*
|
|
106
|
+
* Writes to `out` as (x=radius, y=theta, z=phi).
|
|
107
|
+
*/
|
|
108
|
+
export declare function getVector3Spherical(out: Vector3Like, source: Readonly<Vector3Like>): void;
|
|
109
|
+
/**
|
|
110
|
+
* Linear interpolation between two Vector3Like objects at parameter `t` in [0, 1].
|
|
111
|
+
* `t=0` returns `a`; `t=1` returns `b`.
|
|
112
|
+
*
|
|
113
|
+
* Safe when `out` aliases `a` or `b` (all inputs are read into locals first).
|
|
114
|
+
*/
|
|
115
|
+
export declare function interpolateVector3(out: Vector3Like, a: Readonly<Vector3Like>, b: Readonly<Vector3Like>, t: number): void;
|
|
116
|
+
/**
|
|
117
|
+
* Writes the per-component maximum of two vectors.
|
|
118
|
+
*
|
|
119
|
+
* Safe when `out` aliases `a` or `b`.
|
|
120
|
+
*/
|
|
121
|
+
export declare function maxVector3(out: Vector3Like, a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): void;
|
|
122
|
+
/**
|
|
123
|
+
* Writes the per-component minimum of two vectors.
|
|
124
|
+
*
|
|
125
|
+
* Safe when `out` aliases `a` or `b`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function minVector3(out: Vector3Like, a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): void;
|
|
128
|
+
/**
|
|
129
|
+
* Component-wise product of two vectors (Hadamard product).
|
|
130
|
+
*
|
|
131
|
+
* Safe when `out` aliases `a` or `b`.
|
|
132
|
+
*/
|
|
133
|
+
export declare function multiplyVector3(out: Vector3Like, a: Readonly<Vector3Like>, b: Readonly<Vector3Like>): void;
|
|
134
|
+
/**
|
|
135
|
+
* Compares the elements of the current Vector3Like object with the elements of a
|
|
136
|
+
* specified Vector3Like object to determine whether they are nearly equal.
|
|
137
|
+
*
|
|
138
|
+
* The two Vector3Like objects are nearly equal if the value of all the elements of the two
|
|
139
|
+
* vertices are equal, or the result of the comparison is within the tolerance range.
|
|
140
|
+
**/
|
|
141
|
+
export declare function nearEqualsVector3(a: Readonly<Vector3Like>, b: Readonly<Vector3Like>, tolerance?: number): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Sets the current Vector3Like object to its inverse. The inverse object is also
|
|
144
|
+
* considered the opposite of the original object. The value of the `x`, `y`, and `z`
|
|
145
|
+
* properties of the current Vector3Like object is changed to -x, -y, and -z.
|
|
146
|
+
**/
|
|
147
|
+
export declare function negateVector3(out: Vector3Like, source: Readonly<Vector3Like>): void;
|
|
148
|
+
/**
|
|
149
|
+
* Converts a Vector3Like object to a unit vector by dividing the first three elements
|
|
150
|
+
* (x, y, z) by the length of the vector.
|
|
151
|
+
*
|
|
152
|
+
* Returns the original length.
|
|
153
|
+
**/
|
|
154
|
+
export declare function normalizeVector3(out: Vector3Like, source: Readonly<Vector3Like>): number;
|
|
155
|
+
/**
|
|
156
|
+
* Offsets each component of the current Vector3Like object by a scalar per axis.
|
|
157
|
+
**/
|
|
158
|
+
export declare function offsetVector3(out: Vector3Like, source: Readonly<Vector3Like>, dx: number, dy: number, dz: number): void;
|
|
159
|
+
/**
|
|
160
|
+
* Divides the value of the `x` and `y` properties of the current Vector3Like
|
|
161
|
+
* object by the value of its `z` property.
|
|
162
|
+
**/
|
|
163
|
+
export declare function projectVector3(out: Vector2Like, source: Readonly<Vector3Like>): void;
|
|
164
|
+
/**
|
|
165
|
+
* Reflects an incident vector about a unit normal. The result is the reflection of
|
|
166
|
+
* `incident` across the plane whose normal is `normal`.
|
|
167
|
+
*
|
|
168
|
+
* Formula: out = incident - 2 * dot(incident, normal) * normal
|
|
169
|
+
*
|
|
170
|
+
* Safe when `out` aliases `incident` or `normal`.
|
|
171
|
+
*/
|
|
172
|
+
export declare function reflectVector3(out: Vector3Like, incident: Readonly<Vector3Like>, normal: Readonly<Vector3Like>): void;
|
|
173
|
+
/**
|
|
174
|
+
* Scales the current Vector3Like object by a scalar, a magnitude. The Vector3Like object's
|
|
175
|
+
* x, y, and z elements are multiplied by the provided scalar number.
|
|
176
|
+
**/
|
|
177
|
+
export declare function scaleVector3(out: Vector3Like, source: Readonly<Vector3Like>, scalar: number): void;
|
|
178
|
+
/**
|
|
179
|
+
* Sets the members of Vector3Like to the specified values
|
|
180
|
+
**/
|
|
181
|
+
export declare function setVector3(out: Vector3Like, x: number, y: number, z: number): void;
|
|
182
|
+
/**
|
|
183
|
+
* Reads a Vector3Like from a Float32Array at a byte offset.
|
|
184
|
+
*/
|
|
185
|
+
export declare function setVector3FromFloat32Array(out: Vector3Like, offset: number, source: Readonly<Float32Array>): void;
|
|
186
|
+
/**
|
|
187
|
+
* Writes a Vector3Like into spherical coordinates.
|
|
188
|
+
* Uses the physics convention: theta is polar angle from +Y, phi is azimuthal from +X in XZ.
|
|
189
|
+
*/
|
|
190
|
+
export declare function setVector3FromSpherical(out: Vector3Like, radius: number, theta: number, phi: number): void;
|
|
191
|
+
/**
|
|
192
|
+
* Copies the x, y, and z components of a Vector4Like into a Vector3Like, dropping the w component.
|
|
193
|
+
* For perspective-correct results (when w ≠ 1) use projectVector4 instead, which performs the
|
|
194
|
+
* perspective divide.
|
|
195
|
+
*
|
|
196
|
+
* Safe when `out` aliases the same memory as `source`.
|
|
197
|
+
*/
|
|
198
|
+
export declare function setVector3FromVector4(out: Vector3Like, source: Readonly<Vector4Like>): void;
|
|
199
|
+
/**
|
|
200
|
+
* Subtracts the value of the x, y, and z elements of the current Vector3Like object
|
|
201
|
+
* from the values of the x, y, and z elements of another Vector3Like object.
|
|
202
|
+
**/
|
|
203
|
+
export declare function subtractVector3(out: Vector3Like, source: Readonly<Vector3Like>, other: Readonly<Vector3Like>): void;
|
|
204
|
+
/**
|
|
205
|
+
* Transforms a Vector3Like by a Matrix3 (column-major, row-major storage).
|
|
206
|
+
* Useful for transforming normals by a normal matrix.
|
|
207
|
+
*
|
|
208
|
+
* Safe when `out` aliases `source`.
|
|
209
|
+
*/
|
|
210
|
+
export declare function transformVector3ByMatrix3(out: Vector3Like, source: Readonly<Vector3Like>, matrix: Readonly<{
|
|
211
|
+
m: Readonly<Float32Array>;
|
|
212
|
+
}>): void;
|
|
213
|
+
/**
|
|
214
|
+
* Writes a Vector3Like into a Float32Array at a byte offset.
|
|
215
|
+
*/
|
|
216
|
+
export declare function writeVector3ToFloat32Array(out: Float32Array, offset: number, source: Readonly<Vector3Like>): void;
|
|
217
|
+
export declare const VECTOR3_X_AXIS: Readonly<Vector3>;
|
|
218
|
+
export declare const VECTOR3_Y_AXIS: Readonly<Vector3>;
|
|
219
|
+
export declare const VECTOR3_Z_AXIS: Readonly<Vector3>;
|
|
220
|
+
//# sourceMappingURL=vector3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector3.d.ts","sourceRoot":"","sources":["../src/vector3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEtF;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAIrG;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC5B,GAAG,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC1B,GAAG,EAAE,QAAQ,CAAC,WAAW,CAAC,GACzB,IAAI,CAaN;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,OAAO,CAEnE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAIjF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAI9F;AAED;;;;IAII;AACJ,wBAAgB,YAAY,CAAC,GAAG,EAAE,WAAW,EAAE,MA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AC,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAInH;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC7B,MAAM,EAAE,QAAQ,CAAC;IAAE,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAA;CAAE,CAAC,GAC9C,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAIjH;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,OAAO,CAA0B,CAAC;AACxE,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,OAAO,CAA0B,CAAC;AACxE,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,OAAO,CAA0B,CAAC"}
|
package/dist/vector3.js
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the x, y and z components of two vector objects
|
|
4
|
+
* and writes to out.
|
|
5
|
+
*/
|
|
6
|
+
export function addVector3(out, a, b) {
|
|
7
|
+
out.x = a.x + b.x;
|
|
8
|
+
out.y = a.y + b.y;
|
|
9
|
+
out.z = a.z + b.z;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Clamps each component of a Vector3Like independently to [min, max].
|
|
13
|
+
*
|
|
14
|
+
* Safe when `out` aliases `value`, `min`, or `max`.
|
|
15
|
+
*/
|
|
16
|
+
export function clampVector3(out, value, min, max) {
|
|
17
|
+
const vx = value.x, vy = value.y, vz = value.z;
|
|
18
|
+
const minX = min.x, minY = min.y, minZ = min.z;
|
|
19
|
+
const maxX = max.x, maxY = max.y, maxZ = max.z;
|
|
20
|
+
out.x = vx < minX ? minX : vx > maxX ? maxX : vx;
|
|
21
|
+
out.y = vy < minY ? minY : vy > maxY ? maxY : vy;
|
|
22
|
+
out.z = vz < minZ ? minZ : vz > maxZ ? maxZ : vz;
|
|
23
|
+
}
|
|
24
|
+
export function cloneVector3(source) {
|
|
25
|
+
return createVector3(source.x, source.y, source.z);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Copies the x, y and z components of a vector.
|
|
29
|
+
*/
|
|
30
|
+
export function copyVector3(out, source) {
|
|
31
|
+
out.x = source.x;
|
|
32
|
+
out.y = source.y;
|
|
33
|
+
out.z = source.z;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The Vector3Like class represents a point or a location in the three-dimensional space using
|
|
37
|
+
* the Cartesian coordinates x, y, and z. As in a two-dimensional space, the `x` property
|
|
38
|
+
* represents the horizontal axis and the `y` property represents the vertical axis. In
|
|
39
|
+
* three-dimensional space, the `z` property represents depth. The value of the `x` property increases as the object moves to the right. The value of the `y` property
|
|
40
|
+
* increases as the object moves down. The `z` property increases as the object moves
|
|
41
|
+
* farther from the point of view. Using perspective projection and scaling, the object is
|
|
42
|
+
* seen to be bigger when near and smaller when farther away from the screen. As in a
|
|
43
|
+
* right-handed three-dimensional coordinate system, the positive z-axis points away from
|
|
44
|
+
* the viewer and the value of the `z` property increases as the object moves away from the
|
|
45
|
+
* viewer's eye. The origin point (0,0,0) of the global space is the upper-left corner of
|
|
46
|
+
* the stage.
|
|
47
|
+
*
|
|
48
|
+
* Invariants:
|
|
49
|
+
*
|
|
50
|
+
* - `X_AXIS = new Vector3Like(1, 0, 0);`
|
|
51
|
+
* - `Y_AXIS = new Vector3Like(0, 1, 0);`
|
|
52
|
+
* - `Z_AXIS = new Vector3Like(0, 0, 1);`
|
|
53
|
+
* - `length = Math.sqrt(x ** 2 + y ** 2 + z ** 2);`
|
|
54
|
+
* - `lengthSquared = x ** 2 + y ** 2 + z ** 2;`
|
|
55
|
+
*/
|
|
56
|
+
export function createVector3(x, y, z) {
|
|
57
|
+
return createEntity({ x: x ?? 0, y: y ?? 0, z: z ?? 0 });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a Vector3 from spherical coordinates (physics convention: radius, inclination θ from
|
|
61
|
+
* +Y axis, azimuth φ from +X axis in the XZ plane).
|
|
62
|
+
*
|
|
63
|
+
* - `theta` is the polar angle measured from the +Y axis (0 = north pole, π = south pole).
|
|
64
|
+
* - `phi` is the azimuthal angle measured from the +X axis in the XZ plane.
|
|
65
|
+
*/
|
|
66
|
+
export function createVector3FromSpherical(radius, theta, phi) {
|
|
67
|
+
const out = createVector3();
|
|
68
|
+
setVector3FromSpherical(out, radius, theta, phi);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Writes a Vector3Like object that is perpendicular (at a right angle) to the
|
|
73
|
+
* current Vector3Like and another Vector3Like object. If the returned Vector3Like object's
|
|
74
|
+
* coordinates are (0,0,0), then the two Vector3Like objects are parallel to each other.
|
|
75
|
+
**/
|
|
76
|
+
export function crossVector3(out, source, other) {
|
|
77
|
+
const x = source.y * other.z - source.z * other.y;
|
|
78
|
+
const y = source.z * other.x - source.x * other.z;
|
|
79
|
+
const z = source.x * other.y - source.y * other.x;
|
|
80
|
+
out.x = x;
|
|
81
|
+
out.y = y;
|
|
82
|
+
out.z = z;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Component-wise division of two vectors (Hadamard division). Each component of
|
|
86
|
+
* `source` is divided by the corresponding component of `divisor`. Components with a
|
|
87
|
+
* zero divisor produce `0` in the output.
|
|
88
|
+
*
|
|
89
|
+
* Safe when `out` aliases `source` or `divisor`.
|
|
90
|
+
*/
|
|
91
|
+
export function divideVector3(out, source, divisor) {
|
|
92
|
+
const sx = source.x, sy = source.y, sz = source.z;
|
|
93
|
+
const dx = divisor.x, dy = divisor.y, dz = divisor.z;
|
|
94
|
+
out.x = dx !== 0 ? sx / dx : 0;
|
|
95
|
+
out.y = dy !== 0 ? sy / dy : 0;
|
|
96
|
+
out.z = dz !== 0 ? sz / dz : 0;
|
|
97
|
+
}
|
|
98
|
+
export function equalsVector3(a, b) {
|
|
99
|
+
if (!a || !b)
|
|
100
|
+
return false;
|
|
101
|
+
return a.x === b.x && a.y === b.y && a.z === b.z;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns the angle in radians between two vectors. The returned angle is the
|
|
105
|
+
* smallest radian the first Vector3Like object rotates until it aligns with the
|
|
106
|
+
* second Vector3Like object.
|
|
107
|
+
**/
|
|
108
|
+
export function getVector3AngleBetween(a, b) {
|
|
109
|
+
const la = getVector3Length(a);
|
|
110
|
+
const lb = getVector3Length(b);
|
|
111
|
+
if (la === 0 || lb === 0)
|
|
112
|
+
return NaN; // undefined angle
|
|
113
|
+
const _dot = getVector3Dot(a, b) / (la * lb);
|
|
114
|
+
// clamp dot to [-1, 1] to avoid floating point errors
|
|
115
|
+
return Math.acos(Math.min(1, Math.max(-1, _dot)));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Returns the distance between two Vector3Like objects.
|
|
119
|
+
**/
|
|
120
|
+
export function getVector3Distance(a, b) {
|
|
121
|
+
const x = b.x - a.x;
|
|
122
|
+
const y = b.y - a.y;
|
|
123
|
+
const z = b.z - a.z;
|
|
124
|
+
return Math.sqrt(x ** 2 + y ** 2 + z ** 2);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns the distance (squared) between two Vector3Like objects.
|
|
128
|
+
*
|
|
129
|
+
* This avoids Math.sqrt for better performance.
|
|
130
|
+
**/
|
|
131
|
+
export function getVector3DistanceSquared(a, b) {
|
|
132
|
+
const x = b.x - a.x;
|
|
133
|
+
const y = b.y - a.y;
|
|
134
|
+
const z = b.z - a.z;
|
|
135
|
+
return x ** 2 + y ** 2 + z ** 2;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* If the current Vector3Like object and the one specified as the parameter are unit
|
|
139
|
+
* vertices, this method returns the cosine of the angle between the two vertices.
|
|
140
|
+
* Unit vertices are vertices that point to the same direction but their length is
|
|
141
|
+
* one. They remove the length of the vector as a factor in the result. You can use
|
|
142
|
+
* the `normalize()` method to convert a vector to a unit vector.
|
|
143
|
+
**/
|
|
144
|
+
export function getVector3Dot(a, b) {
|
|
145
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The length, magnitude, of the current Vector3Like object from the origin (0,0,0) to
|
|
149
|
+
* the object's x, y, and z coordinates. The `w` property is ignored. A unit vector has
|
|
150
|
+
* a length or magnitude of one.
|
|
151
|
+
**/
|
|
152
|
+
export function getVector3Length(source) {
|
|
153
|
+
return Math.sqrt(source.x ** 2 + source.y ** 2 + source.z ** 2);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The square of the length of the current Vector3Like object, calculated using the `x`,
|
|
157
|
+
* `y`, and `z` properties. The `w` property is ignored. Use the `lengthSquared()`
|
|
158
|
+
* method whenever possible instead of the slower `Math.sqrt()` method call of the
|
|
159
|
+
* `Vector3Like.length()` method.
|
|
160
|
+
**/
|
|
161
|
+
export function getVector3LengthSquared(source) {
|
|
162
|
+
return source.x ** 2 + source.y ** 2 + source.z ** 2;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Reads the spherical coordinates (radius, theta, phi) from a Vector3Like. Uses the same
|
|
166
|
+
* convention as `setVector3FromSpherical` / `createVector3FromSpherical`:
|
|
167
|
+
* - `theta` is the polar angle from the +Y axis (0 = north pole, π = south pole).
|
|
168
|
+
* - `phi` is the azimuthal angle from the +X axis in the XZ plane.
|
|
169
|
+
*
|
|
170
|
+
* Writes to `out` as (x=radius, y=theta, z=phi).
|
|
171
|
+
*/
|
|
172
|
+
export function getVector3Spherical(out, source) {
|
|
173
|
+
const x = source.x, y = source.y, z = source.z;
|
|
174
|
+
const radius = Math.sqrt(x * x + y * y + z * z);
|
|
175
|
+
if (radius === 0) {
|
|
176
|
+
out.x = 0;
|
|
177
|
+
out.y = 0;
|
|
178
|
+
out.z = 0;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
out.x = radius;
|
|
182
|
+
out.y = Math.acos(Math.min(1, Math.max(-1, y / radius)));
|
|
183
|
+
out.z = Math.atan2(z, x);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Linear interpolation between two Vector3Like objects at parameter `t` in [0, 1].
|
|
187
|
+
* `t=0` returns `a`; `t=1` returns `b`.
|
|
188
|
+
*
|
|
189
|
+
* Safe when `out` aliases `a` or `b` (all inputs are read into locals first).
|
|
190
|
+
*/
|
|
191
|
+
export function interpolateVector3(out, a, b, t) {
|
|
192
|
+
const ax = a.x, ay = a.y, az = a.z;
|
|
193
|
+
out.x = ax + t * (b.x - ax);
|
|
194
|
+
out.y = ay + t * (b.y - ay);
|
|
195
|
+
out.z = az + t * (b.z - az);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Writes the per-component maximum of two vectors.
|
|
199
|
+
*
|
|
200
|
+
* Safe when `out` aliases `a` or `b`.
|
|
201
|
+
*/
|
|
202
|
+
export function maxVector3(out, a, b) {
|
|
203
|
+
out.x = a.x > b.x ? a.x : b.x;
|
|
204
|
+
out.y = a.y > b.y ? a.y : b.y;
|
|
205
|
+
out.z = a.z > b.z ? a.z : b.z;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Writes the per-component minimum of two vectors.
|
|
209
|
+
*
|
|
210
|
+
* Safe when `out` aliases `a` or `b`.
|
|
211
|
+
*/
|
|
212
|
+
export function minVector3(out, a, b) {
|
|
213
|
+
out.x = a.x < b.x ? a.x : b.x;
|
|
214
|
+
out.y = a.y < b.y ? a.y : b.y;
|
|
215
|
+
out.z = a.z < b.z ? a.z : b.z;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Component-wise product of two vectors (Hadamard product).
|
|
219
|
+
*
|
|
220
|
+
* Safe when `out` aliases `a` or `b`.
|
|
221
|
+
*/
|
|
222
|
+
export function multiplyVector3(out, a, b) {
|
|
223
|
+
out.x = a.x * b.x;
|
|
224
|
+
out.y = a.y * b.y;
|
|
225
|
+
out.z = a.z * b.z;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Compares the elements of the current Vector3Like object with the elements of a
|
|
229
|
+
* specified Vector3Like object to determine whether they are nearly equal.
|
|
230
|
+
*
|
|
231
|
+
* The two Vector3Like objects are nearly equal if the value of all the elements of the two
|
|
232
|
+
* vertices are equal, or the result of the comparison is within the tolerance range.
|
|
233
|
+
**/
|
|
234
|
+
export function nearEqualsVector3(a, b, tolerance = 1e-6) {
|
|
235
|
+
return Math.abs(a.x - b.x) < tolerance && Math.abs(a.y - b.y) < tolerance && Math.abs(a.z - b.z) < tolerance;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Sets the current Vector3Like object to its inverse. The inverse object is also
|
|
239
|
+
* considered the opposite of the original object. The value of the `x`, `y`, and `z`
|
|
240
|
+
* properties of the current Vector3Like object is changed to -x, -y, and -z.
|
|
241
|
+
**/
|
|
242
|
+
export function negateVector3(out, source) {
|
|
243
|
+
out.x = source.x * -1;
|
|
244
|
+
out.y = source.y * -1;
|
|
245
|
+
out.z = source.z * -1;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Converts a Vector3Like object to a unit vector by dividing the first three elements
|
|
249
|
+
* (x, y, z) by the length of the vector.
|
|
250
|
+
*
|
|
251
|
+
* Returns the original length.
|
|
252
|
+
**/
|
|
253
|
+
export function normalizeVector3(out, source) {
|
|
254
|
+
const l = getVector3Length(source);
|
|
255
|
+
if (l !== 0) {
|
|
256
|
+
out.x = source.x / l;
|
|
257
|
+
out.y = source.y / l;
|
|
258
|
+
out.z = source.z / l;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
out.x = 0;
|
|
262
|
+
out.y = 0;
|
|
263
|
+
out.z = 0;
|
|
264
|
+
}
|
|
265
|
+
return l;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Offsets each component of the current Vector3Like object by a scalar per axis.
|
|
269
|
+
**/
|
|
270
|
+
export function offsetVector3(out, source, dx, dy, dz) {
|
|
271
|
+
out.x = source.x + dx;
|
|
272
|
+
out.y = source.y + dy;
|
|
273
|
+
out.z = source.z + dz;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Divides the value of the `x` and `y` properties of the current Vector3Like
|
|
277
|
+
* object by the value of its `z` property.
|
|
278
|
+
**/
|
|
279
|
+
export function projectVector3(out, source) {
|
|
280
|
+
out.x = source.x / source.z;
|
|
281
|
+
out.y = source.y / source.z;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Reflects an incident vector about a unit normal. The result is the reflection of
|
|
285
|
+
* `incident` across the plane whose normal is `normal`.
|
|
286
|
+
*
|
|
287
|
+
* Formula: out = incident - 2 * dot(incident, normal) * normal
|
|
288
|
+
*
|
|
289
|
+
* Safe when `out` aliases `incident` or `normal`.
|
|
290
|
+
*/
|
|
291
|
+
export function reflectVector3(out, incident, normal) {
|
|
292
|
+
const ix = incident.x, iy = incident.y, iz = incident.z;
|
|
293
|
+
const nx = normal.x, ny = normal.y, nz = normal.z;
|
|
294
|
+
const twoDot = 2 * (ix * nx + iy * ny + iz * nz);
|
|
295
|
+
out.x = ix - twoDot * nx;
|
|
296
|
+
out.y = iy - twoDot * ny;
|
|
297
|
+
out.z = iz - twoDot * nz;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Scales the current Vector3Like object by a scalar, a magnitude. The Vector3Like object's
|
|
301
|
+
* x, y, and z elements are multiplied by the provided scalar number.
|
|
302
|
+
**/
|
|
303
|
+
export function scaleVector3(out, source, scalar) {
|
|
304
|
+
out.x = source.x * scalar;
|
|
305
|
+
out.y = source.y * scalar;
|
|
306
|
+
out.z = source.z * scalar;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Sets the members of Vector3Like to the specified values
|
|
310
|
+
**/
|
|
311
|
+
export function setVector3(out, x, y, z) {
|
|
312
|
+
out.x = x;
|
|
313
|
+
out.y = y;
|
|
314
|
+
out.z = z;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Reads a Vector3Like from a Float32Array at a byte offset.
|
|
318
|
+
*/
|
|
319
|
+
export function setVector3FromFloat32Array(out, offset, source) {
|
|
320
|
+
out.x = source[offset];
|
|
321
|
+
out.y = source[offset + 1];
|
|
322
|
+
out.z = source[offset + 2];
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Writes a Vector3Like into spherical coordinates.
|
|
326
|
+
* Uses the physics convention: theta is polar angle from +Y, phi is azimuthal from +X in XZ.
|
|
327
|
+
*/
|
|
328
|
+
export function setVector3FromSpherical(out, radius, theta, phi) {
|
|
329
|
+
const sinTheta = Math.sin(theta);
|
|
330
|
+
out.x = radius * sinTheta * Math.cos(phi);
|
|
331
|
+
out.y = radius * Math.cos(theta);
|
|
332
|
+
out.z = radius * sinTheta * Math.sin(phi);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Copies the x, y, and z components of a Vector4Like into a Vector3Like, dropping the w component.
|
|
336
|
+
* For perspective-correct results (when w ≠ 1) use projectVector4 instead, which performs the
|
|
337
|
+
* perspective divide.
|
|
338
|
+
*
|
|
339
|
+
* Safe when `out` aliases the same memory as `source`.
|
|
340
|
+
*/
|
|
341
|
+
export function setVector3FromVector4(out, source) {
|
|
342
|
+
const x = source.x, y = source.y, z = source.z;
|
|
343
|
+
out.x = x;
|
|
344
|
+
out.y = y;
|
|
345
|
+
out.z = z;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Subtracts the value of the x, y, and z elements of the current Vector3Like object
|
|
349
|
+
* from the values of the x, y, and z elements of another Vector3Like object.
|
|
350
|
+
**/
|
|
351
|
+
export function subtractVector3(out, source, other) {
|
|
352
|
+
out.x = source.x - other.x;
|
|
353
|
+
out.y = source.y - other.y;
|
|
354
|
+
out.z = source.z - other.z;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Transforms a Vector3Like by a Matrix3 (column-major, row-major storage).
|
|
358
|
+
* Useful for transforming normals by a normal matrix.
|
|
359
|
+
*
|
|
360
|
+
* Safe when `out` aliases `source`.
|
|
361
|
+
*/
|
|
362
|
+
export function transformVector3ByMatrix3(out, source, matrix) {
|
|
363
|
+
const m = matrix.m;
|
|
364
|
+
const x = source.x, y = source.y, z = source.z;
|
|
365
|
+
out.x = m[0] * x + m[1] * y + m[2] * z;
|
|
366
|
+
out.y = m[3] * x + m[4] * y + m[5] * z;
|
|
367
|
+
out.z = m[6] * x + m[7] * y + m[8] * z;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Writes a Vector3Like into a Float32Array at a byte offset.
|
|
371
|
+
*/
|
|
372
|
+
export function writeVector3ToFloat32Array(out, offset, source) {
|
|
373
|
+
out[offset] = source.x;
|
|
374
|
+
out[offset + 1] = source.y;
|
|
375
|
+
out[offset + 2] = source.z;
|
|
376
|
+
}
|
|
377
|
+
export const VECTOR3_X_AXIS = createVector3(1, 0, 0);
|
|
378
|
+
export const VECTOR3_Y_AXIS = createVector3(0, 1, 0);
|
|
379
|
+
export const VECTOR3_Z_AXIS = createVector3(0, 0, 1);
|
|
380
|
+
//# sourceMappingURL=vector3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector3.js","sourceRoot":"","sources":["../src/vector3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,GAAgB,EAAE,CAAwB,EAAE,CAAwB;IAC7F,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAClB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,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,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAsB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,MAAM,CAAC,MAAM,cAAc,GAAsB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,MAAM,CAAC,MAAM,cAAc,GAAsB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Vector3 } from '@flighthq/types';
|
|
2
|
+
export declare function acquireEmptyVector3(): Vector3;
|
|
3
|
+
export declare function acquireVector3(): Vector3;
|
|
4
|
+
export declare function clearVector3Pool(): void;
|
|
5
|
+
export declare function releaseVector3(v: Vector3): void;
|
|
6
|
+
//# sourceMappingURL=vector3Pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector3Pool.d.ts","sourceRoot":"","sources":["../src/vector3Pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAI/C,wBAAgB,mBAAmB,IAAI,OAAO,CAM7C;AAED,wBAAgB,cAAc,IAAI,OAAO,CAUxC;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAG/C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createVector3 } from './vector3';
|
|
2
|
+
export function acquireEmptyVector3() {
|
|
3
|
+
const v = acquireVector3();
|
|
4
|
+
v.x = 0;
|
|
5
|
+
v.y = 0;
|
|
6
|
+
v.z = 0;
|
|
7
|
+
return v;
|
|
8
|
+
}
|
|
9
|
+
export function acquireVector3() {
|
|
10
|
+
let v;
|
|
11
|
+
if (pool.length > 0) {
|
|
12
|
+
v = pool.pop();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
v = createVector3();
|
|
16
|
+
}
|
|
17
|
+
return v;
|
|
18
|
+
}
|
|
19
|
+
export function clearVector3Pool() {
|
|
20
|
+
pool.length = 0;
|
|
21
|
+
}
|
|
22
|
+
export function releaseVector3(v) {
|
|
23
|
+
if (!v)
|
|
24
|
+
return;
|
|
25
|
+
pool.push(v);
|
|
26
|
+
}
|
|
27
|
+
const pool = [];
|
|
28
|
+
//# sourceMappingURL=vector3Pool.js.map
|