xl-public-utils 1.0.10 → 1.0.12
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/index.d.ts +60 -3
- package/index.js +2 -1
- package/package.json +4 -2
- package/src/threeFont/Curve/Curve.js +349 -0
- package/src/threeFont/Curve/CurvePath.js +202 -0
- package/src/threeFont/Curve/Interpolations.js +57 -0
- package/src/threeFont/Curve/Shape.js +77 -0
- package/src/threeFont/Math/MathUtils.js +526 -0
- package/src/threeFont/Math/Matrix4.js +863 -0
- package/src/threeFont/Math/Quaternion.js +584 -0
- package/src/threeFont/Math/Vector2.js +373 -0
- package/src/threeFont/Math/Vector3.js +617 -0
- package/src/threeFont/TextGeometry/Earcut.js +634 -0
- package/src/threeFont/TextGeometry/ExtrudeGeometry.js +647 -0
- package/src/threeFont/TextGeometry/FontLoader.js +114 -0
- package/src/threeFont/TextGeometry/Path.js +146 -0
- package/src/threeFont/TextGeometry/ShapePath.js +222 -0
- package/src/threeFont/TextGeometry/ShapeUtils.js +70 -0
- package/src/threeFont/curves/CubicBezierCurve.js +66 -0
- package/src/threeFont/curves/Curves.js +10 -0
- package/src/threeFont/curves/EllipseCurve.js +130 -0
- package/src/threeFont/curves/LineCurve.js +70 -0
- package/src/threeFont/curves/QuadraticBezierCurve.js +61 -0
- package/src/threeFont/curves/SplineCurve.js +76 -0
- package/src/threeFont/index.js +166 -0
- package/src/vtkUtils.js +55 -28
- package/tsconfig.json +1 -1
- package/types/vtkUtils.d.ts +22 -8
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
class Vector2 {
|
|
2
|
+
constructor(x = 0, y = 0) {
|
|
3
|
+
this.isVector2 = true;
|
|
4
|
+
|
|
5
|
+
this.x = x;
|
|
6
|
+
this.y = y;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get width() {
|
|
10
|
+
return this.x;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
set width(value) {
|
|
14
|
+
this.x = value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get height() {
|
|
18
|
+
return this.y;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
set height(value) {
|
|
22
|
+
this.y = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
set(x, y) {
|
|
26
|
+
this.x = x;
|
|
27
|
+
this.y = y;
|
|
28
|
+
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setScalar(scalar) {
|
|
33
|
+
this.x = scalar;
|
|
34
|
+
this.y = scalar;
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setX(x) {
|
|
40
|
+
this.x = x;
|
|
41
|
+
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setY(y) {
|
|
46
|
+
this.y = y;
|
|
47
|
+
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setComponent(index, value) {
|
|
52
|
+
switch (index) {
|
|
53
|
+
case 0:
|
|
54
|
+
this.x = value;
|
|
55
|
+
break;
|
|
56
|
+
case 1:
|
|
57
|
+
this.y = value;
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new Error('index is out of range: ' + index);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getComponent(index) {
|
|
67
|
+
switch (index) {
|
|
68
|
+
case 0:
|
|
69
|
+
return this.x;
|
|
70
|
+
case 1:
|
|
71
|
+
return this.y;
|
|
72
|
+
default:
|
|
73
|
+
throw new Error('index is out of range: ' + index);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
clone() {
|
|
78
|
+
return new this.constructor(this.x, this.y);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
copy(v) {
|
|
82
|
+
this.x = v.x;
|
|
83
|
+
this.y = v.y;
|
|
84
|
+
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
add(v, w) {
|
|
89
|
+
if (w !== undefined) {
|
|
90
|
+
console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
|
|
91
|
+
return this.addVectors(v, w);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.x += v.x;
|
|
95
|
+
this.y += v.y;
|
|
96
|
+
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
addScalar(s) {
|
|
101
|
+
this.x += s;
|
|
102
|
+
this.y += s;
|
|
103
|
+
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
addVectors(a, b) {
|
|
108
|
+
this.x = a.x + b.x;
|
|
109
|
+
this.y = a.y + b.y;
|
|
110
|
+
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
addScaledVector(v, s) {
|
|
115
|
+
this.x += v.x * s;
|
|
116
|
+
this.y += v.y * s;
|
|
117
|
+
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
sub(v, w) {
|
|
122
|
+
if (w !== undefined) {
|
|
123
|
+
console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
|
|
124
|
+
return this.subVectors(v, w);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.x -= v.x;
|
|
128
|
+
this.y -= v.y;
|
|
129
|
+
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
subScalar(s) {
|
|
134
|
+
this.x -= s;
|
|
135
|
+
this.y -= s;
|
|
136
|
+
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
subVectors(a, b) {
|
|
141
|
+
this.x = a.x - b.x;
|
|
142
|
+
this.y = a.y - b.y;
|
|
143
|
+
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
multiply(v) {
|
|
148
|
+
this.x *= v.x;
|
|
149
|
+
this.y *= v.y;
|
|
150
|
+
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
multiplyScalar(scalar) {
|
|
155
|
+
this.x *= scalar;
|
|
156
|
+
this.y *= scalar;
|
|
157
|
+
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
divide(v) {
|
|
162
|
+
this.x /= v.x;
|
|
163
|
+
this.y /= v.y;
|
|
164
|
+
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
divideScalar(scalar) {
|
|
169
|
+
return this.multiplyScalar(1 / scalar);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
applyMatrix3(m) {
|
|
173
|
+
const x = this.x,
|
|
174
|
+
y = this.y;
|
|
175
|
+
const e = m.elements;
|
|
176
|
+
|
|
177
|
+
this.x = e[0] * x + e[3] * y + e[6];
|
|
178
|
+
this.y = e[1] * x + e[4] * y + e[7];
|
|
179
|
+
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
min(v) {
|
|
184
|
+
this.x = Math.min(this.x, v.x);
|
|
185
|
+
this.y = Math.min(this.y, v.y);
|
|
186
|
+
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
max(v) {
|
|
191
|
+
this.x = Math.max(this.x, v.x);
|
|
192
|
+
this.y = Math.max(this.y, v.y);
|
|
193
|
+
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
clamp(min, max) {
|
|
198
|
+
// assumes min < max, componentwise
|
|
199
|
+
|
|
200
|
+
this.x = Math.max(min.x, Math.min(max.x, this.x));
|
|
201
|
+
this.y = Math.max(min.y, Math.min(max.y, this.y));
|
|
202
|
+
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
clampScalar(minVal, maxVal) {
|
|
207
|
+
this.x = Math.max(minVal, Math.min(maxVal, this.x));
|
|
208
|
+
this.y = Math.max(minVal, Math.min(maxVal, this.y));
|
|
209
|
+
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
clampLength(min, max) {
|
|
214
|
+
const length = this.length();
|
|
215
|
+
|
|
216
|
+
return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
floor() {
|
|
220
|
+
this.x = Math.floor(this.x);
|
|
221
|
+
this.y = Math.floor(this.y);
|
|
222
|
+
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
ceil() {
|
|
227
|
+
this.x = Math.ceil(this.x);
|
|
228
|
+
this.y = Math.ceil(this.y);
|
|
229
|
+
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
round() {
|
|
234
|
+
this.x = Math.round(this.x);
|
|
235
|
+
this.y = Math.round(this.y);
|
|
236
|
+
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
roundToZero() {
|
|
241
|
+
this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
|
|
242
|
+
this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
|
|
243
|
+
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
negate() {
|
|
248
|
+
this.x = -this.x;
|
|
249
|
+
this.y = -this.y;
|
|
250
|
+
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
dot(v) {
|
|
255
|
+
return this.x * v.x + this.y * v.y;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
cross(v) {
|
|
259
|
+
return this.x * v.y - this.y * v.x;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
lengthSq() {
|
|
263
|
+
return this.x * this.x + this.y * this.y;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
length() {
|
|
267
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
manhattanLength() {
|
|
271
|
+
return Math.abs(this.x) + Math.abs(this.y);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
normalize() {
|
|
275
|
+
return this.divideScalar(this.length() || 1);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
angle() {
|
|
279
|
+
// computes the angle in radians with respect to the positive x-axis
|
|
280
|
+
|
|
281
|
+
const angle = Math.atan2(-this.y, -this.x) + Math.PI;
|
|
282
|
+
|
|
283
|
+
return angle;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
distanceTo(v) {
|
|
287
|
+
return Math.sqrt(this.distanceToSquared(v));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
distanceToSquared(v) {
|
|
291
|
+
const dx = this.x - v.x,
|
|
292
|
+
dy = this.y - v.y;
|
|
293
|
+
return dx * dx + dy * dy;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
manhattanDistanceTo(v) {
|
|
297
|
+
return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
setLength(length) {
|
|
301
|
+
return this.normalize().multiplyScalar(length);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
lerp(v, alpha) {
|
|
305
|
+
this.x += (v.x - this.x) * alpha;
|
|
306
|
+
this.y += (v.y - this.y) * alpha;
|
|
307
|
+
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
lerpVectors(v1, v2, alpha) {
|
|
312
|
+
this.x = v1.x + (v2.x - v1.x) * alpha;
|
|
313
|
+
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
314
|
+
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
equals(v) {
|
|
319
|
+
return v.x === this.x && v.y === this.y;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
fromArray(array, offset = 0) {
|
|
323
|
+
this.x = array[offset];
|
|
324
|
+
this.y = array[offset + 1];
|
|
325
|
+
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
toArray(array = [], offset = 0) {
|
|
330
|
+
array[offset] = this.x;
|
|
331
|
+
array[offset + 1] = this.y;
|
|
332
|
+
|
|
333
|
+
return array;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
fromBufferAttribute(attribute, index, offset) {
|
|
337
|
+
if (offset !== undefined) {
|
|
338
|
+
console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
this.x = attribute.getX(index);
|
|
342
|
+
this.y = attribute.getY(index);
|
|
343
|
+
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
rotateAround(center, angle) {
|
|
348
|
+
const c = Math.cos(angle),
|
|
349
|
+
s = Math.sin(angle);
|
|
350
|
+
|
|
351
|
+
const x = this.x - center.x;
|
|
352
|
+
const y = this.y - center.y;
|
|
353
|
+
|
|
354
|
+
this.x = x * c - y * s + center.x;
|
|
355
|
+
this.y = x * s + y * c + center.y;
|
|
356
|
+
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
random() {
|
|
361
|
+
this.x = Math.random();
|
|
362
|
+
this.y = Math.random();
|
|
363
|
+
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
*[Symbol.iterator]() {
|
|
368
|
+
yield this.x;
|
|
369
|
+
yield this.y;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export { Vector2 };
|