-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
vec2.ts
768 lines (679 loc) · 21.4 KB
/
vec2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/*
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @category core/math
*/
import { CCClass } from '../data/class';
import { ValueType } from '../value-types/value-type';
import { Mat4 } from './mat4';
import { IMat3Like, IMat4Like, IVec2Like } from './type-define';
import { clamp } from './utils';
import { EPSILON, random } from './utils';
import { Vec3 } from './vec3';
import { legacyCC } from '../global-exports';
/**
* 二维向量。
*/
export class Vec2 extends ValueType {
public static ZERO = Object.freeze(new Vec2(0, 0));
public static ONE = Object.freeze(new Vec2(1, 1));
public static NEG_ONE = Object.freeze(new Vec2(-1, -1));
public static UNIT_X = Object.freeze(new Vec2(1, 0));
public static UNIT_Y = Object.freeze(new Vec2(0, 1));
/**
* @zh 获得指定向量的拷贝
*/
public static clone <Out extends IVec2Like> (a: Out) {
return new Vec2(a.x, a.y);
}
/**
* @zh 复制目标向量
*/
public static copy <Out extends IVec2Like> (out: Out, a: Out) {
out.x = a.x;
out.y = a.y;
return out;
}
/**
* @zh 设置向量值
*/
public static set <Out extends IVec2Like> (out: Out, x: number, y: number) {
out.x = x;
out.y = y;
return out;
}
/**
* @zh 逐元素向量加法
*/
public static add <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = a.x + b.x;
out.y = a.y + b.y;
return out;
}
/**
* @zh 逐元素向量减法
*/
public static subtract <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = a.x - b.x;
out.y = a.y - b.y;
return out;
}
/**
* @zh 逐元素向量乘法
*/
public static multiply <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = a.x * b.x;
out.y = a.y * b.y;
return out;
}
/**
* @zh 逐元素向量除法
*/
public static divide <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = a.x / b.x;
out.y = a.y / b.y;
return out;
}
/**
* @zh 逐元素向量向上取整
*/
public static ceil <Out extends IVec2Like> (out: Out, a: Out) {
out.x = Math.ceil(a.x);
out.y = Math.ceil(a.y);
return out;
}
/**
* @zh 逐元素向量向下取整
*/
public static floor <Out extends IVec2Like> (out: Out, a: Out) {
out.x = Math.floor(a.x);
out.y = Math.floor(a.y);
return out;
}
/**
* @zh 逐元素向量最小值
*/
public static min <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = Math.min(a.x, b.x);
out.y = Math.min(a.y, b.y);
return out;
}
/**
* @zh 逐元素向量最大值
*/
public static max <Out extends IVec2Like> (out: Out, a: Out, b: Out) {
out.x = Math.max(a.x, b.x);
out.y = Math.max(a.y, b.y);
return out;
}
/**
* @zh 逐元素向量四舍五入取整
*/
public static round <Out extends IVec2Like> (out: Out, a: Out) {
out.x = Math.round(a.x);
out.y = Math.round(a.y);
return out;
}
/**
* @zh 向量标量乘法
*/
public static multiplyScalar <Out extends IVec2Like> (out: Out, a: Out, b: number) {
out.x = a.x * b;
out.y = a.y * b;
return out;
}
/**
* @zh 逐元素向量乘加: A + B * scale
*/
public static scaleAndAdd <Out extends IVec2Like> (out: Out, a: Out, b: Out, scale: number) {
out.x = a.x + (b.x * scale);
out.y = a.y + (b.y * scale);
return out;
}
/**
* @zh 求两向量的欧氏距离
*/
public static distance <Out extends IVec2Like> (a: Out, b: Out) {
const x = b.x - a.x;
const y = b.y - a.y;
return Math.sqrt(x * x + y * y);
}
/**
* @zh 求两向量的欧氏距离平方
*/
public static squaredDistance <Out extends IVec2Like> (a: Out, b: Out) {
const x = b.x - a.x;
const y = b.y - a.y;
return x * x + y * y;
}
/**
* @zh 求向量长度
*/
public static len <Out extends IVec2Like> (a: Out) {
const x = a.x;
const y = a.y;
return Math.sqrt(x * x + y * y);
}
/**
* @zh 求向量长度平方
*/
public static lengthSqr <Out extends IVec2Like> (a: Out) {
const x = a.x;
const y = a.y;
return x * x + y * y;
}
/**
* @zh 逐元素向量取负
*/
public static negate <Out extends IVec2Like> (out: Out, a: Out) {
out.x = -a.x;
out.y = -a.y;
return out;
}
/**
* @zh 逐元素向量取倒数,接近 0 时返回 Infinity
*/
public static inverse <Out extends IVec2Like> (out: Out, a: Out) {
out.x = 1.0 / a.x;
out.y = 1.0 / a.y;
return out;
}
/**
* @zh 逐元素向量取倒数,接近 0 时返回 0
*/
public static inverseSafe <Out extends IVec2Like> (out: Out, a: Out) {
const x = a.x;
const y = a.y;
if (Math.abs(x) < EPSILON) {
out.x = 0;
} else {
out.x = 1.0 / x;
}
if (Math.abs(y) < EPSILON) {
out.y = 0;
} else {
out.y = 1.0 / y;
}
return out;
}
/**
* @zh 归一化向量
*/
public static normalize <Out extends IVec2Like, Vec2Like extends IVec2Like> (out: Out, a: Vec2Like) {
const x = a.x;
const y = a.y;
let len = x * x + y * y;
if (len > 0) {
len = 1 / Math.sqrt(len);
out.x = x * len;
out.y = y * len;
}
return out;
}
/**
* @zh 向量点积(数量积)
*/
public static dot <Out extends IVec2Like> (a: Out, b: Out) {
return a.x * b.x + a.y * b.y;
}
/**
* @zh 向量叉积(向量积),注意二维向量的叉积为与 Z 轴平行的三维向量
*/
public static cross <Out extends IVec2Like> (out: Vec3, a: Out, b: Out) {
out.x = out.y = 0;
out.z = a.x * b.y - a.y * b.x;
return out;
}
/**
* @zh 逐元素向量线性插值: A + t * (B - A)
*/
public static lerp <Out extends IVec2Like> (out: Out, a: Out, b: Out, t: number) {
const x = a.x;
const y = a.y;
out.x = x + t * (b.x - x);
out.y = y + t * (b.y - y);
return out;
}
/**
* @zh 生成一个在单位圆上均匀分布的随机向量
* @param scale 生成的向量长度
*/
public static random <Out extends IVec2Like> (out: Out, scale?: number) {
scale = scale || 1.0;
const r = random() * 2.0 * Math.PI;
out.x = Math.cos(r) * scale;
out.y = Math.sin(r) * scale;
return out;
}
/**
* @zh 向量与三维矩阵乘法,默认向量第三位为 1。
*/
public static transformMat3 <Out extends IVec2Like, MatLike extends IMat3Like> (out: Out, a: Out, m: IMat3Like) {
const x = a.x;
const y = a.y;
out.x = m.m00 * x + m.m03 * y + m.m06;
out.y = m.m01 * x + m.m04 * y + m.m07;
return out;
}
/**
* @zh 向量与四维矩阵乘法,默认向量第三位为 0,第四位为 1。
*/
public static transformMat4 <Out extends IVec2Like, MatLike extends IMat4Like> (out: Out, a: Out, m: IMat4Like) {
const x = a.x;
const y = a.y;
out.x = m.m00 * x + m.m04 * y + m.m12;
out.y = m.m01 * x + m.m05 * y + m.m13;
return out;
}
/**
* @zh 返回向量的字符串表示
*/
public static str <Out extends IVec2Like> (a: Out) {
return `Vec2(${a.x}, ${a.y})`;
}
/**
* @zh 向量转数组
* @param ofs 数组起始偏移量
*/
public static toArray <Out extends IWritableArrayLike<number>> (out: Out, v: IVec2Like, ofs = 0) {
out[ofs + 0] = v.x;
out[ofs + 1] = v.y;
return out;
}
/**
* @zh 数组转向量
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IVec2Like> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.x = arr[ofs + 0];
out.y = arr[ofs + 1];
return out;
}
/**
* @zh 向量等价判断
*/
public static strictEquals <Out extends IVec2Like> (a: Out, b: Out) {
return a.x === b.x && a.y === b.y;
}
/**
* @zh 排除浮点数误差的向量近似等价判断
*/
public static equals <Out extends IVec2Like> (a: Out, b: Out, epsilon = EPSILON) {
return (
Math.abs(a.x - b.x) <=
epsilon * Math.max(1.0, Math.abs(a.x), Math.abs(b.x)) &&
Math.abs(a.y - b.y) <=
epsilon * Math.max(1.0, Math.abs(a.y), Math.abs(b.y))
);
}
/**
* @zh 求两向量夹角弧度
*/
public static angle <Out extends IVec2Like> (a: Out, b: Out) {
Vec2.normalize(v2_1, a);
Vec2.normalize(v2_2, b);
const cosine = Vec2.dot(v2_1, v2_2);
if (cosine > 1.0) {
return 0;
}
if (cosine < -1.0) {
return Math.PI;
}
return Math.acos(cosine);
}
/**
* x 分量。
*/
public declare x: number;
/**
* y 分量。
*/
public declare y: number;
constructor (other: Vec2);
constructor (x?: number, y?: number);
constructor (x?: number | Vec2, y?: number) {
super();
if (x && typeof x === 'object') {
this.x = x.x;
this.y = x.y;
} else {
this.x = x || 0;
this.y = y || 0;
}
}
/**
* @zh 克隆当前向量。
*/
public clone () {
return new Vec2(this.x, this.y);
}
/**
* @zh 设置当前向量使其与指定向量相等。
* @param other 相比较的向量。
* @return `this`
*/
public set (other: Vec2);
/**
* @zh 设置当前向量的具体分量值。
* @param x 要设置的 x 分量的值
* @param y 要设置的 y 分量的值
* @return `this`
*/
public set (x?: number, y?: number);
public set (x?: number | Vec2, y?: number) {
if (x && typeof x === 'object') {
this.x = x.x;
this.y = x.y;
} else {
this.x = x || 0;
this.y = y || 0;
}
return this;
}
/**
* @zh 判断当前向量是否在误差范围内与指定向量相等。
* @param other 相比较的向量。
* @param epsilon 允许的误差,应为非负数。
* @return 当两向量的各分量都在指定的误差范围内分别相等时,返回 `true`;否则返回 `false`。
*/
public equals (other: Vec2, epsilon = EPSILON) {
return (
Math.abs(this.x - other.x) <=
epsilon * Math.max(1.0, Math.abs(this.x), Math.abs(other.x)) &&
Math.abs(this.y - other.y) <=
epsilon * Math.max(1.0, Math.abs(this.y), Math.abs(other.y))
);
}
/**
* @zh 判断当前向量是否在误差范围内与指定分量的向量相等。
* @param x 相比较的向量的 x 分量。
* @param y 相比较的向量的 y 分量。
* @param epsilon 允许的误差,应为非负数。
* @return 当两向量的各分量都在指定的误差范围内分别相等时,返回 `true`;否则返回 `false`。
*/
public equals2f (x: number, y: number, epsilon = EPSILON) {
return (
Math.abs(this.x - x) <=
epsilon * Math.max(1.0, Math.abs(this.x), Math.abs(x)) &&
Math.abs(this.y - y) <=
epsilon * Math.max(1.0, Math.abs(this.y), Math.abs(y))
);
}
/**
* @zh 判断当前向量是否与指定向量相等。
* @param other 相比较的向量。
* @return 两向量的各分量都分别相等时返回 `true`;否则返回 `false`。
*/
public strictEquals (other: Vec2) {
return other && this.x === other.x && this.y === other.y;
}
/**
* @zh 判断当前向量是否与指定分量的向量相等。
* @param x 指定向量的 x 分量。
* @param y 指定向量的 y 分量。
* @return 两向量的各分量都分别相等时返回 `true`;否则返回 `false`。
*/
public strictEquals2f (x: number, y: number) {
return this.x === x && this.y === y;
}
/**
* @zh 返回当前向量的字符串表示。
* @returns 当前向量的字符串表示。
*/
public toString () {
return `(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`;
}
/**
* @zh 根据指定的插值比率,从当前向量到目标向量之间做插值。
* @param to 目标向量。
* @param ratio 插值比率,范围为 [0,1]。
*/
public lerp (to: Vec2, ratio: number) {
const x = this.x;
const y = this.y;
this.x = x + ratio * (to.x - x);
this.y = y + ratio * (to.y - y);
return this;
}
/**
* @zh 设置当前向量的值,使其各个分量都处于指定的范围内。
* @param minInclusive 每个分量都代表了对应分量允许的最小值。
* @param maxInclusive 每个分量都代表了对应分量允许的最大值。
* @return `this`
*/
public clampf (minInclusive: Vec2, maxInclusive: Vec2) {
this.x = clamp(this.x, minInclusive.x, maxInclusive.x);
this.y = clamp(this.y, minInclusive.y, maxInclusive.y);
return this;
}
/**
* @zh 向量加法。将当前向量与指定向量的相加
* @param other 指定的向量。
*/
public add (other: Vec2) {
this.x = this.x + other.x;
this.y = this.y + other.y;
return this;
}
/**
* @zh 向量加法。将当前向量与指定分量的向量相加
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public add2f (x: number, y: number) {
this.x = this.x + x;
this.y = this.y + y;
return this;
}
/**
* @zh 向量减法。将当前向量减去指定向量
* @param other 减数向量。
*/
public subtract (other: Vec2) {
this.x = this.x - other.x;
this.y = this.y - other.y;
return this;
}
/**
* @zh 向量减法。将当前向量减去指定分量的向量
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public subtract2f (x: number, y: number) {
this.x = this.x - x;
this.y = this.y - y;
return this;
}
/**
* @zh 向量数乘。将当前向量数乘指定标量
* @param scalar 标量乘数。
*/
public multiplyScalar (scalar: number) {
if (typeof scalar === 'object') { console.warn('should use Vec2.multiply for vector * vector operation'); }
this.x = this.x * scalar;
this.y = this.y * scalar;
return this;
}
/**
* @zh 向量乘法。将当前向量乘以与指定向量的结果赋值给当前向量。
* @param other 指定的向量。
*/
public multiply (other: Vec2) {
if (typeof other !== 'object') { console.warn('should use Vec2.scale for vector * scalar operation'); }
this.x = this.x * other.x;
this.y = this.y * other.y;
return this;
}
/**
* @zh 向量乘法。将当前向量与指定分量的向量相乘的结果赋值给当前向量。
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public multiply2f (x: number, y: number) {
this.x = this.x * x;
this.y = this.y * y;
return this;
}
/**
* @zh 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
* @param other 指定的向量
*/
public divide (other: Vec2) {
this.x = this.x / other.x;
this.y = this.y / other.y;
return this;
}
/**
* @zh 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
* @param x 指定的向量的 x 分量。
* @param y 指定的向量的 y 分量。
*/
public divide2f (x: number, y: number) {
this.x = this.x / x;
this.y = this.y / y;
return this;
}
/**
* @zh 将当前向量的各个分量取反
*/
public negative () {
this.x = -this.x;
this.y = -this.y;
return this;
}
/**
* @zh 向量点乘。
* @param other 指定的向量。
* @return 当前向量与指定向量点乘的结果。
*/
public dot (other: Vec2) {
return this.x * other.x + this.y * other.y;
}
/**
* @zh 向量叉乘。
* @param other 指定的向量。
* @return `out`
*/
public cross (other: Vec2) {
return this.x * other.y - this.y * other.x;
}
/**
* 计算向量的长度(模)。
* @return 向量的长度(模)。
*/
public length () {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
/**
* 计算向量长度(模)的平方。
* @return 向量长度(模)的平方。
*/
public lengthSqr () {
return this.x * this.x + this.y * this.y;
}
/**
* @zh 将当前向量归一化。
*/
public normalize () {
const x = this.x;
const y = this.y;
let len = x * x + y * y;
if (len > 0) {
len = 1 / Math.sqrt(len);
this.x = this.x * len;
this.y = this.y * len;
}
return this;
}
/**
* @zh 获取当前向量和指定向量之间的角度。
* @param other 指定的向量。
* @return 当前向量和指定向量之间的角度(弧度制);若当前向量和指定向量中存在零向量,将返回 0。
*/
public angle (other: Vec2) {
const magSqr1 = this.lengthSqr();
const magSqr2 = other.lengthSqr();
if (magSqr1 === 0 || magSqr2 === 0) {
console.warn('Can\'t get angle between zero vector');
return 0.0;
}
const dot = this.dot(other);
let theta = dot / (Math.sqrt(magSqr1 * magSqr2));
theta = clamp(theta, -1.0, 1.0);
return Math.acos(theta);
}
/**
* @zh 获取当前向量和指定向量之间的有符号角度。<br/>
* 有符号角度的取值范围为 (-180, 180],当前向量可以通过逆时针旋转有符号角度与指定向量同向。<br/>
* @param other 指定的向量。
* @return 当前向量和指定向量之间的有符号角度(弧度制);若当前向量和指定向量中存在零向量,将返回 0。
*/
public signAngle (other: Vec2) {
const angle = this.angle(other);
return this.cross(other) < 0 ? -angle : angle;
}
/**
* @zh 将当前向量的旋转
* @param radians 旋转角度(弧度制)。
*/
public rotate (radians: number) {
const x = this.x;
const y = this.y;
const sin = Math.sin(radians);
const cos = Math.cos(radians);
this.x = cos * x - sin * y;
this.y = sin * x + cos * y;
return this;
}
/**
* @zh 计算当前向量在指定向量上的投影向量。
* @param other 指定的向量。
*/
public project (other: Vec2) {
const scalar = this.dot(other) / other.dot(other);
this.x = other.x * scalar;
this.y = other.y * scalar;
return this;
}
/**
* @zh 将当前向量视为 z 分量为 0、w 分量为 1 的四维向量,<br/>
* 应用四维矩阵变换到当前矩阵<br/>
* @param matrix 变换矩阵。
*/
public transformMat4 (matrix: Mat4) {
const x = this.x;
const y = this.y;
this.x = matrix.m00 * x + matrix.m04 * y + matrix.m12;
this.y = matrix.m01 * x + matrix.m05 * y + matrix.m13;
return this;
}
}
const v2_1 = new Vec2();
const v2_2 = new Vec2();
CCClass.fastDefine('cc.Vec2', Vec2, { x: 0, y: 0 });
legacyCC.Vec2 = Vec2;
export function v2 (other: Vec2): Vec2;
export function v2 (x?: number, y?: number): Vec2;
export function v2 (x?: number | Vec2, y?: number) {
return new Vec2(x as any, y);
}
legacyCC.v2 = v2;