@vpmedia/phaser 1.123.0 → 1.125.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/dist/index.js +635 -623
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +3 -3
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +27 -2
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts +11 -11
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/callback.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +125 -19
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +3 -2
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +3 -2
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +5 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +3 -3
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +8 -8
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +11 -2
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +14 -1
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +1 -1
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +16 -6
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +13 -5
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +9 -7
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +6 -5
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +9 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +5 -3
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +1 -1
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +1 -1
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +6 -5
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +3 -2
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +2 -16
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +2 -2
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +8 -4
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +10 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts +2 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +11 -11
- package/src/phaser/core/animation_manager.ts +12 -12
- package/src/phaser/core/animation_parser.ts +39 -37
- package/src/phaser/core/array_set.ts +28 -28
- package/src/phaser/core/cache.test.ts +33 -33
- package/src/phaser/core/cache.ts +7 -7
- package/src/phaser/core/callback.ts +1 -0
- package/src/phaser/core/callback_context.test.ts +8 -8
- package/src/phaser/core/device_util.ts +4 -4
- package/src/phaser/core/dom.ts +38 -24
- package/src/phaser/core/factory.ts +9 -2
- package/src/phaser/core/frame_data.test.ts +23 -23
- package/src/phaser/core/frame_data.ts +2 -5
- package/src/phaser/core/game.ts +12 -12
- package/src/phaser/core/input.ts +11 -10
- package/src/phaser/core/input_handler.test.ts +18 -18
- package/src/phaser/core/input_handler.ts +14 -14
- package/src/phaser/core/input_mouse.ts +13 -12
- package/src/phaser/core/input_pointer.test.ts +26 -26
- package/src/phaser/core/input_pointer.ts +4 -4
- package/src/phaser/core/input_touch.ts +8 -8
- package/src/phaser/core/loader.test.ts +26 -26
- package/src/phaser/core/loader.ts +63 -75
- package/src/phaser/core/loader_parser.test.ts +16 -16
- package/src/phaser/core/loader_parser.ts +16 -6
- package/src/phaser/core/raf.ts +1 -1
- package/src/phaser/core/registry.test.ts +6 -6
- package/src/phaser/core/scale_manager.ts +12 -11
- package/src/phaser/core/scene_manager.test.ts +30 -30
- package/src/phaser/core/scene_manager.ts +3 -3
- package/src/phaser/core/signal.test.ts +8 -8
- package/src/phaser/core/signal.ts +3 -3
- package/src/phaser/core/signal_dispatch.test.ts +30 -30
- package/src/phaser/core/sound.ts +45 -40
- package/src/phaser/core/sound_manager.ts +18 -22
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +22 -12
- package/src/phaser/core/time.ts +1 -1
- package/src/phaser/core/timer.test.ts +47 -47
- package/src/phaser/core/timer.ts +2 -2
- package/src/phaser/core/tween.ts +34 -36
- package/src/phaser/core/tween_data.test.ts +119 -0
- package/src/phaser/core/tween_data.ts +54 -39
- package/src/phaser/core/tween_easing.test.ts +5 -5
- package/src/phaser/core/tween_manager.ts +2 -2
- package/src/phaser/display/bitmap_text.test.ts +30 -30
- package/src/phaser/display/bitmap_text.ts +3 -3
- package/src/phaser/display/button.ts +20 -18
- package/src/phaser/display/canvas/buffer.ts +2 -2
- package/src/phaser/display/canvas/graphics.ts +2 -2
- package/src/phaser/display/canvas/masker.ts +1 -1
- package/src/phaser/display/canvas/pool.test.ts +20 -20
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +18 -16
- package/src/phaser/display/canvas/tinter.ts +1 -1
- package/src/phaser/display/canvas/util.test.ts +25 -25
- package/src/phaser/display/canvas/util.ts +2 -2
- package/src/phaser/display/display_object.ts +16 -15
- package/src/phaser/display/graphics.test.ts +70 -20
- package/src/phaser/display/graphics.ts +46 -42
- package/src/phaser/display/group.ts +13 -12
- package/src/phaser/display/image.ts +35 -31
- package/src/phaser/display/sprite_util.ts +4 -3
- package/src/phaser/display/text.test.ts +28 -25
- package/src/phaser/display/text.ts +56 -62
- package/src/phaser/display/webgl/abstract_filter.ts +21 -11
- package/src/phaser/display/webgl/blend_manager.ts +4 -5
- package/src/phaser/display/webgl/earcut.test.ts +20 -20
- package/src/phaser/display/webgl/earcut.ts +46 -42
- package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
- package/src/phaser/display/webgl/filter_manager.ts +7 -4
- package/src/phaser/display/webgl/filter_texture.ts +5 -5
- package/src/phaser/display/webgl/graphics.ts +3 -3
- package/src/phaser/display/webgl/mask_manager.ts +9 -14
- package/src/phaser/display/webgl/render_texture.ts +15 -14
- package/src/phaser/display/webgl/renderer.ts +10 -9
- package/src/phaser/display/webgl/shader/normal.ts +45 -35
- package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
- package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
- package/src/phaser/display/webgl/shader_manager.ts +1 -1
- package/src/phaser/display/webgl/sprite_batch.ts +10 -10
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +2 -1
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +4 -4
- package/src/phaser/geom/circle.test.ts +38 -38
- package/src/phaser/geom/circle.ts +7 -7
- package/src/phaser/geom/ellipse.test.ts +12 -12
- package/src/phaser/geom/line.test.ts +15 -15
- package/src/phaser/geom/line.ts +5 -2
- package/src/phaser/geom/matrix.test.ts +31 -31
- package/src/phaser/geom/point.test.ts +31 -31
- package/src/phaser/geom/polygon.test.ts +27 -27
- package/src/phaser/geom/polygon.ts +2 -2
- package/src/phaser/geom/rectangle.test.ts +87 -87
- package/src/phaser/geom/rectangle.ts +12 -13
- package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +5 -5
- package/src/phaser/geom/util/circle.ts +8 -11
- package/src/phaser/geom/util/ellipse.test.ts +2 -2
- package/src/phaser/geom/util/line.test.ts +2 -2
- package/src/phaser/geom/util/matrix.test.ts +4 -4
- package/src/phaser/geom/util/point.test.ts +2 -2
- package/src/phaser/geom/util/point.ts +6 -8
- package/src/phaser/geom/util/polygon.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.ts +1 -1
- package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
- package/src/phaser/util/math.test.ts +41 -41
- package/src/phaser/util/math.ts +7 -5
|
@@ -2,16 +2,16 @@ import { expect, describe, it } from 'vitest';
|
|
|
2
2
|
import { Circle } from './circle.js';
|
|
3
3
|
import { Point } from './point.js';
|
|
4
4
|
|
|
5
|
-
describe('Circle', () => {
|
|
6
|
-
describe('constructor', () => {
|
|
7
|
-
it('should initialize properties correctly when no arguments are provided', () => {
|
|
5
|
+
describe('Circle', (): void => {
|
|
6
|
+
describe('constructor', (): void => {
|
|
7
|
+
it('should initialize properties correctly when no arguments are provided', (): void => {
|
|
8
8
|
const circle = new Circle();
|
|
9
9
|
expect(circle.x).toBe(0);
|
|
10
10
|
expect(circle.y).toBe(0);
|
|
11
11
|
expect(circle.diameter).toBe(0);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
it('should initialize properties correctly when x, y, and diameter are provided', () => {
|
|
14
|
+
it('should initialize properties correctly when x, y, and diameter are provided', (): void => {
|
|
15
15
|
const circle = new Circle(10, 20, 30);
|
|
16
16
|
expect(circle.x).toBe(10);
|
|
17
17
|
expect(circle.y).toBe(20);
|
|
@@ -19,21 +19,21 @@ describe('Circle', () => {
|
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
describe('circumference', () => {
|
|
23
|
-
it('should calculate the circumference correctly when diameter is provided', () => {
|
|
22
|
+
describe('circumference', (): void => {
|
|
23
|
+
it('should calculate the circumference correctly when diameter is provided', (): void => {
|
|
24
24
|
const circle = new Circle(0, 0, 1);
|
|
25
25
|
expect(circle.circumference()).toBeCloseTo(Math.PI);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it('should return Infinity when diameter is 0', () => {
|
|
28
|
+
it('should return Infinity when diameter is 0', (): void => {
|
|
29
29
|
const circle = new Circle();
|
|
30
30
|
circle.diameter = 0;
|
|
31
31
|
expect(circle.circumference()).toBe(0);
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
describe('random', () => {
|
|
36
|
-
it('should generate a random point within the circle correctly', () => {
|
|
35
|
+
describe('random', (): void => {
|
|
36
|
+
it('should generate a random point within the circle correctly', (): void => {
|
|
37
37
|
const circle = new Circle();
|
|
38
38
|
const output = new Point();
|
|
39
39
|
circle.random(output);
|
|
@@ -42,7 +42,7 @@ describe('Circle', () => {
|
|
|
42
42
|
expect(Math.hypot(output.x, output.y)).toBe(0);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
it('should generate a random point within the circle correctly when output is not provided', () => {
|
|
45
|
+
it('should generate a random point within the circle correctly when output is not provided', (): void => {
|
|
46
46
|
const circle = new Circle();
|
|
47
47
|
const output = new Point();
|
|
48
48
|
circle.random(output);
|
|
@@ -52,8 +52,8 @@ describe('Circle', () => {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
describe('getBounds', () => {
|
|
56
|
-
it('should calculate the bounds correctly when diameter is provided', () => {
|
|
55
|
+
describe('getBounds', (): void => {
|
|
56
|
+
it('should calculate the bounds correctly when diameter is provided', (): void => {
|
|
57
57
|
const circle = new Circle(0, 0, 1);
|
|
58
58
|
const bounds = circle.getBounds();
|
|
59
59
|
expect(bounds.x).toBe(-0.5);
|
|
@@ -62,7 +62,7 @@ describe('Circle', () => {
|
|
|
62
62
|
expect(bounds.height).toBe(1);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it('should return empty rectangle when diameter is 0', () => {
|
|
65
|
+
it('should return empty rectangle when diameter is 0', (): void => {
|
|
66
66
|
const circle = new Circle();
|
|
67
67
|
circle.diameter = 0;
|
|
68
68
|
const bounds = circle.getBounds();
|
|
@@ -73,8 +73,8 @@ describe('Circle', () => {
|
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
describe('setTo', () => {
|
|
77
|
-
it('should set properties correctly when x, y, and diameter are provided', () => {
|
|
76
|
+
describe('setTo', (): void => {
|
|
77
|
+
it('should set properties correctly when x, y, and diameter are provided', (): void => {
|
|
78
78
|
const circle = new Circle();
|
|
79
79
|
circle.setTo(10, 20, 30);
|
|
80
80
|
expect(circle.x).toBe(10);
|
|
@@ -82,15 +82,15 @@ describe('Circle', () => {
|
|
|
82
82
|
expect(circle.diameter).toBe(30);
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('should set radius property correctly when diameter is changed', () => {
|
|
85
|
+
it('should set radius property correctly when diameter is changed', (): void => {
|
|
86
86
|
const circle = new Circle();
|
|
87
87
|
circle.diameter = 1;
|
|
88
88
|
expect(circle.radius).toBe(0.5);
|
|
89
89
|
});
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
describe('copyFrom', () => {
|
|
93
|
-
it('should copy properties correctly from another Circle instance', () => {
|
|
92
|
+
describe('copyFrom', (): void => {
|
|
93
|
+
it('should copy properties correctly from another Circle instance', (): void => {
|
|
94
94
|
const source = new Circle(10, 20, 30);
|
|
95
95
|
const dest = new Circle();
|
|
96
96
|
dest.copyFrom(source);
|
|
@@ -100,8 +100,8 @@ describe('Circle', () => {
|
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
describe('copyTo', () => {
|
|
104
|
-
it('should copy properties correctly to another Circle instance', () => {
|
|
103
|
+
describe('copyTo', (): void => {
|
|
104
|
+
it('should copy properties correctly to another Circle instance', (): void => {
|
|
105
105
|
const source = new Circle(10, 20, 30);
|
|
106
106
|
const dest = new Circle();
|
|
107
107
|
source.copyTo(dest);
|
|
@@ -111,22 +111,22 @@ describe('Circle', () => {
|
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
describe('distance', () => {
|
|
115
|
-
it('should calculate the distance correctly between two points within a circle', () => {
|
|
114
|
+
describe('distance', (): void => {
|
|
115
|
+
it('should calculate the distance correctly between two points within a circle', (): void => {
|
|
116
116
|
const circle = new Circle();
|
|
117
117
|
const point = new Point(1, 1);
|
|
118
118
|
expect(circle.distance(point)).toBeCloseTo(Math.hypot(point.x, point.y));
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
it('should return Infinity when diameter is 0', () => {
|
|
121
|
+
it('should return Infinity when diameter is 0', (): void => {
|
|
122
122
|
const circle = new Circle();
|
|
123
123
|
circle.diameter = 0;
|
|
124
124
|
expect(circle.distance(new Point(1, 1))).toBeCloseTo(Math.SQRT2);
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
-
describe('clone', () => {
|
|
129
|
-
it('should create a deep copy of the Circle instance correctly', () => {
|
|
128
|
+
describe('clone', (): void => {
|
|
129
|
+
it('should create a deep copy of the Circle instance correctly', (): void => {
|
|
130
130
|
const source = new Circle(10, 20, 30);
|
|
131
131
|
const clone = source.clone();
|
|
132
132
|
expect(clone.x).toBe(source.x);
|
|
@@ -135,35 +135,35 @@ describe('Circle', () => {
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
describe('contains', () => {
|
|
139
|
-
it('should determine if a point is within the circle correctly', () => {
|
|
138
|
+
describe('contains', (): void => {
|
|
139
|
+
it('should determine if a point is within the circle correctly', (): void => {
|
|
140
140
|
const circle = new Circle();
|
|
141
141
|
const point = new Point(1, 1);
|
|
142
142
|
expect(circle.contains(point.x, point.y)).toBe(false);
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
it('should return false when diameter is 0', () => {
|
|
145
|
+
it('should return false when diameter is 0', (): void => {
|
|
146
146
|
const circle = new Circle();
|
|
147
147
|
circle.diameter = 0;
|
|
148
148
|
expect(circle.contains(1, 1)).toBe(false);
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
-
describe('circumferencePoint', () => {
|
|
153
|
-
it('should generate a point on the circumference correctly', () => {
|
|
152
|
+
describe('circumferencePoint', (): void => {
|
|
153
|
+
it('should generate a point on the circumference correctly', (): void => {
|
|
154
154
|
const circle = new Circle();
|
|
155
155
|
expect(circle.circumferencePoint(Math.PI / 2).x).toBeCloseTo(0.5 * circle.radius);
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
it('should return null when diameter is 0', () => {
|
|
158
|
+
it('should return null when diameter is 0', (): void => {
|
|
159
159
|
const circle = new Circle();
|
|
160
160
|
circle.diameter = 0;
|
|
161
161
|
expect(circle.circumferencePoint(Math.PI / 2).type).toBe(25);
|
|
162
162
|
});
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
describe('offset', () => {
|
|
166
|
-
it('should offset the circle correctly by a point', () => {
|
|
165
|
+
describe('offset', (): void => {
|
|
166
|
+
it('should offset the circle correctly by a point', (): void => {
|
|
167
167
|
const circle = new Circle();
|
|
168
168
|
const point = new Point(1, 1);
|
|
169
169
|
circle.offset(point.x, point.y);
|
|
@@ -171,7 +171,7 @@ describe('Circle', () => {
|
|
|
171
171
|
expect(circle.y).toBeGreaterThan(0);
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
it('should return the Circle instance itself', () => {
|
|
174
|
+
it('should return the Circle instance itself', (): void => {
|
|
175
175
|
const circle = new Circle();
|
|
176
176
|
const point = new Point(1, 1);
|
|
177
177
|
circle.offset(point.x, point.y);
|
|
@@ -179,8 +179,8 @@ describe('Circle', () => {
|
|
|
179
179
|
});
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
describe('offsetPoint', () => {
|
|
183
|
-
it('should offset the circle correctly by a point', () => {
|
|
182
|
+
describe('offsetPoint', (): void => {
|
|
183
|
+
it('should offset the circle correctly by a point', (): void => {
|
|
184
184
|
const circle = new Circle();
|
|
185
185
|
const point = new Point(1, 1);
|
|
186
186
|
circle.offsetPoint(point);
|
|
@@ -189,8 +189,8 @@ describe('Circle', () => {
|
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
-
describe('toString', () => {
|
|
193
|
-
it('should generate the correct string representation of the Circle instance', () => {
|
|
192
|
+
describe('toString', (): void => {
|
|
193
|
+
it('should generate the correct string representation of the Circle instance', (): void => {
|
|
194
194
|
const circle = new Circle();
|
|
195
195
|
expect(circle.toString()).toBe('[{Circle (x=0 y=0 diameter=0 radius=0)}]');
|
|
196
196
|
});
|
|
@@ -182,7 +182,7 @@ export class Circle {
|
|
|
182
182
|
/**
|
|
183
183
|
* Sets the diameter of this circle.
|
|
184
184
|
*/
|
|
185
|
-
public set diameter(value) {
|
|
185
|
+
public set diameter(value: number) {
|
|
186
186
|
if (value > 0) {
|
|
187
187
|
this._diameter = value;
|
|
188
188
|
this._radius = value * 0.5;
|
|
@@ -200,7 +200,7 @@ export class Circle {
|
|
|
200
200
|
/**
|
|
201
201
|
* Sets the radius of this circle.
|
|
202
202
|
*/
|
|
203
|
-
public set radius(value) {
|
|
203
|
+
public set radius(value: number) {
|
|
204
204
|
if (value > 0) {
|
|
205
205
|
this._radius = value;
|
|
206
206
|
this._diameter = value * 2;
|
|
@@ -218,7 +218,7 @@ export class Circle {
|
|
|
218
218
|
/**
|
|
219
219
|
* Sets the left coordinate of this circle.
|
|
220
220
|
*/
|
|
221
|
-
public set left(value) {
|
|
221
|
+
public set left(value: number) {
|
|
222
222
|
if (value > this.x) {
|
|
223
223
|
this._radius = 0;
|
|
224
224
|
this._diameter = 0;
|
|
@@ -238,7 +238,7 @@ export class Circle {
|
|
|
238
238
|
/**
|
|
239
239
|
* Sets the right coordinate of this circle.
|
|
240
240
|
*/
|
|
241
|
-
public set right(value) {
|
|
241
|
+
public set right(value: number) {
|
|
242
242
|
if (value < this.x) {
|
|
243
243
|
this._radius = 0;
|
|
244
244
|
this._diameter = 0;
|
|
@@ -258,7 +258,7 @@ export class Circle {
|
|
|
258
258
|
/**
|
|
259
259
|
* Sets the top coordinate of this circle.
|
|
260
260
|
*/
|
|
261
|
-
public set top(value) {
|
|
261
|
+
public set top(value: number) {
|
|
262
262
|
if (value > this.y) {
|
|
263
263
|
this._radius = 0;
|
|
264
264
|
this._diameter = 0;
|
|
@@ -278,7 +278,7 @@ export class Circle {
|
|
|
278
278
|
/**
|
|
279
279
|
* Sets the bottom coordinate of this circle.
|
|
280
280
|
*/
|
|
281
|
-
public set bottom(value) {
|
|
281
|
+
public set bottom(value: number) {
|
|
282
282
|
if (value < this.y) {
|
|
283
283
|
this._radius = 0;
|
|
284
284
|
this._diameter = 0;
|
|
@@ -309,7 +309,7 @@ export class Circle {
|
|
|
309
309
|
/**
|
|
310
310
|
* Sets whether this circle is empty (zero diameter).
|
|
311
311
|
*/
|
|
312
|
-
public set empty(value) {
|
|
312
|
+
public set empty(value: boolean) {
|
|
313
313
|
if (value) {
|
|
314
314
|
this.setTo(0, 0, 0);
|
|
315
315
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Ellipse } from './ellipse.js';
|
|
3
3
|
|
|
4
|
-
describe('Ellipse', () => {
|
|
5
|
-
it('should create an ellipse with default values', () => {
|
|
4
|
+
describe('Ellipse', (): void => {
|
|
5
|
+
it('should create an ellipse with default values', (): void => {
|
|
6
6
|
const ellipse = new Ellipse();
|
|
7
7
|
expect(ellipse.x).toBe(0);
|
|
8
8
|
expect(ellipse.y).toBe(0);
|
|
@@ -10,7 +10,7 @@ describe('Ellipse', () => {
|
|
|
10
10
|
expect(ellipse.height).toBe(0);
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it('should create an ellipse with custom x, y, width, height', () => {
|
|
13
|
+
it('should create an ellipse with custom x, y, width, height', (): void => {
|
|
14
14
|
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
15
15
|
expect(ellipse.x).toBe(10);
|
|
16
16
|
expect(ellipse.y).toBe(20);
|
|
@@ -18,7 +18,7 @@ describe('Ellipse', () => {
|
|
|
18
18
|
expect(ellipse.height).toBe(40);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it('should set the ellipse values to new x, y, width, height', () => {
|
|
21
|
+
it('should set the ellipse values to new x, y, width, height', (): void => {
|
|
22
22
|
const ellipse = new Ellipse();
|
|
23
23
|
ellipse.setTo(10, 20, 30, 40);
|
|
24
24
|
expect(ellipse.x).toBe(10);
|
|
@@ -27,13 +27,13 @@ describe('Ellipse', () => {
|
|
|
27
27
|
expect(ellipse.height).toBe(40);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
it('should return the ellipse instance', () => {
|
|
30
|
+
it('should return the ellipse instance', (): void => {
|
|
31
31
|
const ellipse = new Ellipse();
|
|
32
32
|
const result = ellipse.setTo(10, 20, 30, 40);
|
|
33
33
|
expect(result).toBe(ellipse);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it('should create a rectangle with correct bounds', () => {
|
|
36
|
+
it('should create a rectangle with correct bounds', (): void => {
|
|
37
37
|
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
38
38
|
const bounds = ellipse.getBounds();
|
|
39
39
|
expect(bounds.x).toBe(10 - 30);
|
|
@@ -42,7 +42,7 @@ describe('Ellipse', () => {
|
|
|
42
42
|
expect(bounds.height).toBe(40);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
it('should copy the values from another ellipse', () => {
|
|
45
|
+
it('should copy the values from another ellipse', (): void => {
|
|
46
46
|
const source = new Ellipse(10, 20, 30, 40);
|
|
47
47
|
const target = new Ellipse();
|
|
48
48
|
target.copyFrom(source);
|
|
@@ -52,7 +52,7 @@ describe('Ellipse', () => {
|
|
|
52
52
|
expect(target.height).toBe(source.height);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
it('should copy the values to another ellipse', () => {
|
|
55
|
+
it('should copy the values to another ellipse', (): void => {
|
|
56
56
|
const source = new Ellipse(10, 20, 30, 40);
|
|
57
57
|
const target = new Ellipse();
|
|
58
58
|
source.copyTo(target);
|
|
@@ -62,24 +62,24 @@ describe('Ellipse', () => {
|
|
|
62
62
|
expect(target.height).toBe(source.height);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it('should return true if point is inside the ellipse', () => {
|
|
65
|
+
it('should return true if point is inside the ellipse', (): void => {
|
|
66
66
|
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
67
67
|
expect(ellipse.contains(20, 30)).toBe(true);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
it('should return false if point is outside the ellipse', () => {
|
|
70
|
+
it('should return false if point is outside the ellipse', (): void => {
|
|
71
71
|
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
72
72
|
expect(ellipse.contains(-5, -10)).toBe(false);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('should generate a random point within the ellipse', () => {
|
|
75
|
+
it('should generate a random point within the ellipse', (): void => {
|
|
76
76
|
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
77
77
|
const point = ellipse.random();
|
|
78
78
|
expect(point.x).toBeTypeOf('number');
|
|
79
79
|
expect(point.y).toBeTypeOf('number');
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
it('should return a string representation of the ellipse', () => {
|
|
82
|
+
it('should return a string representation of the ellipse', (): void => {
|
|
83
83
|
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
84
84
|
expect(ellipse.toString()).toBe('[{Ellipse (x=10 y=20 width=30 height=40)}]');
|
|
85
85
|
});
|
|
@@ -2,8 +2,8 @@ import { expect, describe, it } from 'vitest';
|
|
|
2
2
|
import { degToRad } from '../util/math.js';
|
|
3
3
|
import { Line } from './line.js';
|
|
4
4
|
|
|
5
|
-
describe('Line', () => {
|
|
6
|
-
it('should create a new line instance with correct coordinates', () => {
|
|
5
|
+
describe('Line', (): void => {
|
|
6
|
+
it('should create a new line instance with correct coordinates', (): void => {
|
|
7
7
|
const line = new Line(0, 0, 10, 10);
|
|
8
8
|
expect(line.start.x).toBe(0);
|
|
9
9
|
expect(line.start.y).toBe(0);
|
|
@@ -11,7 +11,7 @@ describe('Line', () => {
|
|
|
11
11
|
expect(line.end.y).toBe(10);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
it('should set the start and end points of the line correctly', () => {
|
|
14
|
+
it('should set the start and end points of the line correctly', (): void => {
|
|
15
15
|
const line = new Line(0, 0, 10, 10);
|
|
16
16
|
line.setTo(5, 5, 15, 15);
|
|
17
17
|
expect(line.start.x).toBe(5);
|
|
@@ -20,7 +20,7 @@ describe('Line', () => {
|
|
|
20
20
|
expect(line.end.y).toBe(15);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it('should create a new line instance from two sprites correctly', () => {
|
|
23
|
+
it('should create a new line instance from two sprites correctly', (): void => {
|
|
24
24
|
const line = new Line(0, 0, 10, 10);
|
|
25
25
|
const sprite1 = { x: 0, y: 0 };
|
|
26
26
|
const sprite2 = { x: 10, y: 10 };
|
|
@@ -31,7 +31,7 @@ describe('Line', () => {
|
|
|
31
31
|
expect(result.end.y).toBe(10);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it('should create a new line instance from an angle and length correctly', () => {
|
|
34
|
+
it('should create a new line instance from an angle and length correctly', (): void => {
|
|
35
35
|
const line = new Line(0, 10, 10, 10);
|
|
36
36
|
const result = line.fromAngle(0, 0, degToRad(45), 10);
|
|
37
37
|
expect(result.start.x).toBe(0);
|
|
@@ -40,7 +40,7 @@ describe('Line', () => {
|
|
|
40
40
|
expect(result.end.y).toBeCloseTo(7.07);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('should rotate the line correctly', () => {
|
|
43
|
+
it('should rotate the line correctly', (): void => {
|
|
44
44
|
const line = new Line(0, 0, 10, 0);
|
|
45
45
|
const result = line.rotate(90, true);
|
|
46
46
|
expect(result.start.x).toBe(5);
|
|
@@ -49,7 +49,7 @@ describe('Line', () => {
|
|
|
49
49
|
expect(result.end.y).toBe(5);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it('should rotate the line around a point correctly', () => {
|
|
52
|
+
it('should rotate the line around a point correctly', (): void => {
|
|
53
53
|
const line = new Line(0, 0, 10, 10);
|
|
54
54
|
const result = line.rotateAround(5, 5, 90, true);
|
|
55
55
|
expect(result.start.x).toBe(10);
|
|
@@ -58,54 +58,54 @@ describe('Line', () => {
|
|
|
58
58
|
expect(result.end.y).toBe(10);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it('should intersect the line with another line correctly', () => {
|
|
61
|
+
it('should intersect the line with another line correctly', (): void => {
|
|
62
62
|
const line = new Line(0, 0, 10, 10);
|
|
63
63
|
const line2 = new Line(5, 5, 15, 15);
|
|
64
64
|
const result = line.intersects(line2, true, null);
|
|
65
65
|
expect(result).toBeNull();
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it('should reflect the line across another line correctly', () => {
|
|
68
|
+
it('should reflect the line across another line correctly', (): void => {
|
|
69
69
|
const line = new Line(0, 0, 10, 10);
|
|
70
70
|
const line2 = new Line(5, 5, 15, 15);
|
|
71
71
|
const result = line.reflect(line2);
|
|
72
72
|
expect(result).toBeCloseTo(-5.497);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('should get the midpoint of the line correctly', () => {
|
|
75
|
+
it('should get the midpoint of the line correctly', (): void => {
|
|
76
76
|
const line = new Line(0, 0, 10, 10);
|
|
77
77
|
const result = line.midPoint(null);
|
|
78
78
|
expect(result.x).toBe(5);
|
|
79
79
|
expect(result.y).toBe(5);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
it('should center the line on a point correctly', () => {
|
|
82
|
+
it('should center the line on a point correctly', (): void => {
|
|
83
83
|
const line = new Line(0, 0, 10, 10);
|
|
84
84
|
line.centerOn(10, 10);
|
|
85
85
|
expect(line.start.x).toBe(10 - (line.end.x - line.start.x) / 2);
|
|
86
86
|
expect(line.start.y).toBe(10 - (line.end.y - line.start.y) / 2);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
it('should check if a point is on the line correctly', () => {
|
|
89
|
+
it('should check if a point is on the line correctly', (): void => {
|
|
90
90
|
const line = new Line(0, 0, 10, 10);
|
|
91
91
|
expect(line.pointOnLine(5, 0)).toBe(false);
|
|
92
92
|
expect(line.pointOnLine(-5, 0)).toBe(false);
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
it('should check if a point is on the segment of the line correctly', () => {
|
|
95
|
+
it('should check if a point is on the segment of the line correctly', (): void => {
|
|
96
96
|
const line = new Line(0, 0, 10, 10);
|
|
97
97
|
expect(line.pointOnSegment(5, -10)).toBe(false);
|
|
98
98
|
expect(line.pointOnSegment(15, 15)).toBe(false);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
it('should get the random point on the line correctly', () => {
|
|
101
|
+
it('should get the random point on the line correctly', (): void => {
|
|
102
102
|
const line = new Line(0, 0, 10, 10);
|
|
103
103
|
const result = line.random(null);
|
|
104
104
|
expect(result.x).toBeGreaterThan(0);
|
|
105
105
|
expect(result.y).toBeGreaterThan(0);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
it('should get the coordinates on the line correctly', () => {
|
|
108
|
+
it('should get the coordinates on the line correctly', (): void => {
|
|
109
109
|
const line = new Line(0, 0, 10, 10);
|
|
110
110
|
const result = line.coordinatesOnLine(1, []);
|
|
111
111
|
expect(result.length).toBeGreaterThan(0);
|
package/src/phaser/geom/line.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { clone, intersectsPoints, reflect } from './util/line.js';
|
|
|
3
3
|
import { wrap } from '../util/math.js';
|
|
4
4
|
import { GEOM_LINE } from '../core/const.js';
|
|
5
5
|
|
|
6
|
+
/** Anything a line can read a position from: a display object, a point, or a plain x/y pair. */
|
|
7
|
+
export type LineAnchor = { x: number; y: number; center?: { x: number; y: number } };
|
|
8
|
+
|
|
6
9
|
export class Line {
|
|
7
10
|
public start: Point;
|
|
8
11
|
public end: Point;
|
|
@@ -45,9 +48,9 @@ export class Line {
|
|
|
45
48
|
* @param {boolean} useCenter - Whether to use the center of the sprites (default: false).
|
|
46
49
|
* @returns {Line} This line instance for chaining.
|
|
47
50
|
*/
|
|
48
|
-
public fromSprite(startSprite:
|
|
51
|
+
public fromSprite(startSprite: LineAnchor, endSprite: LineAnchor, useCenter = false): this {
|
|
49
52
|
if (useCenter) {
|
|
50
|
-
return this.setTo(startSprite.center
|
|
53
|
+
return this.setTo(startSprite.center!.x, startSprite.center!.y, endSprite.center!.x, endSprite.center!.y);
|
|
51
54
|
}
|
|
52
55
|
return this.setTo(startSprite.x, startSprite.y, endSprite.x, endSprite.y);
|
|
53
56
|
}
|