@vpmedia/phaser 1.75.0 → 1.77.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 (93) hide show
  1. package/README.md +1 -1
  2. package/coverage/clover.xml +1089 -3
  3. package/coverage/coverage-final.json +19 -1
  4. package/coverage/lcov-report/core/const.js.html +901 -0
  5. package/coverage/lcov-report/core/index.html +116 -0
  6. package/coverage/lcov-report/geom/circle.js.html +1003 -0
  7. package/coverage/lcov-report/geom/ellipse.js.html +388 -0
  8. package/coverage/lcov-report/geom/index.html +221 -0
  9. package/coverage/lcov-report/geom/line.js.html +1102 -0
  10. package/coverage/lcov-report/geom/matrix.js.html +751 -0
  11. package/coverage/lcov-report/geom/point.js.html +1027 -0
  12. package/coverage/lcov-report/geom/polygon.js.html +604 -0
  13. package/coverage/lcov-report/geom/rectangle.js.html +1774 -0
  14. package/coverage/lcov-report/geom/rounded_rectangle.js.html +226 -0
  15. package/coverage/lcov-report/geom/util/circle.js.html +436 -0
  16. package/coverage/lcov-report/geom/util/ellipse.js.html +139 -0
  17. package/coverage/lcov-report/geom/util/index.html +221 -0
  18. package/coverage/lcov-report/geom/util/line.js.html +475 -0
  19. package/coverage/lcov-report/geom/util/matrix.js.html +223 -0
  20. package/coverage/lcov-report/geom/util/point.js.html +961 -0
  21. package/coverage/lcov-report/geom/util/polygon.js.html +124 -0
  22. package/coverage/lcov-report/geom/util/rectangle.js.html +784 -0
  23. package/coverage/lcov-report/geom/util/rounded_rectangle.js.html +136 -0
  24. package/coverage/lcov-report/index.html +70 -10
  25. package/coverage/lcov-report/util/index.html +116 -0
  26. package/coverage/lcov-report/util/math.js.html +958 -0
  27. package/coverage/lcov.info +2179 -0
  28. package/lefthook.yml +0 -4
  29. package/package.json +13 -15
  30. package/src/phaser/core/device_util.js +1 -0
  31. package/src/phaser/core/dom.js +1 -0
  32. package/src/phaser/core/game.js +4 -1
  33. package/src/phaser/core/input_handler.js +2 -2
  34. package/src/phaser/core/scene.js +3 -1
  35. package/src/phaser/core/signal.js +1 -1
  36. package/src/phaser/core/timer.js +1 -1
  37. package/src/phaser/display/canvas/util.js +1 -0
  38. package/src/phaser/display/display_object.js +2 -0
  39. package/src/phaser/display/text.js +34 -4
  40. package/src/phaser/display/webgl/render_texture.js +5 -4
  41. package/src/phaser/display/webgl/shader/complex.js +1 -0
  42. package/src/phaser/display/webgl/shader/fast.js +1 -0
  43. package/src/phaser/display/webgl/shader/normal.js +3 -0
  44. package/src/phaser/display/webgl/shader/primitive.js +1 -0
  45. package/src/phaser/display/webgl/shader/strip.js +1 -0
  46. package/src/phaser/display/webgl/shader_manager.js +1 -1
  47. package/src/phaser/display/webgl/texture.js +1 -1
  48. package/src/phaser/geom/circle.test.js +198 -0
  49. package/src/phaser/geom/ellipse.test.js +83 -0
  50. package/src/phaser/geom/line.test.js +112 -0
  51. package/src/phaser/geom/matrix.test.js +242 -0
  52. package/src/phaser/geom/point.test.js +209 -0
  53. package/src/phaser/geom/rectangle.test.js +460 -0
  54. package/src/phaser/geom/rounded_rectangle.test.js +63 -0
  55. package/src/phaser/geom/util/circle.test.js +29 -0
  56. package/src/phaser/geom/util/ellipse.js +1 -1
  57. package/src/phaser/geom/util/ellipse.test.js +8 -0
  58. package/src/phaser/geom/util/line.js +1 -1
  59. package/src/phaser/geom/util/line.test.js +11 -0
  60. package/src/phaser/geom/util/matrix.test.js +23 -0
  61. package/src/phaser/geom/util/point.js +1 -1
  62. package/src/phaser/geom/util/point.test.js +9 -0
  63. package/src/phaser/geom/util/polygon.test.js +13 -0
  64. package/src/phaser/geom/util/rectangle.test.js +11 -0
  65. package/src/phaser/geom/util/rounded_rectangle.test.js +12 -0
  66. package/src/phaser/util/math.test.js +187 -0
  67. package/types/phaser/core/device_util.d.ts.map +1 -1
  68. package/types/phaser/core/dom.d.ts.map +1 -1
  69. package/types/phaser/core/game.d.ts.map +1 -1
  70. package/types/phaser/core/scene.d.ts +3 -1
  71. package/types/phaser/core/scene.d.ts.map +1 -1
  72. package/types/phaser/core/signal.d.ts +1 -1
  73. package/types/phaser/core/signal.d.ts.map +1 -1
  74. package/types/phaser/core/timer.d.ts +1 -1
  75. package/types/phaser/core/timer.d.ts.map +1 -1
  76. package/types/phaser/display/canvas/util.d.ts.map +1 -1
  77. package/types/phaser/display/display_object.d.ts +2 -0
  78. package/types/phaser/display/display_object.d.ts.map +1 -1
  79. package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
  80. package/types/phaser/display/webgl/shader/complex.d.ts +1 -0
  81. package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  82. package/types/phaser/display/webgl/shader/fast.d.ts +1 -0
  83. package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  84. package/types/phaser/display/webgl/shader/normal.d.ts +3 -0
  85. package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  86. package/types/phaser/display/webgl/shader/primitive.d.ts +1 -0
  87. package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  88. package/types/phaser/display/webgl/shader/strip.d.ts +1 -0
  89. package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  90. package/types/phaser/display/webgl/shader_manager.d.ts +7 -3
  91. package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  92. package/types/phaser/geom/util/ellipse.d.ts +1 -1
  93. package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
