@esengine/ecs-framework-math 1.0.3 → 2.8.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/bin/Animation/Easing.d.ts +150 -150
  3. package/bin/Animation/Easing.d.ts.map +1 -1
  4. package/bin/Animation/Easing.js +151 -151
  5. package/bin/Animation/Easing.js.map +1 -1
  6. package/bin/Animation/Interpolation.d.ts +102 -102
  7. package/bin/Animation/Interpolation.d.ts.map +1 -1
  8. package/bin/Animation/Interpolation.js +104 -104
  9. package/bin/Animation/Interpolation.js.map +1 -1
  10. package/bin/Animation/index.d.ts.map +1 -1
  11. package/bin/Animation/index.js.map +1 -1
  12. package/bin/Circle.d.ts +159 -159
  13. package/bin/Circle.d.ts.map +1 -1
  14. package/bin/Circle.js +159 -159
  15. package/bin/Circle.js.map +1 -1
  16. package/bin/Collision/CollisionDetector.d.ts +64 -64
  17. package/bin/Collision/CollisionDetector.d.ts.map +1 -1
  18. package/bin/Collision/CollisionDetector.js +66 -66
  19. package/bin/Collision/CollisionDetector.js.map +1 -1
  20. package/bin/Color.d.ts +277 -0
  21. package/bin/Color.d.ts.map +1 -0
  22. package/bin/Color.js +470 -0
  23. package/bin/Color.js.map +1 -0
  24. package/bin/Fixed32.d.ts +266 -0
  25. package/bin/Fixed32.d.ts.map +1 -0
  26. package/bin/Fixed32.js +381 -0
  27. package/bin/Fixed32.js.map +1 -0
  28. package/bin/FixedMath.d.ts +109 -0
  29. package/bin/FixedMath.d.ts.map +1 -0
  30. package/bin/FixedMath.js +264 -0
  31. package/bin/FixedMath.js.map +1 -0
  32. package/bin/FixedVector2.d.ts +293 -0
  33. package/bin/FixedVector2.d.ts.map +1 -0
  34. package/bin/FixedVector2.js +413 -0
  35. package/bin/FixedVector2.js.map +1 -0
  36. package/bin/MathUtils.d.ts +205 -205
  37. package/bin/MathUtils.d.ts.map +1 -1
  38. package/bin/MathUtils.js +206 -206
  39. package/bin/MathUtils.js.map +1 -1
  40. package/bin/Matrix3.d.ts +158 -139
  41. package/bin/Matrix3.d.ts.map +1 -1
  42. package/bin/Matrix3.js +179 -151
  43. package/bin/Matrix3.js.map +1 -1
  44. package/bin/Rectangle.d.ts +144 -144
  45. package/bin/Rectangle.d.ts.map +1 -1
  46. package/bin/Rectangle.js +144 -144
  47. package/bin/Rectangle.js.map +1 -1
  48. package/bin/Vector2.d.ts +202 -186
  49. package/bin/Vector2.d.ts.map +1 -1
  50. package/bin/Vector2.js +198 -188
  51. package/bin/Vector2.js.map +1 -1
  52. package/bin/Vector3.d.ts +257 -0
  53. package/bin/Vector3.d.ts.map +1 -0
  54. package/bin/Vector3.js +372 -0
  55. package/bin/Vector3.js.map +1 -0
  56. package/bin/index.d.ts +8 -1
  57. package/bin/index.d.ts.map +1 -1
  58. package/bin/index.js +9 -0
  59. package/bin/index.js.map +1 -1
  60. package/package.json +66 -67
package/bin/Vector2.js CHANGED
@@ -9,110 +9,110 @@
9
9
  */
