@vpmedia/phaser 1.75.0 → 1.76.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/README.md +1 -1
- package/coverage/clover.xml +1089 -3
- package/coverage/coverage-final.json +19 -1
- package/coverage/lcov-report/core/const.js.html +901 -0
- package/coverage/lcov-report/core/index.html +116 -0
- package/coverage/lcov-report/geom/circle.js.html +1003 -0
- package/coverage/lcov-report/geom/ellipse.js.html +388 -0
- package/coverage/lcov-report/geom/index.html +221 -0
- package/coverage/lcov-report/geom/line.js.html +1102 -0
- package/coverage/lcov-report/geom/matrix.js.html +751 -0
- package/coverage/lcov-report/geom/point.js.html +1027 -0
- package/coverage/lcov-report/geom/polygon.js.html +604 -0
- package/coverage/lcov-report/geom/rectangle.js.html +1774 -0
- package/coverage/lcov-report/geom/rounded_rectangle.js.html +226 -0
- package/coverage/lcov-report/geom/util/circle.js.html +436 -0
- package/coverage/lcov-report/geom/util/ellipse.js.html +139 -0
- package/coverage/lcov-report/geom/util/index.html +221 -0
- package/coverage/lcov-report/geom/util/line.js.html +475 -0
- package/coverage/lcov-report/geom/util/matrix.js.html +223 -0
- package/coverage/lcov-report/geom/util/point.js.html +961 -0
- package/coverage/lcov-report/geom/util/polygon.js.html +124 -0
- package/coverage/lcov-report/geom/util/rectangle.js.html +784 -0
- package/coverage/lcov-report/geom/util/rounded_rectangle.js.html +136 -0
- package/coverage/lcov-report/index.html +70 -10
- package/coverage/lcov-report/util/index.html +116 -0
- package/coverage/lcov-report/util/math.js.html +958 -0
- package/coverage/lcov.info +2179 -0
- package/package.json +1 -1
- package/src/phaser/core/device_util.js +1 -0
- package/src/phaser/core/dom.js +1 -0
- package/src/phaser/core/game.js +4 -1
- package/src/phaser/core/input_handler.js +2 -2
- package/src/phaser/core/scene.js +3 -1
- package/src/phaser/core/signal.js +1 -1
- package/src/phaser/core/timer.js +1 -1
- package/src/phaser/display/canvas/util.js +1 -0
- package/src/phaser/display/display_object.js +2 -0
- package/src/phaser/display/webgl/render_texture.js +5 -4
- package/src/phaser/display/webgl/shader/complex.js +1 -0
- package/src/phaser/display/webgl/shader/fast.js +1 -0
- package/src/phaser/display/webgl/shader/normal.js +3 -0
- package/src/phaser/display/webgl/shader/primitive.js +1 -0
- package/src/phaser/display/webgl/shader/strip.js +1 -0
- package/src/phaser/display/webgl/shader_manager.js +1 -1
- package/src/phaser/display/webgl/texture.js +1 -1
- package/src/phaser/geom/circle.test.js +198 -0
- package/src/phaser/geom/ellipse.test.js +83 -0
- package/src/phaser/geom/line.test.js +112 -0
- package/src/phaser/geom/matrix.test.js +242 -0
- package/src/phaser/geom/point.test.js +209 -0
- package/src/phaser/geom/rectangle.test.js +460 -0
- package/src/phaser/geom/rounded_rectangle.test.js +63 -0
- package/src/phaser/geom/util/circle.test.js +29 -0
- package/src/phaser/geom/util/ellipse.js +1 -1
- package/src/phaser/geom/util/ellipse.test.js +8 -0
- package/src/phaser/geom/util/line.js +1 -1
- package/src/phaser/geom/util/line.test.js +11 -0
- package/src/phaser/geom/util/matrix.test.js +23 -0
- package/src/phaser/geom/util/point.js +1 -1
- package/src/phaser/geom/util/point.test.js +9 -0
- package/src/phaser/geom/util/polygon.test.js +13 -0
- package/src/phaser/geom/util/rectangle.test.js +11 -0
- package/src/phaser/geom/util/rounded_rectangle.test.js +12 -0
- package/src/phaser/util/math.test.js +187 -0
- package/types/phaser/core/device_util.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +3 -1
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +1 -1
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +1 -1
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +2 -0
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +1 -0
- package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/fast.d.ts +1 -0
- package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/normal.d.ts +3 -0
- package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/primitive.d.ts +1 -0
- package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/strip.d.ts +1 -0
- package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader_manager.d.ts +7 -3
- package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/types/phaser/geom/util/ellipse.d.ts +1 -1
- package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
|
@@ -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
|
+
});
|