@@ -0,0 +1,112 @@
1
+ import { degToRad } from '../util/math.js';
2
+ import { Line } from './line.js';
3
+
4
+ describe('Line', () => {
5
+ it('should create a new line instance with correct coordinates', () => {
6
+ const line = new Line(0, 0, 10, 10);
7
+ expect(line.start.x).toBe(0);
8
+ expect(line.start.y).toBe(0);
9
+ expect(line.end.x).toBe(10);
10
+ expect(line.end.y).toBe(10);
11
+ });
12
+
13
+ it('should set the start and end points of the line correctly', () => {
14
+ const line = new Line(0, 0, 10, 10);
15
+ line.setTo(5, 5, 15, 15);
16
+ expect(line.start.x).toBe(5);
17
+ expect(line.start.y).toBe(5);
18
+ expect(line.end.x).toBe(15);
19
+ expect(line.end.y).toBe(15);
20
+ });
21
+
22
+ it('should create a new line instance from two sprites correctly', () => {
23
+ const line = new Line(0, 0, 10, 10);
24
+ const sprite1 = { x: 0, y: 0 };
25
+ const sprite2 = { x: 10, y: 10 };
26
+ const result = line.fromSprite(sprite1, sprite2);
27
+ expect(result.start.x).toBe(0);
28
+ expect(result.start.y).toBe(0);
29
+ expect(result.end.x).toBe(10);
30
+ expect(result.end.y).toBe(10);
31
+ });
32
+
33
+ it('should create a new line instance from an angle and length correctly', () => {
34
+ const line = new Line(0, 10, 10, 10);
35
+ const result = line.fromAngle(0, 0, degToRad(45), 10);
36
+ expect(result.start.x).toBe(0);
37
+ expect(result.start.y).toBe(0);
38
+ expect(result.end.x).toBeCloseTo(7.07);
39
+ expect(result.end.y).toBeCloseTo(7.07);
40
+ });
41
+
42
+ it('should rotate the line correctly', () => {
43
+ const line = new Line(0, 0, 10, 0);
44
+ const result = line.rotate(90, true);
45
+ expect(result.start.x).toBe(5);
46
+ expect(result.start.y).toBe(-5);
47
+ expect(result.end.x).toBe(5);
48
+ expect(result.end.y).toBe(5);
49
+ });
50
+
51
+ it('should rotate the line around a point correctly', () => {
52
+ const line = new Line(0, 0, 10, 10);
53
+ const result = line.rotateAround(5, 5, 90, true);
54
+ expect(result.start.x).toBe(10);
55
+ expect(result.start.y).toBe(0);
56
+ expect(result.end.x).toBe(0);
57
+ expect(result.end.y).toBe(10);
58
+ });
59
+
60
+ it('should intersect the line with another line correctly', () => {
61
+ const line = new Line(0, 0, 10, 10);
62
+ const line2 = new Line(5, 5, 15, 15);
63
+ const result = line.intersects(line2, true, null);
64
+ expect(result).toBe(null);
65
+ });
66
+
67
+ it('should reflect the line across another line correctly', () => {
68
+ const line = new Line(0, 0, 10, 10);
69
+ const line2 = new Line(5, 5, 15, 15);
70
+ const result = line.reflect(line2);
71
+ expect(result).toBeCloseTo(-5.497);
72
+ });
73
+
74
+ it('should get the midpoint of the line correctly', () => {
75
+ const line = new Line(0, 0, 10, 10);
76
+ const result = line.midPoint(null);
77
+ expect(result.x).toBe(5);
78
+ expect(result.y).toBe(5);
79
+ });
80
+
81
+ it('should center the line on a point correctly', () => {
82
+ const line = new Line(0, 0, 10, 10);
83
+ const result = line.centerOn(10, 10);
84
+ expect(line.start.x).toBe(10 - (line.end.x - line.start.x) / 2);
85
+ expect(line.start.y).toBe(10 - (line.end.y - line.start.y) / 2);
86
+ });
87
+
88
+ it('should check if a point is on the line correctly', () => {
89
+ const line = new Line(0, 0, 10, 10);
90
+ expect(line.pointOnLine(5, 0)).toBe(false);
91
+ expect(line.pointOnLine(-5, 0)).toBe(false);
92
+ });
93
+
94
+ it('should check if a point is on the segment of the line correctly', () => {
95
+ const line = new Line(0, 0, 10, 10);
96
+ expect(line.pointOnSegment(5, -10)).toBe(false);
97
+ expect(line.pointOnSegment(15, 15)).toBe(false);
98
+ });
99
+
100
+ it('should get the random point on the line correctly', () => {
101
+ const line = new Line(0, 0, 10, 10);
102
+ const result = line.random(null);
103
+ expect(result.x > 0).toBe(true);
104
+ expect(result.y > 0).toBe(true);
105
+ });
106
+
107
+ it('should get the coordinates on the line correctly', () => {
108
+ const line = new Line(0, 0, 10, 10);
109
+ const result = line.coordinatesOnLine(1, []);
110
+ expect(result.length).toBeGreaterThan(0);
111
+ });
112
+ });
@@ -0,0 +1,242 @@
1
+ import { Matrix } from './matrix.js';
2
+ import { Point } from './point.js';
3
+
4
+ describe('Constructor', () => {
5
+ it('should set default values when no arguments are passed', () => {
6
+ const matrix = new Matrix();
7
+ expect(matrix.a).toBe(1);
8
+ expect(matrix.b).toBe(0);
9
+ expect(matrix.c).toBe(0);
10
+ expect(matrix.d).toBe(1);
11
+ expect(matrix.tx).toBe(0);
12
+ expect(matrix.ty).toBe(0);
13
+ });
14
+
15
+ it('should set values when arguments are passed', () => {
16
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
17
+ expect(matrix.a).toBe(2);
18
+ expect(matrix.b).toBe(3);
19
+ expect(matrix.c).toBe(4);
20
+ expect(matrix.d).toBe(5);
21
+ expect(matrix.tx).toBe(6);
22
+ expect(matrix.ty).toBe(7);
23
+ });
24
+ });
25
+
26
+ describe('fromArray', () => {
27
+ it('should set values from an array', () => {
28
+ const matrix = new Matrix();
29
+ const array = [2, 3, 4, 5, 6, 7];
30
+ matrix.fromArray(array);
31
+ expect(matrix.a).toBe(array[0]);
32
+ expect(matrix.b).toBe(array[1]);
33
+ expect(matrix.c).toBe(array[3]);
34
+ expect(matrix.d).toBe(array[4]);
35
+ expect(matrix.tx).toBe(array[2]);
36
+ expect(matrix.ty).toBe(array[5]);
37
+ });
38
+ });
39
+
40
+ describe('setTo', () => {
41
+ it('should set values when arguments are passed', () => {
42
+ const matrix = new Matrix();
43
+ const a = 2;
44
+ const b = 3;
45
+ const c = 4;
46
+ const d = 5;
47
+ const tx = 6;
48
+ const ty = 7;
49
+ matrix.setTo(a, b, c, d, tx, ty);
50
+ expect(matrix.a).toBe(a);
51
+ expect(matrix.b).toBe(b);
52
+ expect(matrix.c).toBe(c);
53
+ expect(matrix.d).toBe(d);
54
+ expect(matrix.tx).toBe(tx);
55
+ expect(matrix.ty).toBe(ty);
56
+ });
57
+
58
+ it('should return the matrix instance', () => {
59
+ const matrix = new Matrix();
60
+ const a = 2;
61
+ const b = 3;
62
+ const c = 4;
63
+ const d = 5;
64
+ const tx = 6;
65
+ const ty = 7;
66
+ expect(matrix.setTo(a, b, c, d, tx, ty)).toBe(matrix);
67
+ });
68
+ });
69
+
70
+ describe('clone', () => {
71
+ it('should return a copy of the matrix instance', () => {
72
+ const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
73
+ const matrix2 = matrix1.clone();
74
+ expect(matrix2.a).toBe(matrix1.a);
75
+ expect(matrix2.b).toBe(matrix1.b);
76
+ expect(matrix2.c).toBe(matrix1.c);
77
+ expect(matrix2.d).toBe(matrix1.d);
78
+ expect(matrix2.tx).toBe(matrix1.tx);
79
+ expect(matrix2.ty).toBe(matrix1.ty);
80
+ });
81
+ });
82
+
83
+ describe('copyTo', () => {
84
+ it('should copy values to another matrix instance', () => {
85
+ const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
86
+ const matrix2 = new Matrix();
87
+ matrix1.copyTo(matrix2);
88
+ expect(matrix2.a).toBe(matrix1.a);
89
+ expect(matrix2.b).toBe(matrix1.b);
90
+ expect(matrix2.c).toBe(matrix1.c);
91
+ expect(matrix2.d).toBe(matrix1.d);
92
+ expect(matrix2.tx).toBe(matrix1.tx);
93
+ expect(matrix2.ty).toBe(matrix1.ty);
94
+ });
95
+ });
96
+
97
+ describe('copyFrom', () => {
98
+ it('should copy values from another matrix instance', () => {
99
+ const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
100
+ const matrix2 = new Matrix();
101
+ matrix2.copyFrom(matrix1);
102
+ expect(matrix2.a).toBe(matrix1.a);
103
+ expect(matrix2.b).toBe(matrix1.b);
104
+ expect(matrix2.c).toBe(matrix1.c);
105
+ expect(matrix2.d).toBe(matrix1.d);
106
+ expect(matrix2.tx).toBe(matrix1.tx);
107
+ expect(matrix2.ty).toBe(matrix1.ty);
108
+ });
109
+ });
110
+
111
+ describe('apply', () => {
112
+ it('should apply the matrix to a point', () => {
113
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
114
+ const point = new Point(1, 2);
115
+ const result = new Point();
116
+ matrix.apply(point, result);
117
+ expect(result.x).toBe(matrix.a * point.x + matrix.c * point.y + matrix.tx);
118
+ expect(result.y).toBe(matrix.b * point.x + matrix.d * point.y + matrix.ty);
119
+
120
+ matrix.setTo(8, 9, 10, 11, 12, 13);
121
+ matrix.apply(point, result);
122
+ expect(result.x).toBe(matrix.a * point.x + matrix.c * point.y + matrix.tx);
123
+ expect(result.y).toBe(matrix.b * point.x + matrix.d * point.y + matrix.ty);
124
+ });
125
+ });
126
+
127
+ describe('applyInverse', () => {
128
+ it('should apply the inverse of the matrix to a point', () => {
129
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
130
+ const point = new Point(1, 2);
131
+ const result = new Point();
132
+ matrix.applyInverse(point, result);
133
+ expect(result.x).toBe(2.5);
134
+ expect(result.y).toBe(-2.5);
135
+ });
136
+ });
137
+
138
+ describe('translate', () => {
139
+ it('should add the translation values to the matrix', () => {
140
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
141
+ const x = 1;
142
+ const y = 2;
143
+ matrix.translate(x, y);
144
+ expect(matrix.tx).toBe(7);
145
+ expect(matrix.ty).toBe(9);
146
+ });
147
+ });
148
+
149
+ describe('scale', () => {
150
+ it('should multiply the scaling values with the matrix', () => {
151
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
152
+ const x = 1;
153
+ const y = 2;
154
+ matrix.scale(x, y);
155
+ expect(matrix.a).toBe(2);
156
+ expect(matrix.b).toBe(6);
157
+ expect(matrix.c).toBe(4);
158
+ expect(matrix.d).toBe(10);
159
+ expect(matrix.tx).toBe(6);
160
+ expect(matrix.ty).toBe(14);
161
+ });
162
+ });
163
+
164
+ describe('rotate', () => {
165
+ it('should multiply the rotation values with the matrix', () => {
166
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
167
+ const angle = Math.PI / 2;
168
+ matrix.rotate(angle);
169
+ expect(matrix.a).toBe(-3);
170
+ expect(matrix.c).toBe(-5);
171
+ expect(matrix.tx).toBe(-7);
172
+ });
173
+ });
174
+
175
+ describe('append', () => {
176
+ it('should add the second matrix to the first one', () => {
177
+ const matrix1 = new Matrix(2, 3, 4, 5, 6, 7);
178
+ const matrix2 = new Matrix(8, 9, 10, 11, 12, 13);
179
+ matrix1.append(matrix2);
180
+ expect(matrix1.a).toBe(52);
181
+ expect(matrix1.d).toBe(85);
182
+ expect(matrix1.tx).toBe(82);
183
+ });
184
+ });
185
+
186
+ describe('identity', () => {
187
+ it('should set the values to the identity matrix', () => {
188
+ const matrix = new Matrix();
189
+ matrix.identity();
190
+ expect(matrix.a).toBe(1);
191
+ expect(matrix.c).toBe(0);
192
+ expect(matrix.tx).toBe(0);
193
+
194
+ matrix.setTo(2, 3, 4, 5, 6, 7);
195
+ matrix.identity();
196
+ expect(matrix.a).toBe(1);
197
+ expect(matrix.c).toBe(0);
198
+ expect(matrix.tx).toBe(0);
199
+ });
200
+ });
201
+
202
+ describe('toArray', () => {
203
+ it('should return the values as an array', () => {
204
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
205
+ const result = matrix.toArray();
206
+ expect(result[0]).toBe(matrix.a);
207
+ expect(result[1]).toBe(matrix.c);
208
+ expect(result[2]).toBe(matrix.tx);
209
+ expect(result[3]).toBe(matrix.b);
210
+ expect(result[4]).toBe(matrix.d);
211
+ expect(result[5]).toBe(matrix.ty);
212
+
213
+ matrix.setTo(8, 9, 10, 11, 12, 13);
214
+ const result2 = matrix.toArray();
215
+ expect(result2[0]).toBe(matrix.a);
216
+ expect(result2[1]).toBe(matrix.c);
217
+ expect(result2[2]).toBe(matrix.tx);
218
+ expect(result2[3]).toBe(matrix.b);
219
+ expect(result2[4]).toBe(matrix.d);
220
+ expect(result2[5]).toBe(matrix.ty);
221
+ });
222
+
223
+ it('should return the values as an array with transposed coordinates', () => {
224
+ const matrix = new Matrix(2, 3, 4, 5, 6, 7);
225
+ const result = matrix.toArray(true);
226
+ expect(result[0]).toBe(matrix.a);
227
+ expect(result[1]).toBe(matrix.b);
228
+ expect(result[2]).toBe(0);
229
+ expect(result[3]).toBe(matrix.c);
230
+ expect(result[4]).toBe(matrix.d);
231
+ expect(result[5]).toBe(0);
232
+
233
+ matrix.setTo(8, 9, 10, 11, 12, 13);
234
+ const result2 = matrix.toArray(true);
235
+ expect(result2[0]).toBe(matrix.a);
236
+ expect(result2[1]).toBe(matrix.b);
237
+ expect(result2[2]).toBe(0);
238
+ expect(result2[3]).toBe(matrix.c);
239
+ expect(result2[4]).toBe(matrix.d);
240
+ expect(result2[5]).toBe(0);
241
+ });
242
+ });
@@ -0,0 +1,209 @@
1
+ import { Point } from './point.js';
2
+
3
+ describe('Point', () => {
4
+ it('should create a point with default values', () => {
5
+ const point = new Point();
6
+ expect(point.x).toBe(0);
7
+ expect(point.y).toBe(0);
8
+ });
9
+
10
+ it('should create a point with custom x and y values', () => {
11
+ const point = new Point(10, 20);
12
+ expect(point.x).toBe(10);
13
+ expect(point.y).toBe(20);
14
+ });
15
+
16
+ it('should copy from another point', () => {
17
+ const point1 = new Point(10, 20);
18
+ const point2 = new Point();
19
+ point2.copyFrom(point1);
20
+ expect(point2.x).toBe(10);
21
+ expect(point2.y).toBe(20);
22
+ });
23
+
24
+ it('should invert a point', () => {
25
+ const point = new Point(10, 20);
26
+ const invertedPoint = point.invert();
27
+ expect(invertedPoint.x).toBe(20);
28
+ expect(invertedPoint.y).toBe(10);
29
+ });
30
+
31
+ it('should set to x and y values', () => {
32
+ const point = new Point();
33
+ point.setTo(10, 20);
34
+ expect(point.x).toBe(10);
35
+ expect(point.y).toBe(20);
36
+ });
37
+
38
+ it('should set to y value as x value', () => {
39
+ const point = new Point();
40
+ point.setTo(10);
41
+ expect(point.x).toBe(10);
42
+ expect(point.y).toBe(10);
43
+ });
44
+
45
+ it('should add points', () => {
46
+ const point1 = new Point(10, 20);
47
+ const point2 = new Point(30, 40);
48
+ const sum = point1.add(point2.x, point2.y);
49
+ expect(sum.x).toBe(40);
50
+ expect(sum.y).toBe(60);
51
+ });
52
+
53
+ it('should subtract points', () => {
54
+ const point1 = new Point(10, 20);
55
+ const point2 = new Point(30, 40);
56
+ const difference = point1.subtract(point2.x, point2.y);
57
+ expect(difference.x).toBe(-20);
58
+ expect(difference.y).toBe(-20);
59
+ });
60
+
61
+ it('should multiply points', () => {
62
+ const point = new Point(10, 20);
63
+ const multipliedPoint = point.multiply(2, 3);
64
+ expect(multipliedPoint.x).toBe(20);
65
+ expect(multipliedPoint.y).toBe(60);
66
+ });
67
+
68
+ it('should divide points', () => {
69
+ const point1 = new Point(10, 20);
70
+ const point2 = new Point(2, 3);
71
+ const quotient = point1.divide(2, 3);
72
+ expect(quotient.x).toBe(5);
73
+ expect(quotient.y).toBeCloseTo(6.67);
74
+ });
75
+
76
+ it('should clamp x value', () => {
77
+ const point = new Point(-10, 20);
78
+ const clampedPoint = point.clampX(-5, 10);
79
+ expect(clampedPoint.x).toBe(-5);
80
+ expect(clampedPoint.y).toBe(20);
81
+ });
82
+
83
+ it('should clamp y value', () => {
84
+ const point = new Point(10, -20);
85
+ const clampedPoint = point.clampY(-5, 10);
86
+ expect(clampedPoint.x).toBe(10);
87
+ expect(clampedPoint.y).toBe(-5);
88
+ });
89
+
90
+ it('should clamp x and y values', () => {
91
+ const point = new Point(-10, -20);
92
+ const clampedPoint = point.clamp(-5, 10);
93
+ expect(clampedPoint.x).toBe(-5);
94
+ expect(clampedPoint.y).toBe(-5);
95
+ });
96
+
97
+ it('should clone a point', () => {
98
+ const point1 = new Point(10, 20);
99
+ const clonedPoint = point1.clone();
100
+ expect(clonedPoint.x).toBe(10);
101
+ expect(clonedPoint.y).toBe(20);
102
+ });
103
+
104
+ it('should copy to another point', () => {
105
+ const point1 = new Point(10, 20);
106
+ const point2 = new Point();
107
+ point1.copyTo(point2);
108
+ expect(point2.x).toBe(10);
109
+ expect(point2.y).toBe(20);
110
+ });
111
+
112
+ it('should calculate distance between two points', () => {
113
+ const point1 = new Point(0, 0);
114
+ const point2 = new Point(3, 4);
115
+ const distance = point1.distance(point2);
116
+ expect(distance).toBeCloseTo(5);
117
+ });
118
+
119
+ it('should check if two points are equal', () => {
120
+ const point1 = new Point(10, 20);
121
+ const point2 = new Point(10, 20);
122
+ expect(point1.equals(point2)).toBe(true);
123
+ });
124
+
125
+ it('should calculate angle between two points', () => {
126
+ const point1 = new Point(0, 0);
127
+ const point2 = new Point(3, 4);
128
+ const angle = point1.angle(point2, true);
129
+ expect(angle).toBeCloseTo(53.13);
130
+ });
131
+
132
+ it('should rotate a point around another point', () => {
133
+ const point1 = new Point(10, 20);
134
+ const rotatedPoint = point1.rotate(0, 0, Math.PI / 2, true);
135
+ expect(rotatedPoint.x).toBeCloseTo(9.447);
136
+ expect(rotatedPoint.y).toBeCloseTo(20.266);
137
+ });
138
+
139
+ it('should get magnitude of a point', () => {
140
+ const point = new Point(3, 4);
141
+ expect(point.getMagnitude()).toBeCloseTo(5);
142
+ });
143
+
144
+ it('should get magnitude squared of a point', () => {
145
+ const point = new Point(3, 4);
146
+ expect(point.getMagnitudeSq()).toBeCloseTo(25);
147
+ });
148
+
149
+ it('should set magnitude of a point', () => {
150
+ const point = new Point(3, 4);
151
+ const newPoint = point.setMagnitude(10);
152
+ expect(newPoint.x).toBe(6);
153
+ expect(newPoint.y).toBe(8);
154
+ });
155
+
156
+ it('should normalize a point', () => {
157
+ const point = new Point(3, 4);
158
+ const normalizedPoint = point.normalize();
159
+ expect(normalizedPoint.x).toBeCloseTo(0.6);
160
+ expect(normalizedPoint.y).toBeCloseTo(0.8);
161
+ });
162
+
163
+ it('should check if a point is zero', () => {
164
+ const point1 = new Point(0, 0);
165
+ const point2 = new Point(10, 20);
166
+ expect(point1.isZero()).toBe(true);
167
+ expect(point2.isZero()).toBe(false);
168
+ });
169
+
170
+ it('should calculate dot product of two points', () => {
171
+ const point1 = new Point(1, 1);
172
+ const point2 = new Point(2, 2);
173
+ expect(point1.dot(point2)).toBe(4);
174
+ });
175
+
176
+ it('should calculate cross product of two points', () => {
177
+ const point1 = new Point(1, 1);
178
+ const point2 = new Point(1, 2);
179
+ expect(point1.cross(point2)).toBe(1);
180
+ });
181
+
182
+ it('should get perpendicular point', () => {
183
+ const point = new Point(10, 20);
184
+ const perpPoint = point.perp();
185
+ expect(perpPoint.x).toBe(-20);
186
+ expect(perpPoint.y).toBe(10);
187
+ });
188
+
189
+ it('should get right-hand normal point', () => {
190
+ const point = new Point(10, 20);
191
+ const normalPoint = point.normalRightHand();
192
+ expect(normalPoint.x).toBe(-20);
193
+ expect(normalPoint.y).toBe(10);
194
+ });
195
+
196
+ it('should floor a point', () => {
197
+ const point = new Point(3.14, 4.23);
198
+ const flooredPoint = point.floor();
199
+ expect(flooredPoint.x).toBe(3);
200
+ expect(flooredPoint.y).toBe(4);
201
+ });
202
+
203
+ it('should ceil a point', () => {
204
+ const point = new Point(3.14, 4.23);
205
+ const ceiledPoint = point.ceil();
206
+ expect(ceiledPoint.x).toBe(4);
207
+ expect(ceiledPoint.y).toBe(5);
208
+ });
209
+ });