10
10
  export class Vector2 {
11
11
  /**
12
- * 创建2D向量
13
- * @param x X分量,默认为0
14
- * @param y Y分量,默认为0
15
- */
12
+ * 创建2D向量
13
+ * @param x X分量,默认为0
14
+ * @param y Y分量,默认为0
15
+ */
16
16
  constructor(x = 0, y = 0) {
17
17
  this.x = x;
18
18
  this.y = y;
19
19
  }
20
20
  // 基础属性
21
21
  /**
22
- * 获取向量长度(模)
23
- */
22
+ * 获取向量长度(模)
23
+ */
24
24
  get length() {
25
25
  return Math.sqrt(this.x * this.x + this.y * this.y);
26
26
  }
27
27
  /**
28
- * 获取向量长度的平方
29
- */
28
+ * 获取向量长度的平方
29
+ */
30
30
  get lengthSquared() {
31
31
  return this.x * this.x + this.y * this.y;
32
32
  }
33
33
  /**
34
- * 获取向量角度(弧度)
35
- */
34
+ * 获取向量角度(弧度)
35
+ */
36
36
  get angle() {
37
37
  return Math.atan2(this.y, this.x);
38
38
  }
39
39
  /**
40
- * 检查是否为零向量
41
- */
40
+ * 检查是否为零向量
41
+ */
42
42
  get isZero() {
43
43
  return this.x === 0 && this.y === 0;
44
44
  }
45
45
  /**
46
- * 检查是否为单位向量
47
- */
46
+ * 检查是否为单位向量
47
+ */
48
48
  get isUnit() {
49
49
  const lenSq = this.lengthSquared;
50
50
  return Math.abs(lenSq - 1) < Number.EPSILON;
51
51
  }
52
52
  // 基础运算
53
53
  /**
54
- * 设置向量分量
55
- * @param x X分量
56
- * @param y Y分量
57
- * @returns 当前向量实例(链式调用)
58
- */
54
+ * 设置向量分量
55
+ * @param x X分量
56
+ * @param y Y分量
57
+ * @returns 当前向量实例(链式调用)
58
+ */
59
59
  set(x, y) {
60
60
  this.x = x;
61
61
  this.y = y;
62
62
  return this;
63
63
  }
64
64
  /**
65
- * 复制另一个向量的值
66
- * @param other 源向量
67
- * @returns 当前向量实例(链式调用)
68
- */
65
+ * 复制另一个向量的值
66
+ * @param other 源向量
67
+ * @returns 当前向量实例(链式调用)
68
+ */
69
69
  copy(other) {
70
70
  this.x = other.x;
71
71
  this.y = other.y;
72
72
  return this;
73
73
  }
74
74
  /**
75
- * 克隆当前向量
76
- * @returns 新的向量实例
77
- */
75
+ * 克隆当前向量
76
+ * @returns 新的向量实例
77
+ */
78
78
  clone() {
79
79
  return new Vector2(this.x, this.y);
80
80
  }
81
81
  /**
82
- * 向量加法
83
- * @param other 另一个向量
84
- * @returns 当前向量实例(链式调用)
85
- */
82
+ * 向量加法
83
+ * @param other 另一个向量
84
+ * @returns 当前向量实例(链式调用)
85
+ */
86
86
  add(other) {
87
87
  this.x += other.x;
88
88
  this.y += other.y;
89
89
  return this;
90
90
  }
91
91
  /**
92
- * 向量减法
93
- * @param other 另一个向量
94
- * @returns 当前向量实例(链式调用)
95
- */
92
+ * 向量减法
93
+ * @param other 另一个向量
94
+ * @returns 当前向量实例(链式调用)
95
+ */
96
96
  subtract(other) {
97
97
  this.x -= other.x;
98
98
  this.y -= other.y;
99
99
  return this;
100
100
  }
101
101
  /**
102
- * 向量数乘
103
- * @param scalar 标量
104
- * @returns 当前向量实例(链式调用)
105
- */
102
+ * 向量数乘
103
+ * @param scalar 标量
104
+ * @returns 当前向量实例(链式调用)
105
+ */
106
106
  multiply(scalar) {
107
107
  this.x *= scalar;
108
108
  this.y *= scalar;
109
109
  return this;
110
110
  }
111
111
  /**
112
- * 向量数除
113
- * @param scalar 标量
114
- * @returns 当前向量实例(链式调用)
115
- */
112
+ * 向量数除
113
+ * @param scalar 标量
114
+ * @returns 当前向量实例(链式调用)
115
+ */
116
116
  divide(scalar) {
117
117
  if (scalar === 0) {
118
118
  throw new Error('不能除以零');
@@ -122,9 +122,9 @@ export class Vector2 {
122
122
  return this;
123
123
  }
124
124
  /**
125
- * 向量取反
126
- * @returns 当前向量实例(链式调用)
127
- */
125
+ * 向量取反
126
+ * @returns 当前向量实例(链式调用)
127
+ */
128
128
  negate() {
129
129
  this.x = -this.x;
130
130
  this.y = -this.y;
@@ -132,25 +132,25 @@ export class Vector2 {
132
132
  }
133
133
  // 向量运算
134
134
  /**
135
- * 计算与另一个向量的点积
136
- * @param other 另一个向量
137
- * @returns 点积值
138
- */
135
+ * 计算与另一个向量的点积
136
+ * @param other 另一个向量
137
+ * @returns 点积值
138
+ */
139
139
  dot(other) {
140
140
  return this.x * other.x + this.y * other.y;
141
141
  }
142
142
  /**
143
- * 计算与另一个向量的叉积(2D中返回标量)
144
- * @param other 另一个向量
145
- * @returns 叉积值
146
- */
143
+ * 计算与另一个向量的叉积(2D中返回标量)
144
+ * @param other 另一个向量
145
+ * @returns 叉积值
146
+ */
147
147
  cross(other) {
148
148
  return this.x * other.y - this.y * other.x;
149
149
  }
150
150
  /**
151
- * 向量归一化(转换为单位向量)
152
- * @returns 当前向量实例(链式调用)
153
- */
151
+ * 向量归一化(转换为单位向量)
152
+ * @returns 当前向量实例(链式调用)
153
+ */
154
154
  normalize() {
155
155
  const len = this.length;
156
156
  if (len === 0) {
@@ -159,38 +159,38 @@ export class Vector2 {
159
159
  return this.divide(len);
160
160
  }
161
161
  /**
162
- * 获取归一化后的向量(不修改原向量)
163
- * @returns 新的单位向量
164
- */
162
+ * 获取归一化后的向量(不修改原向量)
163
+ * @returns 新的单位向量
164
+ */
165
165
  normalized() {
166
166
  return this.clone().normalize();
167
167
  }
168
168
  // 几何运算
169
169
  /**
170
- * 计算到另一个向量的距离
171
- * @param other 另一个向量
172
- * @returns 距离值
173
- */
170
+ * 计算到另一个向量的距离
171
+ * @param other 另一个向量
172
+ * @returns 距离值
173
+ */
174
174
  distanceTo(other) {
175
175
  const dx = this.x - other.x;
176
176
  const dy = this.y - other.y;
177
177
  return Math.sqrt(dx * dx + dy * dy);
178
178
  }
179
179
  /**
180
- * 计算到另一个向量的距离平方
181
- * @param other 另一个向量
182
- * @returns 距离平方值
183
- */
180
+ * 计算到另一个向量的距离平方
181
+ * @param other 另一个向量
182
+ * @returns 距离平方值
183
+ */
184
184
  distanceToSquared(other) {
185
185
  const dx = this.x - other.x;
186
186
  const dy = this.y - other.y;
187
187
  return dx * dx + dy * dy;
188
188
  }
189
189
  /**
190
- * 计算与另一个向量的夹角(弧度)
191
- * @param other 另一个向量
192
- * @returns 夹角(0到π)
193
- */
190
+ * 计算与另一个向量的夹角(弧度)
191
+ * @param other 另一个向量
192
+ * @returns 夹角(0到π)
193
+ */
194
194
  angleTo(other) {
195
195
  const dot = this.dot(other);
196
196
  const lenProduct = this.length * other.length;
@@ -199,10 +199,10 @@ export class Vector2 {
199
199
  return Math.acos(Math.max(-1, Math.min(1, dot / lenProduct)));
200
200
  }
201
201
  /**
202
- * 计算向量在另一个向量上的投影
203
- * @param onto 投影目标向量
204
- * @returns 新的投影向量
205
- */
202
+ * 计算向量在另一个向量上的投影
203
+ * @param onto 投影目标向量
204
+ * @returns 新的投影向量
205
+ */
206
206
  projectOnto(onto) {
207
207
  const dot = this.dot(onto);
208
208
  const lenSq = onto.lengthSquared;
@@ -211,10 +211,10 @@ export class Vector2 {
211
211
  return onto.clone().multiply(dot / lenSq);
212
212
  }
213
213
  /**
214
- * 计算向量在另一个向量上的投影长度
215
- * @param onto 投影目标向量
216
- * @returns 投影长度(带符号)
217
- */
214
+ * 计算向量在另一个向量上的投影长度
215
+ * @param onto 投影目标向量
216
+ * @returns 投影长度(带符号)
217
+ */
218
218
  projectOntoLength(onto) {
219
219
  const len = onto.length;
220
220
  if (len === 0)
@@ -222,49 +222,59 @@ export class Vector2 {
222
222
  return this.dot(onto) / len;
223
223
  }
224
224
  /**
225
- * 获取垂直向量(逆时针旋转90度)
225
+ * 获取垂直向量(顺时针旋转90度)
226
+ * Get perpendicular vector (clockwise 90 degrees)
226
227
  * @returns 新的垂直向量
227
228
  */
228
229
  perpendicular() {
229
- return new Vector2(-this.y, this.x);
230
+ // Clockwise 90° rotation: (x, y) -> (y, -x)
231
+ // 顺时针旋转 90°
232
+ return new Vector2(this.y, -this.x);
230
233
  }
231
234
  // 变换操作
232
235
  /**
233
- * 向量旋转
236
+ * 向量旋转(顺时针为正)
237
+ * Rotate vector (clockwise positive)
238
+ *
239
+ * 使用左手坐标系约定:正角度 = 顺时针旋转
240
+ * Uses left-hand coordinate system: positive angle = clockwise
241
+ *
234
242
  * @param angle 旋转角度(弧度)
235
243
  * @returns 当前向量实例(链式调用)
236
244
  */
237
245
  rotate(angle) {
238
246
  const cos = Math.cos(angle);
239
247
  const sin = Math.sin(angle);
240
- const x = this.x * cos - this.y * sin;
241
- const y = this.x * sin + this.y * cos;
248
+ // Clockwise rotation: x' = x*cos + y*sin, y' = -x*sin + y*cos
249
+ // 顺时针旋转公式
250
+ const x = this.x * cos + this.y * sin;
251
+ const y = -this.x * sin + this.y * cos;
242
252
  this.x = x;
243
253
  this.y = y;
244
254
  return this;
245
255
  }
246
256
  /**
247
- * 获取旋转后的向量(不修改原向量)
248
- * @param angle 旋转角度(弧度)
249
- * @returns 新的旋转后向量
250
- */
257
+ * 获取旋转后的向量(不修改原向量)
258
+ * @param angle 旋转角度(弧度)
259
+ * @returns 新的旋转后向量
260
+ */
251
261
  rotated(angle) {
252
262
  return this.clone().rotate(angle);
253
263
  }
254
264
  /**
255
- * 围绕一个点旋转
256
- * @param center 旋转中心点
257
- * @param angle 旋转角度(弧度)
258
- * @returns 当前向量实例(链式调用)
259
- */
265
+ * 围绕一个点旋转
266
+ * @param center 旋转中心点
267
+ * @param angle 旋转角度(弧度)
268
+ * @returns 当前向量实例(链式调用)
269
+ */
260
270
  rotateAround(center, angle) {
261
271
  return this.subtract(center).rotate(angle).add(center);
262
272
  }
263
273
  /**
264
- * 反射向量(关于法线)
265
- * @param normal 法线向量(应为单位向量)
266
- * @returns 当前向量实例(链式调用)
267
- */
274
+ * 反射向量(关于法线)
275
+ * @param normal 法线向量(应为单位向量)
276
+ * @returns 当前向量实例(链式调用)
277
+ */
268
278
  reflect(normal) {
269
279
  const dot = this.dot(normal);
270
280
  this.x -= 2 * dot * normal.x;
@@ -272,30 +282,30 @@ export class Vector2 {
272
282
  return this;
273
283
  }
274
284
  /**
275
- * 获取反射后的向量(不修改原向量)
276
- * @param normal 法线向量(应为单位向量)
277
- * @returns 新的反射向量
278
- */
285
+ * 获取反射后的向量(不修改原向量)
286
+ * @param normal 法线向量(应为单位向量)
287
+ * @returns 新的反射向量
288
+ */
279
289
  reflected(normal) {
280
290
  return this.clone().reflect(normal);
281
291
  }
282
292
  // 插值和限制
283
293
  /**
284
- * 线性插值
285
- * @param target 目标向量
286
- * @param t 插值参数(0到1)
287
- * @returns 当前向量实例(链式调用)
288
- */
294
+ * 线性插值
295
+ * @param target 目标向量
296
+ * @param t 插值参数(0到1)
297
+ * @returns 当前向量实例(链式调用)
298
+ */
289
299
  lerp(target, t) {
290
300
  this.x += (target.x - this.x) * t;
291
301
  this.y += (target.y - this.y) * t;
292
302
  return this;
293
303
  }
294
304
  /**
295
- * 限制向量长度
296
- * @param maxLength 最大长度
297
- * @returns 当前向量实例(链式调用)
298
- */
305
+ * 限制向量长度
306
+ * @param maxLength 最大长度
307
+ * @returns 当前向量实例(链式调用)
308
+ */
299
309
  clampLength(maxLength) {
300
310
  const lenSq = this.lengthSquared;
301
311
  if (lenSq > maxLength * maxLength) {
@@ -304,11 +314,11 @@ export class Vector2 {
304
314
  return this;
305
315
  }
306
316
  /**
307
- * 限制向量分量
308
- * @param min 最小值向量
309
- * @param max 最大值向量
310
- * @returns 当前向量实例(链式调用)
311
- */
317
+ * 限制向量分量
318
+ * @param min 最小值向量
319
+ * @param max 最大值向量
320
+ * @returns 当前向量实例(链式调用)
321
+ */
312
322
  clamp(min, max) {
313
323
  this.x = Math.max(min.x, Math.min(max.x, this.x));
314
324
  this.y = Math.max(min.y, Math.min(max.y, this.y));
@@ -316,144 +326,144 @@ export class Vector2 {
316
326
  }
317
327
  // 比较操作
318
328
  /**
319
- * 检查两个向量是否相等
320
- * @param other 另一个向量
321
- * @param epsilon 容差,默认为Number.EPSILON
322
- * @returns 是否相等
323
- */
329
+ * 检查两个向量是否相等
330
+ * @param other 另一个向量
331
+ * @param epsilon 容差,默认为Number.EPSILON
332
+ * @returns 是否相等
333
+ */
324
334
  equals(other, epsilon = Number.EPSILON) {
325
335
  return Math.abs(this.x - other.x) < epsilon &&
326
336
  Math.abs(this.y - other.y) < epsilon;
327
337
  }
328
338
  /**
329
- * 检查两个向量是否完全相等
330
- * @param other 另一个向量
331
- * @returns 是否完全相等
332
- */
339
+ * 检查两个向量是否完全相等
340
+ * @param other 另一个向量
341
+ * @returns 是否完全相等
342
+ */
333
343
  exactEquals(other) {
334
344
  return this.x === other.x && this.y === other.y;
335
345
  }
336
346
  // 静态方法
337
347
  /**
338
- * 向量加法(静态方法)
339
- * @param a 向量a
340
- * @param b 向量b
341
- * @returns 新的结果向量
342
- */
348
+ * 向量加法(静态方法)
349
+ * @param a 向量a
350
+ * @param b 向量b
351
+ * @returns 新的结果向量
352
+ */
343
353
  static add(a, b) {
344
354
  return new Vector2(a.x + b.x, a.y + b.y);
345
355
  }
346
356
  /**
347
- * 向量减法(静态方法)
348
- * @param a 向量a
349
- * @param b 向量b
350
- * @returns 新的结果向量
351
- */
357
+ * 向量减法(静态方法)
358
+ * @param a 向量a
359
+ * @param b 向量b
360
+ * @returns 新的结果向量
361
+ */
352
362
  static subtract(a, b) {
353
363
  return new Vector2(a.x - b.x, a.y - b.y);
354
364
  }
355
365
  /**
356
- * 向量数乘(静态方法)
357
- * @param vector 向量
358
- * @param scalar 标量
359
- * @returns 新的结果向量
360
- */
366
+ * 向量数乘(静态方法)
367
+ * @param vector 向量
368
+ * @param scalar 标量
369
+ * @returns 新的结果向量
370
+ */
361
371
  static multiply(vector, scalar) {
362
372
  return new Vector2(vector.x * scalar, vector.y * scalar);
363
373
  }
364
374
  /**
365
- * 向量点积(静态方法)
366
- * @param a 向量a
367
- * @param b 向量b
368
- * @returns 点积值
369
- */
375
+ * 向量点积(静态方法)
376
+ * @param a 向量a
377
+ * @param b 向量b
378
+ * @returns 点积值
379
+ */
370
380
  static dot(a, b) {
371
381
  return a.x * b.x + a.y * b.y;
372
382
  }
373
383
  /**
374
- * 向量叉积(静态方法)
375
- * @param a 向量a
376
- * @param b 向量b
377
- * @returns 叉积值
378
- */
384
+ * 向量叉积(静态方法)
385
+ * @param a 向量a
386
+ * @param b 向量b
387
+ * @returns 叉积值
388
+ */
379
389
  static cross(a, b) {
380
390
  return a.x * b.y - a.y * b.x;
381
391
  }
382
392
  /**
383
- * 计算两点间距离(静态方法)
384
- * @param a 点a
385
- * @param b 点b
386
- * @returns 距离值
387
- */
393
+ * 计算两点间距离(静态方法)
394
+ * @param a 点a
395
+ * @param b 点b
396
+ * @returns 距离值
397
+ */
388
398
  static distance(a, b) {
389
399
  const dx = a.x - b.x;
390
400
  const dy = a.y - b.y;
391
401
  return Math.sqrt(dx * dx + dy * dy);
392
402
  }
393
403
  /**
394
- * 线性插值(静态方法)
395
- * @param a 起始向量
396
- * @param b 目标向量
397
- * @param t 插值参数(0到1)
398
- * @returns 新的插值结果向量
399
- */
404
+ * 线性插值(静态方法)
405
+ * @param a 起始向量
406
+ * @param b 目标向量
407
+ * @param t 插值参数(0到1)
408
+ * @returns 新的插值结果向量
409
+ */
400
410
  static lerp(a, b, t) {
401
411
  return new Vector2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
402
412
  }
403
413
  /**
404
- * 从角度创建单位向量(静态方法)
405
- * @param angle 角度(弧度)
406
- * @returns 新的单位向量
407
- */
414
+ * 从角度创建单位向量(静态方法)
415
+ * @param angle 角度(弧度)
416
+ * @returns 新的单位向量
417
+ */
408
418
  static fromAngle(angle) {
409
419
  return new Vector2(Math.cos(angle), Math.sin(angle));
410
420
  }
411
421
  /**
412
- * 从极坐标创建向量(静态方法)
413
- * @param length 长度
414
- * @param angle 角度(弧度)
415
- * @returns 新的向量
416
- */
422
+ * 从极坐标创建向量(静态方法)
423
+ * @param length 长度
424
+ * @param angle 角度(弧度)
425
+ * @returns 新的向量
426
+ */
417
427
  static fromPolar(length, angle) {
418
428
  return new Vector2(length * Math.cos(angle), length * Math.sin(angle));
419
429
  }
420
430
  /**
421
- * 获取两个向量中的最小分量向量(静态方法)
422
- * @param a 向量a
423
- * @param b 向量b
424
- * @returns 新的最小分量向量
425
- */
431
+ * 获取两个向量中的最小分量向量(静态方法)
432
+ * @param a 向量a
433
+ * @param b 向量b
434
+ * @returns 新的最小分量向量
435
+ */
426
436
  static min(a, b) {
427
437
  return new Vector2(Math.min(a.x, b.x), Math.min(a.y, b.y));
428
438
  }
429
439
  /**
430
- * 获取两个向量中的最大分量向量(静态方法)
431
- * @param a 向量a
432
- * @param b 向量b
433
- * @returns 新的最大分量向量
434
- */
440
+ * 获取两个向量中的最大分量向量(静态方法)
441
+ * @param a 向量a
442
+ * @param b 向量b
443
+ * @returns 新的最大分量向量
444
+ */
435
445
  static max(a, b) {
436
446
  return new Vector2(Math.max(a.x, b.x), Math.max(a.y, b.y));
437
447
  }
438
448
  // 字符串转换
439
449
  /**
440
- * 转换为字符串
441
- * @returns 字符串表示
442
- */
450
+ * 转换为字符串
451
+ * @returns 字符串表示
452
+ */
443
453
  toString() {
444
454
  return `Vector2(${this.x.toFixed(3)}, ${this.y.toFixed(3)})`;
445
455
  }
446
456
  /**
447
- * 转换为数组
448
- * @returns [x, y] 数组
449
- */
457
+ * 转换为数组
458
+ * @returns [x, y] 数组
459
+ */
450
460
  toArray() {
451
461
  return [this.x, this.y];
452
462
  }
453
463
  /**
454
- * 转换为普通对象
455
- * @returns {x, y} 对象
456
- */
464
+ * 转换为普通对象
465
+ * @returns {x, y} 对象
466
+ */
457
467
  toObject() {
458
468
  return { x: this.x, y: this.y };
459
469
  }