@mlightcad/geometry-engine 1.0.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/geometry-engine.js +10186 -0
- package/dist/geometry-engine.umd.cjs +4 -0
- package/lib/geometry/AcGeArea2d.d.ts +61 -0
- package/lib/geometry/AcGeArea2d.d.ts.map +1 -0
- package/lib/geometry/AcGeArea2d.js +174 -0
- package/lib/geometry/AcGeArea2d.js.map +1 -0
- package/lib/geometry/AcGeCircArc2d.d.ts +108 -0
- package/lib/geometry/AcGeCircArc2d.d.ts.map +1 -0
- package/lib/geometry/AcGeCircArc2d.js +412 -0
- package/lib/geometry/AcGeCircArc2d.js.map +1 -0
- package/lib/geometry/AcGeCircArc3d.d.ts +138 -0
- package/lib/geometry/AcGeCircArc3d.d.ts.map +1 -0
- package/lib/geometry/AcGeCircArc3d.js +447 -0
- package/lib/geometry/AcGeCircArc3d.js.map +1 -0
- package/lib/geometry/AcGeCurve2d.d.ts +85 -0
- package/lib/geometry/AcGeCurve2d.d.ts.map +1 -0
- package/lib/geometry/AcGeCurve2d.js +213 -0
- package/lib/geometry/AcGeCurve2d.js.map +1 -0
- package/lib/geometry/AcGeCurve3d.d.ts +27 -0
- package/lib/geometry/AcGeCurve3d.d.ts.map +1 -0
- package/lib/geometry/AcGeCurve3d.js +29 -0
- package/lib/geometry/AcGeCurve3d.js.map +1 -0
- package/lib/geometry/AcGeEllipseArc2d.d.ts +105 -0
- package/lib/geometry/AcGeEllipseArc2d.d.ts.map +1 -0
- package/lib/geometry/AcGeEllipseArc2d.js +292 -0
- package/lib/geometry/AcGeEllipseArc2d.js.map +1 -0
- package/lib/geometry/AcGeEllipseArc3d.d.ts +141 -0
- package/lib/geometry/AcGeEllipseArc3d.d.ts.map +1 -0
- package/lib/geometry/AcGeEllipseArc3d.js +442 -0
- package/lib/geometry/AcGeEllipseArc3d.js.map +1 -0
- package/lib/geometry/AcGeLine2d.d.ts +56 -0
- package/lib/geometry/AcGeLine2d.d.ts.map +1 -0
- package/lib/geometry/AcGeLine2d.js +125 -0
- package/lib/geometry/AcGeLine2d.js.map +1 -0
- package/lib/geometry/AcGeLine3d.d.ts +134 -0
- package/lib/geometry/AcGeLine3d.d.ts.map +1 -0
- package/lib/geometry/AcGeLine3d.js +291 -0
- package/lib/geometry/AcGeLine3d.js.map +1 -0
- package/lib/geometry/AcGeLoop2d.d.ts +59 -0
- package/lib/geometry/AcGeLoop2d.d.ts.map +1 -0
- package/lib/geometry/AcGeLoop2d.js +141 -0
- package/lib/geometry/AcGeLoop2d.js.map +1 -0
- package/lib/geometry/AcGePolyline2d.d.ts +90 -0
- package/lib/geometry/AcGePolyline2d.d.ts.map +1 -0
- package/lib/geometry/AcGePolyline2d.js +224 -0
- package/lib/geometry/AcGePolyline2d.js.map +1 -0
- package/lib/geometry/AcGeShape.d.ts +12 -0
- package/lib/geometry/AcGeShape.d.ts.map +1 -0
- package/lib/geometry/AcGeShape.js +22 -0
- package/lib/geometry/AcGeShape.js.map +1 -0
- package/lib/geometry/AcGeShape2d.d.ts +31 -0
- package/lib/geometry/AcGeShape2d.d.ts.map +1 -0
- package/lib/geometry/AcGeShape2d.js +51 -0
- package/lib/geometry/AcGeShape2d.js.map +1 -0
- package/lib/geometry/AcGeShape3d.d.ts +33 -0
- package/lib/geometry/AcGeShape3d.d.ts.map +1 -0
- package/lib/geometry/AcGeShape3d.js +52 -0
- package/lib/geometry/AcGeShape3d.js.map +1 -0
- package/lib/geometry/AcGeSpline3d.d.ts +77 -0
- package/lib/geometry/AcGeSpline3d.d.ts.map +1 -0
- package/lib/geometry/AcGeSpline3d.js +221 -0
- package/lib/geometry/AcGeSpline3d.js.map +1 -0
- package/lib/geometry/index.d.ts +13 -0
- package/lib/geometry/index.d.ts.map +1 -0
- package/lib/geometry/index.js +13 -0
- package/lib/geometry/index.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib/math/AcGeBox2d.d.ts +173 -0
- package/lib/math/AcGeBox2d.d.ts.map +1 -0
- package/lib/math/AcGeBox2d.js +289 -0
- package/lib/math/AcGeBox2d.js.map +1 -0
- package/lib/math/AcGeBox3d.d.ts +195 -0
- package/lib/math/AcGeBox3d.d.ts.map +1 -0
- package/lib/math/AcGeBox3d.js +378 -0
- package/lib/math/AcGeBox3d.js.map +1 -0
- package/lib/math/AcGeEuler.d.ts +133 -0
- package/lib/math/AcGeEuler.d.ts.map +1 -0
- package/lib/math/AcGeEuler.js +358 -0
- package/lib/math/AcGeEuler.js.map +1 -0
- package/lib/math/AcGeMatrix2d.d.ts +203 -0
- package/lib/math/AcGeMatrix2d.d.ts.map +1 -0
- package/lib/math/AcGeMatrix2d.js +393 -0
- package/lib/math/AcGeMatrix2d.js.map +1 -0
- package/lib/math/AcGeMatrix3d.d.ts +279 -0
- package/lib/math/AcGeMatrix3d.d.ts.map +1 -0
- package/lib/math/AcGeMatrix3d.js +1037 -0
- package/lib/math/AcGeMatrix3d.js.map +1 -0
- package/lib/math/AcGePlane.d.ts +131 -0
- package/lib/math/AcGePlane.d.ts.map +1 -0
- package/lib/math/AcGePlane.js +218 -0
- package/lib/math/AcGePlane.js.map +1 -0
- package/lib/math/AcGePoint.d.ts +4 -0
- package/lib/math/AcGePoint.d.ts.map +1 -0
- package/lib/math/AcGePoint.js +2 -0
- package/lib/math/AcGePoint.js.map +1 -0
- package/lib/math/AcGePoint2d.d.ts +17 -0
- package/lib/math/AcGePoint2d.d.ts.map +1 -0
- package/lib/math/AcGePoint2d.js +40 -0
- package/lib/math/AcGePoint2d.js.map +1 -0
- package/lib/math/AcGePoint3d.d.ts +18 -0
- package/lib/math/AcGePoint3d.d.ts.map +1 -0
- package/lib/math/AcGePoint3d.js +43 -0
- package/lib/math/AcGePoint3d.js.map +1 -0
- package/lib/math/AcGeQuaternion.d.ts +230 -0
- package/lib/math/AcGeQuaternion.d.ts.map +1 -0
- package/lib/math/AcGeQuaternion.js +666 -0
- package/lib/math/AcGeQuaternion.js.map +1 -0
- package/lib/math/AcGeVector.d.ts +9 -0
- package/lib/math/AcGeVector.d.ts.map +1 -0
- package/lib/math/AcGeVector.js +2 -0
- package/lib/math/AcGeVector.js.map +1 -0
- package/lib/math/AcGeVector2d.d.ts +361 -0
- package/lib/math/AcGeVector2d.d.ts.map +1 -0
- package/lib/math/AcGeVector2d.js +622 -0
- package/lib/math/AcGeVector2d.js.map +1 -0
- package/lib/math/AcGeVector3d.d.ts +493 -0
- package/lib/math/AcGeVector3d.d.ts.map +1 -0
- package/lib/math/AcGeVector3d.js +868 -0
- package/lib/math/AcGeVector3d.js.map +1 -0
- package/lib/math/index.d.ts +14 -0
- package/lib/math/index.d.ts.map +1 -0
- package/lib/math/index.js +14 -0
- package/lib/math/index.js.map +1 -0
- package/lib/util/AcGeConstants.d.ts +19 -0
- package/lib/util/AcGeConstants.d.ts.map +1 -0
- package/lib/util/AcGeConstants.js +25 -0
- package/lib/util/AcGeConstants.js.map +1 -0
- package/lib/util/AcGeGeometryUtil.d.ts +16 -0
- package/lib/util/AcGeGeometryUtil.d.ts.map +1 -0
- package/lib/util/AcGeGeometryUtil.js +56 -0
- package/lib/util/AcGeGeometryUtil.js.map +1 -0
- package/lib/util/AcGeMathUtil.d.ts +203 -0
- package/lib/util/AcGeMathUtil.d.ts.map +1 -0
- package/lib/util/AcGeMathUtil.js +585 -0
- package/lib/util/AcGeMathUtil.js.map +1 -0
- package/lib/util/AcGeTol.d.ts +91 -0
- package/lib/util/AcGeTol.d.ts.map +1 -0
- package/lib/util/AcGeTol.js +83 -0
- package/lib/util/AcGeTol.js.map +1 -0
- package/lib/util/index.d.ts +5 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +5 -0
- package/lib/util/index.js.map +1 -0
- package/package.json +42 -0
@@ -0,0 +1,868 @@
|
|
1
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
2
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
3
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
4
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
5
|
+
function step(op) {
|
6
|
+
if (f) throw new TypeError("Generator is already executing.");
|
7
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
8
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
9
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
10
|
+
switch (op[0]) {
|
11
|
+
case 0: case 1: t = op; break;
|
12
|
+
case 4: _.label++; return { value: op[1], done: false };
|
13
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
14
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
15
|
+
default:
|
16
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
17
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
18
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
19
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
20
|
+
if (t[2]) _.ops.pop();
|
21
|
+
_.trys.pop(); continue;
|
22
|
+
}
|
23
|
+
op = body.call(thisArg, _);
|
24
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
25
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
26
|
+
}
|
27
|
+
};
|
28
|
+
import { AcCmErrors } from '@mlightcad/common';
|
29
|
+
import { AcGeQuaternion } from './AcGeQuaternion';
|
30
|
+
/**
|
31
|
+
* Class representing a vector in 3-dimensional space. A 3d vector is an ordered triplet of
|
32
|
+
* numbers (labeled x, y, and z).
|
33
|
+
*/
|
34
|
+
var AcGeVector3d = /** @class */ (function () {
|
35
|
+
/**
|
36
|
+
* Vector may be constructed by three points, or by three float numbers,
|
37
|
+
* or by array of three numbers
|
38
|
+
*/
|
39
|
+
function AcGeVector3d(a, b, c) {
|
40
|
+
this.x = 0;
|
41
|
+
this.y = 0;
|
42
|
+
this.z = 0;
|
43
|
+
var argsLength = +(a !== undefined) + +(b !== undefined) + +(c !== undefined);
|
44
|
+
if (argsLength === 0) {
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
if (argsLength === 1 && a instanceof Array) {
|
48
|
+
this.x = a[0];
|
49
|
+
this.y = a[1];
|
50
|
+
this.z = a[2];
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
if (argsLength === 1) {
|
54
|
+
var _a = a, x = _a.x, y = _a.y, z = _a.z;
|
55
|
+
this.x = x;
|
56
|
+
this.y = y;
|
57
|
+
this.z = z || 0;
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (argsLength === 3) {
|
61
|
+
this.x = a;
|
62
|
+
this.y = b;
|
63
|
+
this.z = c;
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
throw AcCmErrors.ILLEGAL_PARAMETERS;
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* Sets the x, y and z components of this vector.
|
70
|
+
* @param x Input the x components of this vector.
|
71
|
+
* @param y Input the y components of this vector.
|
72
|
+
* @param z Input the z components of this vector.
|
73
|
+
* @returns Return this vector
|
74
|
+
*/
|
75
|
+
AcGeVector3d.prototype.set = function (x, y, z) {
|
76
|
+
if (z === undefined)
|
77
|
+
z = this.z; // sprite.scale.set(x,y)
|
78
|
+
this.x = x;
|
79
|
+
this.y = y;
|
80
|
+
this.z = z;
|
81
|
+
return this;
|
82
|
+
};
|
83
|
+
/**
|
84
|
+
* Set the x, y and z values of this vector both equal to scalar.
|
85
|
+
* @param scalar Input a scalar value
|
86
|
+
* @returns Return this vector
|
87
|
+
*/
|
88
|
+
AcGeVector3d.prototype.setScalar = function (scalar) {
|
89
|
+
this.x = scalar;
|
90
|
+
this.y = scalar;
|
91
|
+
this.z = scalar;
|
92
|
+
return this;
|
93
|
+
};
|
94
|
+
/**
|
95
|
+
* Replace this vector's x value with x.
|
96
|
+
* @param x Input the new vector's x value
|
97
|
+
* @returns Return this vector
|
98
|
+
*/
|
99
|
+
AcGeVector3d.prototype.setX = function (x) {
|
100
|
+
this.x = x;
|
101
|
+
return this;
|
102
|
+
};
|
103
|
+
/**
|
104
|
+
* Replace this vector's y value with y.
|
105
|
+
* @param y Input the new vector's y value
|
106
|
+
* @returns Return this vector
|
107
|
+
*/
|
108
|
+
AcGeVector3d.prototype.setY = function (y) {
|
109
|
+
this.y = y;
|
110
|
+
return this;
|
111
|
+
};
|
112
|
+
/**
|
113
|
+
* Replace this vector's z value with z.
|
114
|
+
* @param z Input the new vector's z value
|
115
|
+
* @returns Return this vector
|
116
|
+
*/
|
117
|
+
AcGeVector3d.prototype.setZ = function (z) {
|
118
|
+
this.z = z;
|
119
|
+
return this;
|
120
|
+
};
|
121
|
+
/**
|
122
|
+
* Set vector component by index - 0, 1 or 2.
|
123
|
+
* - If index equals 0 set x to value.
|
124
|
+
* - If index equals 1 set y to value.
|
125
|
+
* - If index equals 2 set z to value
|
126
|
+
* @param index Input index value - 0, 1 or 2.
|
127
|
+
* @param value Input value to be set
|
128
|
+
* @returns Return this vector
|
129
|
+
*/
|
130
|
+
AcGeVector3d.prototype.setComponent = function (index, value) {
|
131
|
+
switch (index) {
|
132
|
+
case 0:
|
133
|
+
this.x = value;
|
134
|
+
break;
|
135
|
+
case 1:
|
136
|
+
this.y = value;
|
137
|
+
break;
|
138
|
+
case 2:
|
139
|
+
this.z = value;
|
140
|
+
break;
|
141
|
+
default:
|
142
|
+
throw new Error('index is out of range: ' + index);
|
143
|
+
}
|
144
|
+
return this;
|
145
|
+
};
|
146
|
+
/**
|
147
|
+
* Return vector component by index - 0, 1 or 2.
|
148
|
+
* - If index equals 0 returns the x value.
|
149
|
+
* - If index equals 1 returns the y value.
|
150
|
+
* - If index equals 2 returns the z value.
|
151
|
+
* @param index Input index value - 0, 1 or 2.
|
152
|
+
* @returns Return vector component with the specified index
|
153
|
+
*/
|
154
|
+
AcGeVector3d.prototype.getComponent = function (index) {
|
155
|
+
switch (index) {
|
156
|
+
case 0:
|
157
|
+
return this.x;
|
158
|
+
case 1:
|
159
|
+
return this.y;
|
160
|
+
case 2:
|
161
|
+
return this.z;
|
162
|
+
default:
|
163
|
+
throw new Error('index is out of range: ' + index);
|
164
|
+
}
|
165
|
+
};
|
166
|
+
/**
|
167
|
+
* Return a new vector3 with the same x, y and z values as this one.
|
168
|
+
* @returns Return a new vector3 with the same x, y and z values as this one.
|
169
|
+
*/
|
170
|
+
AcGeVector3d.prototype.clone = function () {
|
171
|
+
return new AcGeVector3d(this.x, this.y, this.z);
|
172
|
+
};
|
173
|
+
/**
|
174
|
+
* Copy the values of the passed vector3's x, y and z properties to this vector3.
|
175
|
+
* @param v Input the vector to copy
|
176
|
+
* @returns Return this vector
|
177
|
+
*/
|
178
|
+
AcGeVector3d.prototype.copy = function (v) {
|
179
|
+
this.x = v.x;
|
180
|
+
this.y = v.y;
|
181
|
+
this.z = v.z || 0;
|
182
|
+
return this;
|
183
|
+
};
|
184
|
+
/**
|
185
|
+
* Add the specified 3d vector to this vector.
|
186
|
+
* @param v Input a 3d vector
|
187
|
+
* @returns Return this vector
|
188
|
+
*/
|
189
|
+
AcGeVector3d.prototype.add = function (v) {
|
190
|
+
this.x += v.x;
|
191
|
+
this.y += v.y;
|
192
|
+
this.z += v.z || 0;
|
193
|
+
return this;
|
194
|
+
};
|
195
|
+
/**
|
196
|
+
* Add the scalar value s to this vector's x, y and z values.
|
197
|
+
* @param s Input a scalar value
|
198
|
+
* @returns Return this vector
|
199
|
+
*/
|
200
|
+
AcGeVector3d.prototype.addScalar = function (s) {
|
201
|
+
this.x += s;
|
202
|
+
this.y += s;
|
203
|
+
this.z += s;
|
204
|
+
return this;
|
205
|
+
};
|
206
|
+
/**
|
207
|
+
* Set this vector to a + b.
|
208
|
+
* @param a Input the first 3d vector
|
209
|
+
* @param b Input the second 3d vector
|
210
|
+
* @returns Return this vector
|
211
|
+
*/
|
212
|
+
AcGeVector3d.prototype.addVectors = function (a, b) {
|
213
|
+
this.x = a.x + b.x;
|
214
|
+
this.y = a.y + b.y;
|
215
|
+
this.z = a.z + b.z;
|
216
|
+
return this;
|
217
|
+
};
|
218
|
+
/**
|
219
|
+
* Add the multiple of v and s to this vector.
|
220
|
+
* @param v Input a 3d vector
|
221
|
+
* @param s Input a scalar value
|
222
|
+
* @returns Return this vector
|
223
|
+
*/
|
224
|
+
AcGeVector3d.prototype.addScaledVector = function (v, s) {
|
225
|
+
this.x += v.x * s;
|
226
|
+
this.y += v.y * s;
|
227
|
+
this.z += v.z * s;
|
228
|
+
return this;
|
229
|
+
};
|
230
|
+
/**
|
231
|
+
* Subtract v from this vector.
|
232
|
+
* @param v Input a 3d vector to subtract
|
233
|
+
* @returns Return this vector
|
234
|
+
*/
|
235
|
+
AcGeVector3d.prototype.sub = function (v) {
|
236
|
+
this.x -= v.x;
|
237
|
+
this.y -= v.y;
|
238
|
+
this.z -= v.z;
|
239
|
+
return this;
|
240
|
+
};
|
241
|
+
/**
|
242
|
+
* Subtract s from this vector's x, y and z components.
|
243
|
+
* @param s Input a number value to substract
|
244
|
+
* @returns Return this vector
|
245
|
+
*/
|
246
|
+
AcGeVector3d.prototype.subScalar = function (s) {
|
247
|
+
this.x -= s;
|
248
|
+
this.y -= s;
|
249
|
+
this.z -= s;
|
250
|
+
return this;
|
251
|
+
};
|
252
|
+
/**
|
253
|
+
* Set this vector to a - b.
|
254
|
+
* @param a Input a 3d vector
|
255
|
+
* @param b Input a 3d vector
|
256
|
+
* @returns Return this vector
|
257
|
+
*/
|
258
|
+
AcGeVector3d.prototype.subVectors = function (a, b) {
|
259
|
+
this.x = a.x - b.x;
|
260
|
+
this.y = a.y - b.y;
|
261
|
+
this.z = a.z - b.z;
|
262
|
+
return this;
|
263
|
+
};
|
264
|
+
/**
|
265
|
+
* Multiply this vector by v.
|
266
|
+
* @param v Input a 3d vector
|
267
|
+
* @returns Return this vector
|
268
|
+
*/
|
269
|
+
AcGeVector3d.prototype.multiply = function (v) {
|
270
|
+
this.x *= v.x;
|
271
|
+
this.y *= v.y;
|
272
|
+
this.z *= v.z;
|
273
|
+
return this;
|
274
|
+
};
|
275
|
+
/**
|
276
|
+
* Multiply this vector by scalar s.
|
277
|
+
* @param scalar Input a scalar value
|
278
|
+
* @returns Return this vector
|
279
|
+
*/
|
280
|
+
AcGeVector3d.prototype.multiplyScalar = function (scalar) {
|
281
|
+
this.x *= scalar;
|
282
|
+
this.y *= scalar;
|
283
|
+
this.z *= scalar;
|
284
|
+
return this;
|
285
|
+
};
|
286
|
+
/**
|
287
|
+
* Set this vector equal to a * b, component-wise.
|
288
|
+
* @param a Input a 3d vector
|
289
|
+
* @param b Input a 3d vector
|
290
|
+
* @returns Return this vector
|
291
|
+
*/
|
292
|
+
AcGeVector3d.prototype.multiplyVectors = function (a, b) {
|
293
|
+
this.x = a.x * b.x;
|
294
|
+
this.y = a.y * b.y;
|
295
|
+
this.z = a.z * b.z;
|
296
|
+
return this;
|
297
|
+
};
|
298
|
+
/**
|
299
|
+
* Apply euler transform to this vector by converting the Euler object to a Quaternion and applying.
|
300
|
+
* @param euler Input an euler object
|
301
|
+
* @returns Return this vector
|
302
|
+
*/
|
303
|
+
AcGeVector3d.prototype.applyEuler = function (euler) {
|
304
|
+
return this.applyQuaternion(_quaternion.setFromEuler(euler));
|
305
|
+
};
|
306
|
+
/**
|
307
|
+
* Apply a rotation specified by an axis and an angle to this vector.
|
308
|
+
* @param axis Input a normalized Vector3.
|
309
|
+
* @param angle Input an angle in radians.
|
310
|
+
* @returns Return this vector
|
311
|
+
*/
|
312
|
+
AcGeVector3d.prototype.applyAxisAngle = function (axis, angle) {
|
313
|
+
return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
|
314
|
+
};
|
315
|
+
/**
|
316
|
+
* Multipliy this vector by m
|
317
|
+
* @param m Input a 3*3 matrix
|
318
|
+
* @returns Return this vector
|
319
|
+
*/
|
320
|
+
AcGeVector3d.prototype.applyMatrix3 = function (m) {
|
321
|
+
var x = this.x, y = this.y, z = this.z;
|
322
|
+
var e = m.elements;
|
323
|
+
this.x = e[0] * x + e[3] * y + e[6] * z;
|
324
|
+
this.y = e[1] * x + e[4] * y + e[7] * z;
|
325
|
+
this.z = e[2] * x + e[5] * y + e[8] * z;
|
326
|
+
return this;
|
327
|
+
};
|
328
|
+
/**
|
329
|
+
* Multiply this vector by normal matrix m and normalizes the result.
|
330
|
+
* @param m Input one normal matrix
|
331
|
+
* @returns Return this vector
|
332
|
+
*/
|
333
|
+
AcGeVector3d.prototype.applyNormalMatrix = function (m) {
|
334
|
+
return this.applyMatrix3(m).normalize();
|
335
|
+
};
|
336
|
+
/**
|
337
|
+
* Multiplies this vector (with an implicit 1 in the 4th dimension) by m, and divides by perspective.
|
338
|
+
* @param m Input one 4x4 matrix
|
339
|
+
* @returns Return this vector
|
340
|
+
*/
|
341
|
+
AcGeVector3d.prototype.applyMatrix3d = function (m) {
|
342
|
+
var x = this.x, y = this.y, z = this.z;
|
343
|
+
var e = m.elements;
|
344
|
+
var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
|
345
|
+
this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
|
346
|
+
this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
|
347
|
+
this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
|
348
|
+
return this;
|
349
|
+
};
|
350
|
+
/**
|
351
|
+
* Apply a quaternion transform to this vector.
|
352
|
+
* @param q Input one quaternion transform
|
353
|
+
* @returns Return this vector
|
354
|
+
*/
|
355
|
+
AcGeVector3d.prototype.applyQuaternion = function (q) {
|
356
|
+
// quaternion q is assumed to have unit length
|
357
|
+
var vx = this.x, vy = this.y, vz = this.z;
|
358
|
+
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
359
|
+
// t = 2 * cross( q.xyz, v );
|
360
|
+
var tx = 2 * (qy * vz - qz * vy);
|
361
|
+
var ty = 2 * (qz * vx - qx * vz);
|
362
|
+
var tz = 2 * (qx * vy - qy * vx);
|
363
|
+
// v + q.w * t + cross( q.xyz, t );
|
364
|
+
this.x = vx + qw * tx + qy * tz - qz * ty;
|
365
|
+
this.y = vy + qw * ty + qz * tx - qx * tz;
|
366
|
+
this.z = vz + qw * tz + qx * ty - qy * tx;
|
367
|
+
return this;
|
368
|
+
};
|
369
|
+
/**
|
370
|
+
* Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and
|
371
|
+
* then normalizes the result.
|
372
|
+
* @param m
|
373
|
+
* @returns
|
374
|
+
*/
|
375
|
+
AcGeVector3d.prototype.transformDirection = function (m) {
|
376
|
+
// input: THREE.Matrix4 affine matrix
|
377
|
+
// vector interpreted as a direction
|
378
|
+
var x = this.x, y = this.y, z = this.z;
|
379
|
+
var e = m.elements;
|
380
|
+
this.x = e[0] * x + e[4] * y + e[8] * z;
|
381
|
+
this.y = e[1] * x + e[5] * y + e[9] * z;
|
382
|
+
this.z = e[2] * x + e[6] * y + e[10] * z;
|
383
|
+
return this.normalize();
|
384
|
+
};
|
385
|
+
/**
|
386
|
+
* Divide this vector by v.
|
387
|
+
* @param v Input a 3d vector
|
388
|
+
* @returns Return this vector
|
389
|
+
*/
|
390
|
+
AcGeVector3d.prototype.divide = function (v) {
|
391
|
+
this.x /= v.x;
|
392
|
+
this.y /= v.y;
|
393
|
+
this.z /= v.z;
|
394
|
+
return this;
|
395
|
+
};
|
396
|
+
/**
|
397
|
+
* Divide this vector by scalar s.
|
398
|
+
* @param scalar Input a scalar value
|
399
|
+
* @returns Return this vector
|
400
|
+
*/
|
401
|
+
AcGeVector3d.prototype.divideScalar = function (scalar) {
|
402
|
+
return this.multiplyScalar(1 / scalar);
|
403
|
+
};
|
404
|
+
/**
|
405
|
+
* If this vector's x, y or z value is greater than v's x, y or z value, replace that value with
|
406
|
+
* the corresponding min value.
|
407
|
+
* @param v Input a 3d vector
|
408
|
+
* @returns Return this vector
|
409
|
+
*/
|
410
|
+
AcGeVector3d.prototype.min = function (v) {
|
411
|
+
this.x = Math.min(this.x, v.x);
|
412
|
+
this.y = Math.min(this.y, v.y);
|
413
|
+
this.z = Math.min(this.z, v.z);
|
414
|
+
return this;
|
415
|
+
};
|
416
|
+
/**
|
417
|
+
* If this vector's x, y or z value is less than v's x, y or z value, replace that value with
|
418
|
+
* the corresponding max value.
|
419
|
+
* @param v Input a 3d vector
|
420
|
+
* @returns Return this vector
|
421
|
+
*/
|
422
|
+
AcGeVector3d.prototype.max = function (v) {
|
423
|
+
this.x = Math.max(this.x, v.x);
|
424
|
+
this.y = Math.max(this.y, v.y);
|
425
|
+
this.z = Math.max(this.z, v.z);
|
426
|
+
return this;
|
427
|
+
};
|
428
|
+
/**
|
429
|
+
* If this vector's x, y or z value is greater than the max vector's x, y or z value, it is
|
430
|
+
* replaced by the corresponding value. If this vector's x, y or z value is less than the min
|
431
|
+
* vector's x, y or z value, it is replaced by the corresponding value.
|
432
|
+
* @param min Input the minimum x, y and z values.
|
433
|
+
* @param max Input the maximum x, y and z values in the desired range
|
434
|
+
* @returns Return this vector
|
435
|
+
*/
|
436
|
+
AcGeVector3d.prototype.clamp = function (min, max) {
|
437
|
+
// assumes min < max, componentwise
|
438
|
+
this.x = Math.max(min.x, Math.min(max.x, this.x));
|
439
|
+
this.y = Math.max(min.y, Math.min(max.y, this.y));
|
440
|
+
this.z = Math.max(min.z, Math.min(max.z, this.z));
|
441
|
+
return this;
|
442
|
+
};
|
443
|
+
/**
|
444
|
+
* If this vector's x, y or z values are greater than the max value, they are replaced by the
|
445
|
+
* max value. If this vector's x, y or z values are less than the min value, they are replaced
|
446
|
+
* by the min value.
|
447
|
+
* @param minVal Input the minimum value the components will be clamped to
|
448
|
+
* @param maxVal Input the maximum value the components will be clamped to
|
449
|
+
* @returns Return this vector
|
450
|
+
*/
|
451
|
+
AcGeVector3d.prototype.clampScalar = function (minVal, maxVal) {
|
452
|
+
this.x = Math.max(minVal, Math.min(maxVal, this.x));
|
453
|
+
this.y = Math.max(minVal, Math.min(maxVal, this.y));
|
454
|
+
this.z = Math.max(minVal, Math.min(maxVal, this.z));
|
455
|
+
return this;
|
456
|
+
};
|
457
|
+
/**
|
458
|
+
* If this vector's length is greater than the max value, the vector will be scaled down so
|
459
|
+
* its length is the max value. If this vector's length is less than the min value, the vector
|
460
|
+
* will be scaled up so its length is the min value.
|
461
|
+
* @param min Input the minimum value the length will be clamped to
|
462
|
+
* @param max Input the maximum value the length will be clamped to
|
463
|
+
* @returns Return this vector
|
464
|
+
*/
|
465
|
+
AcGeVector3d.prototype.clampLength = function (min, max) {
|
466
|
+
var length = this.length();
|
467
|
+
return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
|
468
|
+
};
|
469
|
+
/**
|
470
|
+
* The components of this vector are rounded down to the nearest integer value.
|
471
|
+
* @returns Return this vector
|
472
|
+
*/
|
473
|
+
AcGeVector3d.prototype.floor = function () {
|
474
|
+
this.x = Math.floor(this.x);
|
475
|
+
this.y = Math.floor(this.y);
|
476
|
+
this.z = Math.floor(this.z);
|
477
|
+
return this;
|
478
|
+
};
|
479
|
+
/**
|
480
|
+
* The x, y and z components of this vector are rounded up to the nearest integer value.
|
481
|
+
* @returns Return this vector
|
482
|
+
*/
|
483
|
+
AcGeVector3d.prototype.ceil = function () {
|
484
|
+
this.x = Math.ceil(this.x);
|
485
|
+
this.y = Math.ceil(this.y);
|
486
|
+
this.z = Math.ceil(this.z);
|
487
|
+
return this;
|
488
|
+
};
|
489
|
+
/**
|
490
|
+
* The components of this vector are rounded to the nearest integer value.
|
491
|
+
* @returns Return this vector
|
492
|
+
*/
|
493
|
+
AcGeVector3d.prototype.round = function () {
|
494
|
+
this.x = Math.round(this.x);
|
495
|
+
this.y = Math.round(this.y);
|
496
|
+
this.z = Math.round(this.z);
|
497
|
+
return this;
|
498
|
+
};
|
499
|
+
/**
|
500
|
+
* The components of this vector are rounded towards zero (up if negative, down if positive)
|
501
|
+
* to an integer value.
|
502
|
+
* @returns Return this vector
|
503
|
+
*/
|
504
|
+
AcGeVector3d.prototype.roundToZero = function () {
|
505
|
+
this.x = Math.trunc(this.x);
|
506
|
+
this.y = Math.trunc(this.y);
|
507
|
+
this.z = Math.trunc(this.z);
|
508
|
+
return this;
|
509
|
+
};
|
510
|
+
/**
|
511
|
+
* Inverts this vector - i.e. sets x = -x, y = -y and z = -z.
|
512
|
+
* @returns Return this vector
|
513
|
+
*/
|
514
|
+
AcGeVector3d.prototype.negate = function () {
|
515
|
+
this.x = -this.x;
|
516
|
+
this.y = -this.y;
|
517
|
+
this.z = -this.z;
|
518
|
+
return this;
|
519
|
+
};
|
520
|
+
/**
|
521
|
+
* Calculate the dot product of this vector and v.
|
522
|
+
* @param v Input a 3d vector
|
523
|
+
* @returns Return the dot product of this vector and v
|
524
|
+
*/
|
525
|
+
AcGeVector3d.prototype.dot = function (v) {
|
526
|
+
return this.x * v.x + this.y * v.y + this.z * v.z;
|
527
|
+
};
|
528
|
+
/**
|
529
|
+
* Return true if vec is parallel to this vector
|
530
|
+
* @param vec Input vector to check parallelism
|
531
|
+
* @returns Return true if vec is parallel to this vector
|
532
|
+
*/
|
533
|
+
AcGeVector3d.prototype.isParallelTo = function (vec) {
|
534
|
+
var dotProduct = this.dot(vec);
|
535
|
+
var magnitudeA = this.length();
|
536
|
+
var magnitudeB = vec.length();
|
537
|
+
return Math.abs(dotProduct) === magnitudeA * magnitudeB;
|
538
|
+
};
|
539
|
+
/**
|
540
|
+
* Compute the square of the Euclidean length (straight-line length) from (0, 0, 0)
|
541
|
+
* to (x, y, z). If you are comparing the lengths of vectors, you should compare the
|
542
|
+
* length squared instead as it is slightly more efficient to calculate.
|
543
|
+
* @returns Return the square of the Euclidean length
|
544
|
+
*/
|
545
|
+
AcGeVector3d.prototype.lengthSq = function () {
|
546
|
+
return this.x * this.x + this.y * this.y + this.z * this.z;
|
547
|
+
};
|
548
|
+
/**
|
549
|
+
* Compute the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z).
|
550
|
+
* @returns Return the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z).
|
551
|
+
*/
|
552
|
+
AcGeVector3d.prototype.length = function () {
|
553
|
+
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
554
|
+
};
|
555
|
+
/**
|
556
|
+
* Compute the Manhattan length of this vector.
|
557
|
+
* @returns Return the Manhattan length of this vector.
|
558
|
+
*/
|
559
|
+
AcGeVector3d.prototype.manhattanLength = function () {
|
560
|
+
return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
|
561
|
+
};
|
562
|
+
/**
|
563
|
+
* Convert this vector to a unit vector - that is, sets it equal to a vector with
|
564
|
+
* the same direction as this one, but length 1.
|
565
|
+
* @returns Return this vector
|
566
|
+
*/
|
567
|
+
AcGeVector3d.prototype.normalize = function () {
|
568
|
+
return this.divideScalar(this.length() || 1);
|
569
|
+
};
|
570
|
+
/**
|
571
|
+
* Set this vector to a vector with the same direction as this one, but length l.
|
572
|
+
* @param l Input a lenght value
|
573
|
+
* @returns Return this vector
|
574
|
+
*/
|
575
|
+
AcGeVector3d.prototype.setLength = function (l) {
|
576
|
+
return this.normalize().multiplyScalar(l);
|
577
|
+
};
|
578
|
+
/**
|
579
|
+
* Linearly interpolate between this vector and v, where alpha is the percent distance along
|
580
|
+
* the line - alpha = 0 will be this vector, and alpha = 1 will be v.
|
581
|
+
* @param v Input vector to interpolate towards
|
582
|
+
* @param alpha Input interpolation factor, typically in the closed interval [0, 1]
|
583
|
+
* @returns Return this vector
|
584
|
+
*/
|
585
|
+
AcGeVector3d.prototype.lerp = function (v, alpha) {
|
586
|
+
this.x += (v.x - this.x) * alpha;
|
587
|
+
this.y += (v.y - this.y) * alpha;
|
588
|
+
this.z += (v.z - this.z) * alpha;
|
589
|
+
return this;
|
590
|
+
};
|
591
|
+
/**
|
592
|
+
* Set this vector to be the vector linearly interpolated between v1 and v2 where alpha is
|
593
|
+
* the percent distance along the line connecting the two vectors - alpha = 0 will be v1,
|
594
|
+
* and alpha = 1 will be v2.
|
595
|
+
* @param v1 Input the starting vector
|
596
|
+
* @param v2 Input vector to interpolate towards
|
597
|
+
* @param alpha Input interpolation factor, typically in the closed interval [0, 1].
|
598
|
+
* @returns Return this vector
|
599
|
+
*/
|
600
|
+
AcGeVector3d.prototype.lerpVectors = function (v1, v2, alpha) {
|
601
|
+
this.x = v1.x + (v2.x - v1.x) * alpha;
|
602
|
+
this.y = v1.y + (v2.y - v1.y) * alpha;
|
603
|
+
this.z = v1.z + (v2.z - v1.z) * alpha;
|
604
|
+
return this;
|
605
|
+
};
|
606
|
+
/**
|
607
|
+
* Set this vector to cross product of itself and v.
|
608
|
+
* @param v Input a 3d vector
|
609
|
+
* @returns Return this vector
|
610
|
+
*/
|
611
|
+
AcGeVector3d.prototype.cross = function (v) {
|
612
|
+
return this.crossVectors(this, v);
|
613
|
+
};
|
614
|
+
/**
|
615
|
+
* Set this vector to cross product of a and b.
|
616
|
+
* @param a Input a 3d vector
|
617
|
+
* @param b Input a 3d vector
|
618
|
+
* @returns Return this vector
|
619
|
+
*/
|
620
|
+
AcGeVector3d.prototype.crossVectors = function (a, b) {
|
621
|
+
var ax = a.x, ay = a.y, az = a.z;
|
622
|
+
var bx = b.x, by = b.y, bz = b.z;
|
623
|
+
this.x = ay * bz - az * by;
|
624
|
+
this.y = az * bx - ax * bz;
|
625
|
+
this.z = ax * by - ay * bx;
|
626
|
+
return this;
|
627
|
+
};
|
628
|
+
/**
|
629
|
+
* Project this vector onto v.
|
630
|
+
* @param v Input a 3d vector
|
631
|
+
* @returns Return this vector
|
632
|
+
*/
|
633
|
+
AcGeVector3d.prototype.projectOnVector = function (v) {
|
634
|
+
var denominator = v.lengthSq();
|
635
|
+
if (denominator === 0)
|
636
|
+
return this.set(0, 0, 0);
|
637
|
+
var scalar = v.dot(this) / denominator;
|
638
|
+
return this.copy(v).multiplyScalar(scalar);
|
639
|
+
};
|
640
|
+
/**
|
641
|
+
* Project this vector onto a plane by subtracting this vector projected onto the plane's normal
|
642
|
+
* from this vector.
|
643
|
+
* @param planeNormal Input a vector representing a plane normal.
|
644
|
+
* @returns Return this vector
|
645
|
+
*/
|
646
|
+
AcGeVector3d.prototype.projectOnPlane = function (planeNormal) {
|
647
|
+
_vector.copy(this).projectOnVector(planeNormal);
|
648
|
+
return this.sub(_vector);
|
649
|
+
};
|
650
|
+
/**
|
651
|
+
* Reflect this vector off of plane orthogonal to normal. Normal is assumed to have unit length.
|
652
|
+
* @param normal Input the normal to the reflecting plane
|
653
|
+
* @returns Return this vector
|
654
|
+
*/
|
655
|
+
AcGeVector3d.prototype.reflect = function (normal) {
|
656
|
+
// reflect incident vector off plane orthogonal to normal
|
657
|
+
// normal is assumed to have unit length
|
658
|
+
return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
|
659
|
+
};
|
660
|
+
/**
|
661
|
+
* Return the angle between this vector and vector v in radians.
|
662
|
+
* @param v Input a 3d vector
|
663
|
+
* @returns Return the angle between this vector and vector v in radians.
|
664
|
+
*/
|
665
|
+
AcGeVector3d.prototype.angleTo = function (v) {
|
666
|
+
var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
|
667
|
+
if (denominator === 0)
|
668
|
+
return Math.PI / 2;
|
669
|
+
var theta = this.dot(v) / denominator;
|
670
|
+
// clamp, to handle numerical problems
|
671
|
+
return Math.acos(Math.max(-1, Math.min(1, theta)));
|
672
|
+
};
|
673
|
+
/**
|
674
|
+
* Compute the distance from this vector to v.
|
675
|
+
* @param v Input a 3d vector
|
676
|
+
* @returns Return the distance from this vector to v
|
677
|
+
*/
|
678
|
+
AcGeVector3d.prototype.distanceTo = function (v) {
|
679
|
+
return Math.sqrt(this.distanceToSquared(v));
|
680
|
+
};
|
681
|
+
/**
|
682
|
+
* Compute the squared distance from this vector to v. If you are just comparing the distance
|
683
|
+
* with another distance, you should compare the distance squared instead as it is slightly more
|
684
|
+
* efficient to calculate.
|
685
|
+
* @param v Input a 3d vector
|
686
|
+
* @returns Return the squared distance from this vector to v
|
687
|
+
*/
|
688
|
+
AcGeVector3d.prototype.distanceToSquared = function (v) {
|
689
|
+
var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
|
690
|
+
return dx * dx + dy * dy + dz * dz;
|
691
|
+
};
|
692
|
+
/**
|
693
|
+
* Compute the Manhattan distance from this vector to v.
|
694
|
+
* @param v Input a 3d vector
|
695
|
+
* @returns Return the Manhattan distance from this vector to v
|
696
|
+
*/
|
697
|
+
AcGeVector3d.prototype.manhattanDistanceTo = function (v) {
|
698
|
+
return (Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z));
|
699
|
+
};
|
700
|
+
// setFromSpherical(s) {
|
701
|
+
// return this.setFromSphericalCoords(s.radius, s.phi, s.theta)
|
702
|
+
// }
|
703
|
+
// setFromSphericalCoords(radius, phi, theta) {
|
704
|
+
// const sinPhiRadius = Math.sin(phi) * radius
|
705
|
+
// this.x = sinPhiRadius * Math.sin(theta)
|
706
|
+
// this.y = Math.cos(phi) * radius
|
707
|
+
// this.z = sinPhiRadius * Math.cos(theta)
|
708
|
+
// return this
|
709
|
+
// }
|
710
|
+
// setFromCylindrical(c) {
|
711
|
+
// return this.setFromCylindricalCoords(c.radius, c.theta, c.y)
|
712
|
+
// }
|
713
|
+
// setFromCylindricalCoords(radius, theta, y) {
|
714
|
+
// this.x = radius * Math.sin(theta)
|
715
|
+
// this.y = y
|
716
|
+
// this.z = radius * Math.cos(theta)
|
717
|
+
// return this
|
718
|
+
// }
|
719
|
+
/**
|
720
|
+
* Set this vector to the position elements of the transformation matrix m.
|
721
|
+
* @param m Input one 4x4 matrix
|
722
|
+
* @returns Return this vector
|
723
|
+
*/
|
724
|
+
AcGeVector3d.prototype.setFromMatrixPosition = function (m) {
|
725
|
+
var e = m.elements;
|
726
|
+
this.x = e[12];
|
727
|
+
this.y = e[13];
|
728
|
+
this.z = e[14];
|
729
|
+
return this;
|
730
|
+
};
|
731
|
+
/**
|
732
|
+
* Set this vector to the scale elements of the transformation matrix m.
|
733
|
+
* @param m Input one 4x4 matrix
|
734
|
+
* @returns Return this vector
|
735
|
+
*/
|
736
|
+
AcGeVector3d.prototype.setFromMatrixScale = function (m) {
|
737
|
+
var sx = this.setFromMatrixColumn(m, 0).length();
|
738
|
+
var sy = this.setFromMatrixColumn(m, 1).length();
|
739
|
+
var sz = this.setFromMatrixColumn(m, 2).length();
|
740
|
+
this.x = sx;
|
741
|
+
this.y = sy;
|
742
|
+
this.z = sz;
|
743
|
+
return this;
|
744
|
+
};
|
745
|
+
/**
|
746
|
+
* Set this vector's x, y and z components from index column of matrix.
|
747
|
+
* @param m Input one 4x4 matrix
|
748
|
+
* @param index Input column index
|
749
|
+
* @returns Return this vector
|
750
|
+
*/
|
751
|
+
AcGeVector3d.prototype.setFromMatrixColumn = function (m, index) {
|
752
|
+
return this.fromArray(m.elements, index * 4);
|
753
|
+
};
|
754
|
+
/**
|
755
|
+
* Set this vector's x, y and z components from index column of matrix.
|
756
|
+
* @param m Input one 3x3 matrix
|
757
|
+
* @param index Input column index
|
758
|
+
* @returns Return this vector
|
759
|
+
*/
|
760
|
+
AcGeVector3d.prototype.setFromMatrix3Column = function (m, index) {
|
761
|
+
return this.fromArray(m.elements, index * 3);
|
762
|
+
};
|
763
|
+
/**
|
764
|
+
* Return true if the components of this vector and v are strictly equal; false otherwise.
|
765
|
+
* @param v Input a 3d vector
|
766
|
+
* @returns Return true if the components of this vector and v are strictly equal; false otherwise.
|
767
|
+
*/
|
768
|
+
AcGeVector3d.prototype.equals = function (v) {
|
769
|
+
return v.x === this.x && v.y === this.y && v.z === this.z;
|
770
|
+
};
|
771
|
+
/**
|
772
|
+
* Set this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] and
|
773
|
+
* z value to be array[ offset + 2 ].
|
774
|
+
* @param array Input the source array.
|
775
|
+
* @param offset (optional) Input offset into the array. Default is 0.
|
776
|
+
* @returns Return this vector
|
777
|
+
*/
|
778
|
+
AcGeVector3d.prototype.fromArray = function (array, offset) {
|
779
|
+
if (offset === void 0) { offset = 0; }
|
780
|
+
this.x = array[offset];
|
781
|
+
this.y = array[offset + 1];
|
782
|
+
this.z = array[offset + 2];
|
783
|
+
return this;
|
784
|
+
};
|
785
|
+
/**
|
786
|
+
* Return an array [x, y, z], or copies x, y and z into the provided array.
|
787
|
+
* @param array (optional) Input array to store this vector to. If this is not provided a new array will be created.
|
788
|
+
* @param offset (optional) Input optional offset into the array.
|
789
|
+
* @returns Return an array [x, y, z], or copies x, y and z into the provided array.
|
790
|
+
*/
|
791
|
+
AcGeVector3d.prototype.toArray = function (array, offset) {
|
792
|
+
if (array === void 0) { array = []; }
|
793
|
+
if (offset === void 0) { offset = 0; }
|
794
|
+
array[offset] = this.x;
|
795
|
+
array[offset + 1] = this.y;
|
796
|
+
array[offset + 2] = this.z;
|
797
|
+
return array;
|
798
|
+
};
|
799
|
+
/**
|
800
|
+
* Set each component of this vector to a pseudo-random value between 0 and 1, excluding 1.
|
801
|
+
* @returns Return this vector
|
802
|
+
*/
|
803
|
+
AcGeVector3d.prototype.random = function () {
|
804
|
+
this.x = Math.random();
|
805
|
+
this.y = Math.random();
|
806
|
+
this.z = Math.random();
|
807
|
+
return this;
|
808
|
+
};
|
809
|
+
/**
|
810
|
+
* Set this vector to a uniformly random point on a unit sphere.
|
811
|
+
* @returns Return this vector
|
812
|
+
*/
|
813
|
+
AcGeVector3d.prototype.randomDirection = function () {
|
814
|
+
// https://mathworld.wolfram.com/SpherePointPicking.html
|
815
|
+
var theta = Math.random() * Math.PI * 2;
|
816
|
+
var u = Math.random() * 2 - 1;
|
817
|
+
var c = Math.sqrt(1 - u * u);
|
818
|
+
this.x = c * Math.cos(theta);
|
819
|
+
this.y = u;
|
820
|
+
this.z = c * Math.sin(theta);
|
821
|
+
return this;
|
822
|
+
};
|
823
|
+
AcGeVector3d.prototype[Symbol.iterator] = function () {
|
824
|
+
return __generator(this, function (_a) {
|
825
|
+
switch (_a.label) {
|
826
|
+
case 0: return [4 /*yield*/, this.x];
|
827
|
+
case 1:
|
828
|
+
_a.sent();
|
829
|
+
return [4 /*yield*/, this.y];
|
830
|
+
case 2:
|
831
|
+
_a.sent();
|
832
|
+
return [4 /*yield*/, this.z];
|
833
|
+
case 3:
|
834
|
+
_a.sent();
|
835
|
+
return [2 /*return*/];
|
836
|
+
}
|
837
|
+
});
|
838
|
+
};
|
839
|
+
/**
|
840
|
+
* X-Axis
|
841
|
+
*/
|
842
|
+
AcGeVector3d.X_AXIS = Object.freeze(new AcGeVector3d(1, 0, 0));
|
843
|
+
/**
|
844
|
+
* Negative X-Axis
|
845
|
+
*/
|
846
|
+
AcGeVector3d.NEGATIVE_X_AXIS = Object.freeze(new AcGeVector3d(-1, 0, 0));
|
847
|
+
/**
|
848
|
+
* Y-Axis
|
849
|
+
*/
|
850
|
+
AcGeVector3d.Y_AXIS = Object.freeze(new AcGeVector3d(0, 1, 0));
|
851
|
+
/**
|
852
|
+
* Negative Y-Axis
|
853
|
+
*/
|
854
|
+
AcGeVector3d.NEGATIVE_Y_AXIS = Object.freeze(new AcGeVector3d(0, -1, 0));
|
855
|
+
/**
|
856
|
+
* Z-Axis
|
857
|
+
*/
|
858
|
+
AcGeVector3d.Z_AXIS = Object.freeze(new AcGeVector3d(0, 0, 1));
|
859
|
+
/**
|
860
|
+
* Negative Z-Axis
|
861
|
+
*/
|
862
|
+
AcGeVector3d.NEGATIVE_Z_AXIS = Object.freeze(new AcGeVector3d(0, 0, -1));
|
863
|
+
return AcGeVector3d;
|
864
|
+
}());
|
865
|
+
export { AcGeVector3d };
|
866
|
+
var _vector = /*@__PURE__*/ new AcGeVector3d();
|
867
|
+
var _quaternion = /*@__PURE__*/ new AcGeQuaternion();
|
868
|
+
//# sourceMappingURL=AcGeVector3d.js.map
|