@vpmedia/phaser 1.111.0 → 1.113.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 +1300 -1334
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +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/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +7 -6
- package/dist/phaser/display/canvas/graphics.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 +10 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +11 -9
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts +4 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- package/dist/phaser/geom/util/matrix.d.ts.map +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 +5 -4
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +54 -55
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +28 -32
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +50 -51
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +175 -154
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +58 -56
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +27 -27
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- package/src/phaser/util/math.ts +29 -46
|
@@ -5,11 +5,11 @@ import { clone, contains, circumferencePoint } from './util/circle.js';
|
|
|
5
5
|
import { GEOM_CIRCLE } from '../core/const.js';
|
|
6
6
|
|
|
7
7
|
export class Circle {
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
_diameter: number;
|
|
11
|
-
_radius: number;
|
|
12
|
-
type: number;
|
|
8
|
+
public x: number;
|
|
9
|
+
public y: number;
|
|
10
|
+
public _diameter: number;
|
|
11
|
+
public _radius: number;
|
|
12
|
+
public type: number;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates a new Circle instance.
|
|
@@ -17,7 +17,7 @@ export class Circle {
|
|
|
17
17
|
* @param {number} y - The y coordinate of the center point (default: 0).
|
|
18
18
|
* @param {number} diameter - The diameter of the circle (default: 0).
|
|
19
19
|
*/
|
|
20
|
-
constructor(x
|
|
20
|
+
public constructor(x = 0, y = 0, diameter = 0) {
|
|
21
21
|
/** @type {number} */
|
|
22
22
|
this.x = x;
|
|
23
23
|
/** @type {number} */
|
|
@@ -37,7 +37,7 @@ export class Circle {
|
|
|
37
37
|
* Calculates the circumference of this circle.
|
|
38
38
|
* @returns {number} The circumference of this circle.
|
|
39
39
|
*/
|
|
40
|
-
circumference() {
|
|
40
|
+
public circumference() {
|
|
41
41
|
return 2 * (Math.PI * this._radius);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -46,8 +46,8 @@ export class Circle {
|
|
|
46
46
|
* @param {Point} output - The point to store the result in (optional).
|
|
47
47
|
* @returns {Point} A random point within this circle.
|
|
48
48
|
*/
|
|
49
|
-
random(output: Point | null = null) {
|
|
50
|
-
const result = output
|
|
49
|
+
public random(output: Point | null = null) {
|
|
50
|
+
const result = output ?? new Point();
|
|
51
51
|
const t = 2 * Math.PI * Math.random();
|
|
52
52
|
const u = Math.random() + Math.random();
|
|
53
53
|
const r = u > 1 ? 2 - u : u;
|
|
@@ -62,7 +62,7 @@ export class Circle {
|
|
|
62
62
|
* Gets the bounding rectangle of this circle.
|
|
63
63
|
* @returns {Rectangle} The bounding rectangle of this circle.
|
|
64
64
|
*/
|
|
65
|
-
getBounds() {
|
|
65
|
+
public getBounds() {
|
|
66
66
|
return new Rectangle(this.x - this.radius, this.y - this.radius, this.diameter, this.diameter);
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -73,7 +73,7 @@ export class Circle {
|
|
|
73
73
|
* @param {number} diameter - The new diameter of the circle.
|
|
74
74
|
* @returns {Circle} This circle instance for chaining.
|
|
75
75
|
*/
|
|
76
|
-
setTo(x: number, y: number, diameter: number) {
|
|
76
|
+
public setTo(x: number, y: number, diameter: number) {
|
|
77
77
|
this.x = x;
|
|
78
78
|
this.y = y;
|
|
79
79
|
this._diameter = diameter;
|
|
@@ -86,7 +86,7 @@ export class Circle {
|
|
|
86
86
|
* @param {Circle} source - The circle to copy values from.
|
|
87
87
|
* @returns {Circle} This circle instance for chaining.
|
|
88
88
|
*/
|
|
89
|
-
copyFrom(source: Circle) {
|
|
89
|
+
public copyFrom(source: Circle) {
|
|
90
90
|
return this.setTo(source.x, source.y, source.diameter);
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -95,7 +95,7 @@ export class Circle {
|
|
|
95
95
|
* @param {Circle} dest - The circle to copy values to.
|
|
96
96
|
* @returns {Circle} The destination circle.
|
|
97
97
|
*/
|
|
98
|
-
copyTo(dest: Circle) {
|
|
98
|
+
public copyTo(dest: Circle) {
|
|
99
99
|
dest.x = this.x;
|
|
100
100
|
dest.y = this.y;
|
|
101
101
|
dest.diameter = this._diameter;
|
|
@@ -108,7 +108,7 @@ export class Circle {
|
|
|
108
108
|
* @param {boolean} round - Whether to round the result (default: false).
|
|
109
109
|
* @returns {number} The distance between the circles.
|
|
110
110
|
*/
|
|
111
|
-
distance(dest:
|
|
111
|
+
public distance(dest: { x: number; y: number }, round = false) {
|
|
112
112
|
const d = distance(this.x, this.y, dest.x, dest.y);
|
|
113
113
|
return round ? Math.round(d) : d;
|
|
114
114
|
}
|
|
@@ -117,7 +117,7 @@ export class Circle {
|
|
|
117
117
|
* Creates a clone of this circle.
|
|
118
118
|
* @returns {Circle} A new circle with the same values as this one.
|
|
119
119
|
*/
|
|
120
|
-
clone() {
|
|
120
|
+
public clone() {
|
|
121
121
|
return clone(this);
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -127,7 +127,7 @@ export class Circle {
|
|
|
127
127
|
* @param {number} y - The y coordinate of the point to check.
|
|
128
128
|
* @returns {boolean} True if the point is contained within this circle, false otherwise.
|
|
129
129
|
*/
|
|
130
|
-
contains(x: number, y: number) {
|
|
130
|
+
public contains(x: number, y: number) {
|
|
131
131
|
return contains(this, x, y);
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -138,7 +138,7 @@ export class Circle {
|
|
|
138
138
|
* @param {Point} out - The point to store the result in (optional).
|
|
139
139
|
* @returns {Point} A point at the specified angle on the circumference of this circle.
|
|
140
140
|
*/
|
|
141
|
-
circumferencePoint(angle: number, asDegrees?: boolean, out?: Point) {
|
|
141
|
+
public circumferencePoint(angle: number, asDegrees?: boolean, out?: Point) {
|
|
142
142
|
return circumferencePoint(this, angle, asDegrees, out);
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -148,7 +148,7 @@ export class Circle {
|
|
|
148
148
|
* @param {number} dy - The amount to offset the y coordinate by.
|
|
149
149
|
* @returns {Circle} This circle instance for chaining.
|
|
150
150
|
*/
|
|
151
|
-
offset(dx: number, dy: number) {
|
|
151
|
+
public offset(dx: number, dy: number) {
|
|
152
152
|
this.x += dx;
|
|
153
153
|
this.y += dy;
|
|
154
154
|
return this;
|
|
@@ -159,7 +159,7 @@ export class Circle {
|
|
|
159
159
|
* @param {Point} point - The point to offset the circle by.
|
|
160
160
|
* @returns {Circle} This circle instance for chaining.
|
|
161
161
|
*/
|
|
162
|
-
offsetPoint(point: Point) {
|
|
162
|
+
public offsetPoint(point: Point) {
|
|
163
163
|
return this.offset(point.x, point.y);
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -167,7 +167,7 @@ export class Circle {
|
|
|
167
167
|
* Returns a string representation of this circle.
|
|
168
168
|
* @returns {string} A string representation of the circle.
|
|
169
169
|
*/
|
|
170
|
-
toString() {
|
|
170
|
+
public toString() {
|
|
171
171
|
return `[{Circle (x=${this.x} y=${this.y} diameter=${this.diameter} radius=${this.radius})}]`;
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -175,14 +175,14 @@ export class Circle {
|
|
|
175
175
|
* Gets the diameter of this circle.
|
|
176
176
|
* @returns {number} The diameter of this circle.
|
|
177
177
|
*/
|
|
178
|
-
get diameter() {
|
|
178
|
+
public get diameter() {
|
|
179
179
|
return this._diameter;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
183
|
* Sets the diameter of this circle.
|
|
184
184
|
*/
|
|
185
|
-
set diameter(value) {
|
|
185
|
+
public set diameter(value) {
|
|
186
186
|
if (value > 0) {
|
|
187
187
|
this._diameter = value;
|
|
188
188
|
this._radius = value * 0.5;
|
|
@@ -193,14 +193,14 @@ export class Circle {
|
|
|
193
193
|
* Gets the radius of this circle.
|
|
194
194
|
* @returns {number} The radius of this circle.
|
|
195
195
|
*/
|
|
196
|
-
get radius() {
|
|
196
|
+
public get radius() {
|
|
197
197
|
return this._radius;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
201
|
* Sets the radius of this circle.
|
|
202
202
|
*/
|
|
203
|
-
set radius(value) {
|
|
203
|
+
public set radius(value) {
|
|
204
204
|
if (value > 0) {
|
|
205
205
|
this._radius = value;
|
|
206
206
|
this._diameter = value * 2;
|
|
@@ -211,14 +211,14 @@ export class Circle {
|
|
|
211
211
|
* Gets the left coordinate of this circle.
|
|
212
212
|
* @returns {number} The left coordinate of this circle.
|
|
213
213
|
*/
|
|
214
|
-
get left() {
|
|
214
|
+
public get left() {
|
|
215
215
|
return this.x - this._radius;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
219
|
* Sets the left coordinate of this circle.
|
|
220
220
|
*/
|
|
221
|
-
set left(value) {
|
|
221
|
+
public set left(value) {
|
|
222
222
|
if (value > this.x) {
|
|
223
223
|
this._radius = 0;
|
|
224
224
|
this._diameter = 0;
|
|
@@ -231,14 +231,14 @@ export class Circle {
|
|
|
231
231
|
* Gets the right coordinate of this circle.
|
|
232
232
|
* @returns {number} The right coordinate of this circle.
|
|
233
233
|
*/
|
|
234
|
-
get right() {
|
|
234
|
+
public get right() {
|
|
235
235
|
return this.x + this._radius;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
239
|
* Sets the right coordinate of this circle.
|
|
240
240
|
*/
|
|
241
|
-
set right(value) {
|
|
241
|
+
public set right(value) {
|
|
242
242
|
if (value < this.x) {
|
|
243
243
|
this._radius = 0;
|
|
244
244
|
this._diameter = 0;
|
|
@@ -251,14 +251,14 @@ export class Circle {
|
|
|
251
251
|
* Gets the top coordinate of this circle.
|
|
252
252
|
* @returns {number} The top coordinate of this circle.
|
|
253
253
|
*/
|
|
254
|
-
get top() {
|
|
254
|
+
public get top() {
|
|
255
255
|
return this.y - this._radius;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
/**
|
|
259
259
|
* Sets the top coordinate of this circle.
|
|
260
260
|
*/
|
|
261
|
-
set top(value) {
|
|
261
|
+
public set top(value) {
|
|
262
262
|
if (value > this.y) {
|
|
263
263
|
this._radius = 0;
|
|
264
264
|
this._diameter = 0;
|
|
@@ -271,14 +271,14 @@ export class Circle {
|
|
|
271
271
|
* Gets the bottom coordinate of this circle.
|
|
272
272
|
* @returns {number} The bottom coordinate of this circle.
|
|
273
273
|
*/
|
|
274
|
-
get bottom() {
|
|
274
|
+
public get bottom() {
|
|
275
275
|
return this.y + this._radius;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
/**
|
|
279
279
|
* Sets the bottom coordinate of this circle.
|
|
280
280
|
*/
|
|
281
|
-
set bottom(value) {
|
|
281
|
+
public set bottom(value) {
|
|
282
282
|
if (value < this.y) {
|
|
283
283
|
this._radius = 0;
|
|
284
284
|
this._diameter = 0;
|
|
@@ -291,7 +291,7 @@ export class Circle {
|
|
|
291
291
|
* Gets the area of this circle.
|
|
292
292
|
* @returns {number} The area of this circle.
|
|
293
293
|
*/
|
|
294
|
-
get area() {
|
|
294
|
+
public get area() {
|
|
295
295
|
if (this._radius > 0) {
|
|
296
296
|
return Math.PI * this._radius * this._radius;
|
|
297
297
|
}
|
|
@@ -302,15 +302,15 @@ export class Circle {
|
|
|
302
302
|
* Checks if this circle is empty (has zero diameter).
|
|
303
303
|
* @returns {boolean} True if the circle is empty, false otherwise.
|
|
304
304
|
*/
|
|
305
|
-
get empty() {
|
|
305
|
+
public get empty() {
|
|
306
306
|
return this._diameter === 0;
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
/**
|
|
310
310
|
* Sets whether this circle is empty (zero diameter).
|
|
311
311
|
*/
|
|
312
|
-
set empty(value) {
|
|
313
|
-
if (value
|
|
312
|
+
public set empty(value) {
|
|
313
|
+
if (value) {
|
|
314
314
|
this.setTo(0, 0, 0);
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -1,84 +1,86 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { Ellipse } from './ellipse.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
describe('Ellipse', () => {
|
|
5
|
+
it('should create an ellipse with default values', () => {
|
|
6
|
+
const ellipse = new Ellipse();
|
|
7
|
+
expect(ellipse.x).toBe(0);
|
|
8
|
+
expect(ellipse.y).toBe(0);
|
|
9
|
+
expect(ellipse.width).toBe(0);
|
|
10
|
+
expect(ellipse.height).toBe(0);
|
|
11
|
+
});
|
|
11
12
|
|
|
12
|
-
it('should create an ellipse with custom x, y, width, height', () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
13
|
+
it('should create an ellipse with custom x, y, width, height', () => {
|
|
14
|
+
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
15
|
+
expect(ellipse.x).toBe(10);
|
|
16
|
+
expect(ellipse.y).toBe(20);
|
|
17
|
+
expect(ellipse.width).toBe(30);
|
|
18
|
+
expect(ellipse.height).toBe(40);
|
|
19
|
+
});
|
|
19
20
|
|
|
20
|
-
it('should set the ellipse values to new x, y, width, height', () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
21
|
+
it('should set the ellipse values to new x, y, width, height', () => {
|
|
22
|
+
const ellipse = new Ellipse();
|
|
23
|
+
ellipse.setTo(10, 20, 30, 40);
|
|
24
|
+
expect(ellipse.x).toBe(10);
|
|
25
|
+
expect(ellipse.y).toBe(20);
|
|
26
|
+
expect(ellipse.width).toBe(30);
|
|
27
|
+
expect(ellipse.height).toBe(40);
|
|
28
|
+
});
|
|
28
29
|
|
|
29
|
-
it('should return the ellipse instance', () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
30
|
+
it('should return the ellipse instance', () => {
|
|
31
|
+
const ellipse = new Ellipse();
|
|
32
|
+
const result = ellipse.setTo(10, 20, 30, 40);
|
|
33
|
+
expect(result).toBe(ellipse);
|
|
34
|
+
});
|
|
34
35
|
|
|
35
|
-
it('should create a rectangle with correct bounds', () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
36
|
+
it('should create a rectangle with correct bounds', () => {
|
|
37
|
+
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
38
|
+
const bounds = ellipse.getBounds();
|
|
39
|
+
expect(bounds.x).toBe(10 - 30);
|
|
40
|
+
expect(bounds.y).toBe(20 - 40);
|
|
41
|
+
expect(bounds.width).toBe(30);
|
|
42
|
+
expect(bounds.height).toBe(40);
|
|
43
|
+
});
|
|
43
44
|
|
|
44
|
-
it('should copy the values from another ellipse', () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
45
|
+
it('should copy the values from another ellipse', () => {
|
|
46
|
+
const source = new Ellipse(10, 20, 30, 40);
|
|
47
|
+
const target = new Ellipse();
|
|
48
|
+
target.copyFrom(source);
|
|
49
|
+
expect(target.x).toBe(source.x);
|
|
50
|
+
expect(target.y).toBe(source.y);
|
|
51
|
+
expect(target.width).toBe(source.width);
|
|
52
|
+
expect(target.height).toBe(source.height);
|
|
53
|
+
});
|
|
53
54
|
|
|
54
|
-
it('should copy the values to another ellipse', () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
55
|
+
it('should copy the values to another ellipse', () => {
|
|
56
|
+
const source = new Ellipse(10, 20, 30, 40);
|
|
57
|
+
const target = new Ellipse();
|
|
58
|
+
source.copyTo(target);
|
|
59
|
+
expect(target.x).toBe(source.x);
|
|
60
|
+
expect(target.y).toBe(source.y);
|
|
61
|
+
expect(target.width).toBe(source.width);
|
|
62
|
+
expect(target.height).toBe(source.height);
|
|
63
|
+
});
|
|
63
64
|
|
|
64
|
-
it('should return true if point is inside the ellipse', () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
65
|
+
it('should return true if point is inside the ellipse', () => {
|
|
66
|
+
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
67
|
+
expect(ellipse.contains(20, 30)).toBe(true);
|
|
68
|
+
});
|
|
68
69
|
|
|
69
|
-
it('should return false if point is outside the ellipse', () => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
70
|
+
it('should return false if point is outside the ellipse', () => {
|
|
71
|
+
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
72
|
+
expect(ellipse.contains(-5, -10)).toBe(false);
|
|
73
|
+
});
|
|
73
74
|
|
|
74
|
-
it('should generate a random point within the ellipse', () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
75
|
+
it('should generate a random point within the ellipse', () => {
|
|
76
|
+
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
77
|
+
const point = ellipse.random();
|
|
78
|
+
expect(point.x).toBeTypeOf('number');
|
|
79
|
+
expect(point.y).toBeTypeOf('number');
|
|
80
|
+
});
|
|
80
81
|
|
|
81
|
-
it('should return a string representation of the ellipse', () => {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
it('should return a string representation of the ellipse', () => {
|
|
83
|
+
const ellipse = new Ellipse(10, 20, 30, 40);
|
|
84
|
+
expect(ellipse.toString()).toBe('[{Ellipse (x=10 y=20 width=30 height=40)}]');
|
|
85
|
+
});
|
|
84
86
|
});
|
|
@@ -4,11 +4,11 @@ import { Rectangle } from './rectangle.js';
|
|
|
4
4
|
import { contains } from './util/ellipse.js';
|
|
5
5
|
|
|
6
6
|
export class Ellipse {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
width: number;
|
|
10
|
-
height: number;
|
|
11
|
-
type: number;
|
|
7
|
+
public x: number;
|
|
8
|
+
public y: number;
|
|
9
|
+
public width: number;
|
|
10
|
+
public height: number;
|
|
11
|
+
public type: number;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a new Ellipse instance.
|
|
@@ -17,7 +17,7 @@ export class Ellipse {
|
|
|
17
17
|
* @param {number} width - The width of the ellipse (default: 0).
|
|
18
18
|
* @param {number} height - The height of the ellipse (default: 0).
|
|
19
19
|
*/
|
|
20
|
-
constructor(x
|
|
20
|
+
public constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
21
21
|
/** @type {number} */
|
|
22
22
|
this.x = x;
|
|
23
23
|
/** @type {number} */
|
|
@@ -38,7 +38,7 @@ export class Ellipse {
|
|
|
38
38
|
* @param {number} height - The new height of the ellipse.
|
|
39
39
|
* @returns {Ellipse} This ellipse instance for chaining.
|
|
40
40
|
*/
|
|
41
|
-
setTo(x: number, y: number, width: number, height: number) {
|
|
41
|
+
public setTo(x: number, y: number, width: number, height: number) {
|
|
42
42
|
this.x = x;
|
|
43
43
|
this.y = y;
|
|
44
44
|
this.width = width;
|
|
@@ -50,7 +50,7 @@ export class Ellipse {
|
|
|
50
50
|
* Gets the bounding rectangle of this ellipse.
|
|
51
51
|
* @returns {Rectangle} The bounding rectangle of this ellipse.
|
|
52
52
|
*/
|
|
53
|
-
getBounds() {
|
|
53
|
+
public getBounds() {
|
|
54
54
|
return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -59,7 +59,7 @@ export class Ellipse {
|
|
|
59
59
|
* @param {Ellipse} source - The ellipse to copy values from.
|
|
60
60
|
* @returns {Ellipse} This ellipse instance for chaining.
|
|
61
61
|
*/
|
|
62
|
-
copyFrom(source: Ellipse) {
|
|
62
|
+
public copyFrom(source: Ellipse) {
|
|
63
63
|
return this.setTo(source.x, source.y, source.width, source.height);
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -68,7 +68,7 @@ export class Ellipse {
|
|
|
68
68
|
* @param {Ellipse} dest - The ellipse to copy values to.
|
|
69
69
|
* @returns {Ellipse} The destination ellipse.
|
|
70
70
|
*/
|
|
71
|
-
copyTo(dest: Ellipse) {
|
|
71
|
+
public copyTo(dest: Ellipse) {
|
|
72
72
|
dest.x = this.x;
|
|
73
73
|
dest.y = this.y;
|
|
74
74
|
dest.width = this.width;
|
|
@@ -82,7 +82,7 @@ export class Ellipse {
|
|
|
82
82
|
* @param {number} y - The y coordinate of the point to check.
|
|
83
83
|
* @returns {boolean} True if the point is contained within this ellipse, false otherwise.
|
|
84
84
|
*/
|
|
85
|
-
contains(x: number, y: number) {
|
|
85
|
+
public contains(x: number, y: number) {
|
|
86
86
|
return contains(this, x, y);
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -91,8 +91,8 @@ export class Ellipse {
|
|
|
91
91
|
* @param {Point} output - The point to store the result in (optional).
|
|
92
92
|
* @returns {Point} A random point within this ellipse.
|
|
93
93
|
*/
|
|
94
|
-
random(output: Point | null = null) {
|
|
95
|
-
const result = output
|
|
94
|
+
public random(output: Point | null = null) {
|
|
95
|
+
const result = output ?? new Point();
|
|
96
96
|
const p = Math.random() * Math.PI * 2;
|
|
97
97
|
const r = Math.random();
|
|
98
98
|
result.x = Math.sqrt(r) * Math.cos(p);
|
|
@@ -106,7 +106,7 @@ export class Ellipse {
|
|
|
106
106
|
* Returns a string representation of this ellipse.
|
|
107
107
|
* @returns {string} A string representation of the ellipse.
|
|
108
108
|
*/
|
|
109
|
-
toString() {
|
|
109
|
+
public toString() {
|
|
110
110
|
return `[{Ellipse (x=${this.x} y=${this.y} width=${this.width} height=${this.height})}]`;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
1
|
+
import { expect, describe, it } from 'vitest';
|
|
2
2
|
import { degToRad } from '../util/math.js';
|
|
3
3
|
import { Line } from './line.js';
|
|
4
4
|
|
|
@@ -62,7 +62,7 @@ describe('Line', () => {
|
|
|
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
|
-
expect(result).
|
|
65
|
+
expect(result).toBeNull();
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it('should reflect the line across another line correctly', () => {
|
|
@@ -81,7 +81,7 @@ describe('Line', () => {
|
|
|
81
81
|
|
|
82
82
|
it('should center the line on a point correctly', () => {
|
|
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
|
});
|
|
@@ -101,8 +101,8 @@ describe('Line', () => {
|
|
|
101
101
|
it('should get the random point on the line correctly', () => {
|
|
102
102
|
const line = new Line(0, 0, 10, 10);
|
|
103
103
|
const result = line.random(null);
|
|
104
|
-
expect(result.x
|
|
105
|
-
expect(result.y
|
|
104
|
+
expect(result.x).toBeGreaterThan(0);
|
|
105
|
+
expect(result.y).toBeGreaterThan(0);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
it('should get the coordinates on the line correctly', () => {
|