@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
package/src/phaser/geom/line.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { wrap } from '../util/math.js';
|
|
|
4
4
|
import { GEOM_LINE } from '../core/const.js';
|
|
5
5
|
|
|
6
6
|
export class Line {
|
|
7
|
-
start: Point;
|
|
8
|
-
end: Point;
|
|
9
|
-
type: number;
|
|
7
|
+
public start: Point;
|
|
8
|
+
public end: Point;
|
|
9
|
+
public type: number;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new Line instance.
|
|
@@ -15,7 +15,7 @@ export class Line {
|
|
|
15
15
|
* @param {number} x2 - The x coordinate of the end point (default: 0).
|
|
16
16
|
* @param {number} y2 - The y coordinate of the end point (default: 0).
|
|
17
17
|
*/
|
|
18
|
-
constructor(x1
|
|
18
|
+
public constructor(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
|
|
19
19
|
/** @type {Point} */
|
|
20
20
|
this.start = new Point(x1, y1);
|
|
21
21
|
/** @type {Point} */
|
|
@@ -32,7 +32,7 @@ export class Line {
|
|
|
32
32
|
* @param {number} y2 - The new y coordinate of the end point.
|
|
33
33
|
* @returns {Line} This line instance for chaining.
|
|
34
34
|
*/
|
|
35
|
-
setTo(x1: number, y1: number, x2: number, y2: number) {
|
|
35
|
+
public setTo(x1: number, y1: number, x2: number, y2: number) {
|
|
36
36
|
this.start.setTo(x1, y1);
|
|
37
37
|
this.end.setTo(x2, y2);
|
|
38
38
|
return this;
|
|
@@ -45,7 +45,7 @@ export class Line {
|
|
|
45
45
|
* @param {boolean} useCenter - Whether to use the center of the sprites (default: false).
|
|
46
46
|
* @returns {Line} This line instance for chaining.
|
|
47
47
|
*/
|
|
48
|
-
fromSprite(startSprite: any, endSprite: any, useCenter
|
|
48
|
+
public fromSprite(startSprite: any, endSprite: any, useCenter = false) {
|
|
49
49
|
if (useCenter) {
|
|
50
50
|
return this.setTo(startSprite.center.x, startSprite.center.y, endSprite.center.x, endSprite.center.y);
|
|
51
51
|
}
|
|
@@ -60,7 +60,7 @@ export class Line {
|
|
|
60
60
|
* @param {number} length - The length of the line.
|
|
61
61
|
* @returns {Line} This line instance for chaining.
|
|
62
62
|
*/
|
|
63
|
-
fromAngle(x: number, y: number, angle: number, length: number) {
|
|
63
|
+
public fromAngle(x: number, y: number, angle: number, length: number) {
|
|
64
64
|
this.start.setTo(x, y);
|
|
65
65
|
this.end.setTo(x + Math.cos(angle) * length, y + Math.sin(angle) * length);
|
|
66
66
|
return this;
|
|
@@ -72,7 +72,7 @@ export class Line {
|
|
|
72
72
|
* @param {boolean} asDegrees - Whether the angle is provided in degrees (default: false).
|
|
73
73
|
* @returns {Line} This line instance for chaining.
|
|
74
74
|
*/
|
|
75
|
-
rotate(angle: number, asDegrees
|
|
75
|
+
public rotate(angle: number, asDegrees = false) {
|
|
76
76
|
const cx = (this.start.x + this.end.x) / 2;
|
|
77
77
|
const cy = (this.start.y + this.end.y) / 2;
|
|
78
78
|
this.start.rotate(cx, cy, angle, asDegrees);
|
|
@@ -88,7 +88,7 @@ export class Line {
|
|
|
88
88
|
* @param {boolean} asDegrees - Whether the angle is provided in degrees (default: false).
|
|
89
89
|
* @returns {Line} This line instance for chaining.
|
|
90
90
|
*/
|
|
91
|
-
rotateAround(x: number, y: number, angle: number, asDegrees
|
|
91
|
+
public rotateAround(x: number, y: number, angle: number, asDegrees = false) {
|
|
92
92
|
this.start.rotate(x, y, angle, asDegrees);
|
|
93
93
|
this.end.rotate(x, y, angle, asDegrees);
|
|
94
94
|
return this;
|
|
@@ -101,7 +101,7 @@ export class Line {
|
|
|
101
101
|
* @param {Point} result - The point to store the intersection in (optional).
|
|
102
102
|
* @returns {Point} The intersection point, or null if no intersection occurs.
|
|
103
103
|
*/
|
|
104
|
-
intersects(line: Line, asSegment
|
|
104
|
+
public intersects(line: Line, asSegment = true, result: Point | null = null) {
|
|
105
105
|
return intersectsPoints(this.start, this.end, line.start, line.end, asSegment, result);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -110,7 +110,7 @@ export class Line {
|
|
|
110
110
|
* @param {Line} line - The line to reflect off.
|
|
111
111
|
* @returns {number} The angle of reflection in radians.
|
|
112
112
|
*/
|
|
113
|
-
reflect(line: Line) {
|
|
113
|
+
public reflect(line: Line) {
|
|
114
114
|
return reflect(this, line);
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -119,8 +119,8 @@ export class Line {
|
|
|
119
119
|
* @param {Point} output - The point to store the result in (optional).
|
|
120
120
|
* @returns {Point} The midpoint of this line.
|
|
121
121
|
*/
|
|
122
|
-
midPoint(output: Point | null = null) {
|
|
123
|
-
const result = output
|
|
122
|
+
public midPoint(output: Point | null = null) {
|
|
123
|
+
const result = output ?? new Point();
|
|
124
124
|
result.x = (this.start.x + this.end.x) / 2;
|
|
125
125
|
result.y = (this.start.y + this.end.y) / 2;
|
|
126
126
|
return result;
|
|
@@ -131,7 +131,7 @@ export class Line {
|
|
|
131
131
|
* @param {number} x - The x coordinate to center the line on.
|
|
132
132
|
* @param {number} y - The y coordinate to center the line on.
|
|
133
133
|
*/
|
|
134
|
-
centerOn(x: number, y: number) {
|
|
134
|
+
public centerOn(x: number, y: number) {
|
|
135
135
|
const cx = (this.start.x + this.end.x) / 2;
|
|
136
136
|
const cy = (this.start.y + this.end.y) / 2;
|
|
137
137
|
const tx = x - cx;
|
|
@@ -146,7 +146,7 @@ export class Line {
|
|
|
146
146
|
* @param {number} y - The y coordinate of the point to check.
|
|
147
147
|
* @returns {boolean} True if the point lies on this line, false otherwise.
|
|
148
148
|
*/
|
|
149
|
-
pointOnLine(x: number, y: number) {
|
|
149
|
+
public pointOnLine(x: number, y: number) {
|
|
150
150
|
return (x - this.start.x) * (this.end.y - this.start.y) === (this.end.x - this.start.x) * (y - this.start.y);
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -156,7 +156,7 @@ export class Line {
|
|
|
156
156
|
* @param {number} y - The y coordinate of the point to check.
|
|
157
157
|
* @returns {boolean} True if the point lies on this line segment, false otherwise.
|
|
158
158
|
*/
|
|
159
|
-
pointOnSegment(x: number, y: number) {
|
|
159
|
+
public pointOnSegment(x: number, y: number) {
|
|
160
160
|
const xMin = Math.min(this.start.x, this.end.x);
|
|
161
161
|
const xMax = Math.max(this.start.x, this.end.x);
|
|
162
162
|
const yMin = Math.min(this.start.y, this.end.y);
|
|
@@ -169,8 +169,8 @@ export class Line {
|
|
|
169
169
|
* @param {Point} output - The point to store the result in (optional).
|
|
170
170
|
* @returns {Point} A random point on this line.
|
|
171
171
|
*/
|
|
172
|
-
random(output: Point | null = null) {
|
|
173
|
-
const result = output
|
|
172
|
+
public random(output: Point | null = null) {
|
|
173
|
+
const result = output ?? new Point();
|
|
174
174
|
const t = Math.random();
|
|
175
175
|
result.x = this.start.x + t * (this.end.x - this.start.x);
|
|
176
176
|
result.y = this.start.y + t * (this.end.y - this.start.y);
|
|
@@ -183,7 +183,7 @@ export class Line {
|
|
|
183
183
|
* @param {number[][]} results - The array to store the results in (optional).
|
|
184
184
|
* @returns {number[][]} An array of coordinate pairs representing points along this line.
|
|
185
185
|
*/
|
|
186
|
-
coordinatesOnLine(stepRate
|
|
186
|
+
public coordinatesOnLine(stepRate = 1, results: number[][] = []) {
|
|
187
187
|
let x1 = Math.round(this.start.x);
|
|
188
188
|
let y1 = Math.round(this.start.y);
|
|
189
189
|
const x2 = Math.round(this.end.x);
|
|
@@ -217,7 +217,7 @@ export class Line {
|
|
|
217
217
|
* Creates a clone of this line.
|
|
218
218
|
* @returns {Line} A new line with the same values as this one.
|
|
219
219
|
*/
|
|
220
|
-
clone() {
|
|
220
|
+
public clone() {
|
|
221
221
|
return clone(this);
|
|
222
222
|
}
|
|
223
223
|
|
|
@@ -225,7 +225,7 @@ export class Line {
|
|
|
225
225
|
* Gets the length of this line.
|
|
226
226
|
* @returns {number} The length of this line.
|
|
227
227
|
*/
|
|
228
|
-
get length() {
|
|
228
|
+
public get length() {
|
|
229
229
|
return Math.sqrt(
|
|
230
230
|
(this.end.x - this.start.x) * (this.end.x - this.start.x) +
|
|
231
231
|
(this.end.y - this.start.y) * (this.end.y - this.start.y)
|
|
@@ -236,7 +236,7 @@ export class Line {
|
|
|
236
236
|
* Gets the angle of this line in radians.
|
|
237
237
|
* @returns {number} The angle of this line in radians.
|
|
238
238
|
*/
|
|
239
|
-
get angle() {
|
|
239
|
+
public get angle() {
|
|
240
240
|
return Math.atan2(this.end.y - this.start.y, this.end.x - this.start.x);
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -244,7 +244,7 @@ export class Line {
|
|
|
244
244
|
* Gets the slope of this line.
|
|
245
245
|
* @returns {number} The slope of this line.
|
|
246
246
|
*/
|
|
247
|
-
get slope() {
|
|
247
|
+
public get slope() {
|
|
248
248
|
return (this.end.y - this.start.y) / (this.end.x - this.start.x);
|
|
249
249
|
}
|
|
250
250
|
|
|
@@ -252,7 +252,7 @@ export class Line {
|
|
|
252
252
|
* Gets the perpendicular slope of this line.
|
|
253
253
|
* @returns {number} The perpendicular slope of this line.
|
|
254
254
|
*/
|
|
255
|
-
get perpSlope() {
|
|
255
|
+
public get perpSlope() {
|
|
256
256
|
return -((this.end.x - this.start.x) / (this.end.y - this.start.y));
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -260,7 +260,7 @@ export class Line {
|
|
|
260
260
|
* Gets the x coordinate of the leftmost point on this line.
|
|
261
261
|
* @returns {number} The x coordinate of the leftmost point on this line.
|
|
262
262
|
*/
|
|
263
|
-
get x() {
|
|
263
|
+
public get x() {
|
|
264
264
|
return Math.min(this.start.x, this.end.x);
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -268,7 +268,7 @@ export class Line {
|
|
|
268
268
|
* Gets the y coordinate of the topmost point on this line.
|
|
269
269
|
* @returns {number} The y coordinate of the topmost point on this line.
|
|
270
270
|
*/
|
|
271
|
-
get y() {
|
|
271
|
+
public get y() {
|
|
272
272
|
return Math.min(this.start.y, this.end.y);
|
|
273
273
|
}
|
|
274
274
|
|
|
@@ -276,7 +276,7 @@ export class Line {
|
|
|
276
276
|
* Gets the x coordinate of the leftmost point on this line.
|
|
277
277
|
* @returns {number} The x coordinate of the leftmost point on this line.
|
|
278
278
|
*/
|
|
279
|
-
get left() {
|
|
279
|
+
public get left() {
|
|
280
280
|
return Math.min(this.start.x, this.end.x);
|
|
281
281
|
}
|
|
282
282
|
|
|
@@ -284,7 +284,7 @@ export class Line {
|
|
|
284
284
|
* Gets the x coordinate of the rightmost point on this line.
|
|
285
285
|
* @returns {number} The x coordinate of the rightmost point on this line.
|
|
286
286
|
*/
|
|
287
|
-
get right() {
|
|
287
|
+
public get right() {
|
|
288
288
|
return Math.max(this.start.x, this.end.x);
|
|
289
289
|
}
|
|
290
290
|
|
|
@@ -292,7 +292,7 @@ export class Line {
|
|
|
292
292
|
* Gets the y coordinate of the topmost point on this line.
|
|
293
293
|
* @returns {number} The y coordinate of the topmost point on this line.
|
|
294
294
|
*/
|
|
295
|
-
get top() {
|
|
295
|
+
public get top() {
|
|
296
296
|
return Math.min(this.start.y, this.end.y);
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -300,7 +300,7 @@ export class Line {
|
|
|
300
300
|
* Gets the y coordinate of the bottommost point on this line.
|
|
301
301
|
* @returns {number} The y coordinate of the bottommost point on this line.
|
|
302
302
|
*/
|
|
303
|
-
get bottom() {
|
|
303
|
+
public get bottom() {
|
|
304
304
|
return Math.max(this.start.y, this.end.y);
|
|
305
305
|
}
|
|
306
306
|
|
|
@@ -308,7 +308,7 @@ export class Line {
|
|
|
308
308
|
* Gets the width of this line (absolute difference between x coordinates).
|
|
309
309
|
* @returns {number} The width of this line.
|
|
310
310
|
*/
|
|
311
|
-
get width() {
|
|
311
|
+
public get width() {
|
|
312
312
|
return Math.abs(this.start.x - this.end.x);
|
|
313
313
|
}
|
|
314
314
|
|
|
@@ -316,7 +316,7 @@ export class Line {
|
|
|
316
316
|
* Gets the height of this line (absolute difference between y coordinates).
|
|
317
317
|
* @returns {number} The height of this line.
|
|
318
318
|
*/
|
|
319
|
-
get height() {
|
|
319
|
+
public get height() {
|
|
320
320
|
return Math.abs(this.start.y - this.end.y);
|
|
321
321
|
}
|
|
322
322
|
|
|
@@ -324,7 +324,7 @@ export class Line {
|
|
|
324
324
|
* Gets the normal vector x component of this line (perpendicular to the line).
|
|
325
325
|
* @returns {number} The normal vector x component of this line.
|
|
326
326
|
*/
|
|
327
|
-
get normalX() {
|
|
327
|
+
public get normalX() {
|
|
328
328
|
return Math.cos(this.angle - 1.5707963267948966);
|
|
329
329
|
}
|
|
330
330
|
|
|
@@ -332,7 +332,7 @@ export class Line {
|
|
|
332
332
|
* Gets the normal vector y component of this line (perpendicular to the line).
|
|
333
333
|
* @returns {number} The normal vector y component of this line.
|
|
334
334
|
*/
|
|
335
|
-
get normalY() {
|
|
335
|
+
public get normalY() {
|
|
336
336
|
return Math.sin(this.angle - 1.5707963267948966);
|
|
337
337
|
}
|
|
338
338
|
|
|
@@ -340,7 +340,7 @@ export class Line {
|
|
|
340
340
|
* Gets the angle of the normal vector of this line in radians.
|
|
341
341
|
* @returns {number} The angle of the normal vector of this line in radians.
|
|
342
342
|
*/
|
|
343
|
-
get normalAngle() {
|
|
343
|
+
public get normalAngle() {
|
|
344
344
|
return wrap(this.angle - 1.5707963267948966, -Math.PI, Math.PI);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
@@ -3,13 +3,13 @@ import { clone } from './util/matrix.js';
|
|
|
3
3
|
import { GEOM_MATRIX } from '../core/const.js';
|
|
4
4
|
|
|
5
5
|
export class Matrix {
|
|
6
|
-
a: number;
|
|
7
|
-
b: number;
|
|
8
|
-
c: number;
|
|
9
|
-
d: number;
|
|
10
|
-
tx: number;
|
|
11
|
-
ty: number;
|
|
12
|
-
type: number;
|
|
6
|
+
public a: number;
|
|
7
|
+
public b: number;
|
|
8
|
+
public c: number;
|
|
9
|
+
public d: number;
|
|
10
|
+
public tx: number;
|
|
11
|
+
public ty: number;
|
|
12
|
+
public type: number;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates a new Matrix instance.
|
|
@@ -20,7 +20,7 @@ export class Matrix {
|
|
|
20
20
|
* @param {number} tx - The tx component of the matrix (default: 0).
|
|
21
21
|
* @param {number} ty - The ty component of the matrix (default: 0).
|
|
22
22
|
*/
|
|
23
|
-
constructor(a
|
|
23
|
+
public constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
|
|
24
24
|
/** @type {number} */
|
|
25
25
|
this.a = a;
|
|
26
26
|
/** @type {number} */
|
|
@@ -42,8 +42,8 @@ export class Matrix {
|
|
|
42
42
|
* @param {number[]} array - The array to read the matrix components from (should have 6 elements).
|
|
43
43
|
* @returns {Matrix} This matrix instance for chaining.
|
|
44
44
|
*/
|
|
45
|
-
fromArray(array: number[]) {
|
|
46
|
-
return this.setTo(array[0]
|
|
45
|
+
public fromArray(array: number[]) {
|
|
46
|
+
return this.setTo(array[0]!, array[1]!, array[3]!, array[4]!, array[2]!, array[5]!);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -56,7 +56,7 @@ export class Matrix {
|
|
|
56
56
|
* @param {number} ty - The new ty component of the matrix.
|
|
57
57
|
* @returns {Matrix} This matrix instance for chaining.
|
|
58
58
|
*/
|
|
59
|
-
setTo(a: number, b: number, c: number, d: number, tx: number, ty: number) {
|
|
59
|
+
public setTo(a: number, b: number, c: number, d: number, tx: number, ty: number) {
|
|
60
60
|
this.a = a;
|
|
61
61
|
this.b = b;
|
|
62
62
|
this.c = c;
|
|
@@ -70,7 +70,7 @@ export class Matrix {
|
|
|
70
70
|
* Creates a clone of this matrix.
|
|
71
71
|
* @returns {Matrix} A new matrix with the same values as this one.
|
|
72
72
|
*/
|
|
73
|
-
clone() {
|
|
73
|
+
public clone() {
|
|
74
74
|
return clone(this);
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -79,7 +79,7 @@ export class Matrix {
|
|
|
79
79
|
* @param {Matrix} matrix - The matrix to copy values to.
|
|
80
80
|
* @returns {Matrix} The destination matrix.
|
|
81
81
|
*/
|
|
82
|
-
copyTo(matrix: Matrix) {
|
|
82
|
+
public copyTo(matrix: Matrix) {
|
|
83
83
|
matrix.copyFrom(this);
|
|
84
84
|
return matrix;
|
|
85
85
|
}
|
|
@@ -89,7 +89,7 @@ export class Matrix {
|
|
|
89
89
|
* @param {Matrix} matrix - The matrix to copy values from.
|
|
90
90
|
* @returns {Matrix} This matrix instance for chaining.
|
|
91
91
|
*/
|
|
92
|
-
copyFrom(matrix: Matrix) {
|
|
92
|
+
public copyFrom(matrix: Matrix) {
|
|
93
93
|
this.a = matrix.a;
|
|
94
94
|
this.b = matrix.b;
|
|
95
95
|
this.c = matrix.c;
|
|
@@ -105,8 +105,8 @@ export class Matrix {
|
|
|
105
105
|
* @param {Float32Array} output - The array to store the result in (optional).
|
|
106
106
|
* @returns {Float32Array} A Float32Array containing the matrix elements.
|
|
107
107
|
*/
|
|
108
|
-
toArray(transpose
|
|
109
|
-
const result = output
|
|
108
|
+
public toArray(transpose = false, output: Float32Array | null = null) {
|
|
109
|
+
const result = output ?? new Float32Array(9);
|
|
110
110
|
if (transpose) {
|
|
111
111
|
result[0] = this.a;
|
|
112
112
|
result[1] = this.b;
|
|
@@ -137,8 +137,8 @@ export class Matrix {
|
|
|
137
137
|
* @param {Point} output - The point to store the result in (optional).
|
|
138
138
|
* @returns {Point} The transformed point.
|
|
139
139
|
*/
|
|
140
|
-
apply(pos: Point, output: Point | null = null) {
|
|
141
|
-
const result = output
|
|
140
|
+
public apply(pos: Point, output: Point | null = null) {
|
|
141
|
+
const result = output ?? new Point();
|
|
142
142
|
result.x = this.a * pos.x + this.c * pos.y + this.tx;
|
|
143
143
|
result.y = this.b * pos.x + this.d * pos.y + this.ty;
|
|
144
144
|
return result;
|
|
@@ -150,11 +150,11 @@ export class Matrix {
|
|
|
150
150
|
* @param {Point} output - The point to store the result in (optional).
|
|
151
151
|
* @returns {Point} The transformed point.
|
|
152
152
|
*/
|
|
153
|
-
applyInverse(pos: Point, output: Point | null = null) {
|
|
154
|
-
const result = output
|
|
153
|
+
public applyInverse(pos: Point, output: Point | null = null) {
|
|
154
|
+
const result = output ?? new Point();
|
|
155
155
|
const id = 1 / (this.a * this.d + this.c * -this.b);
|
|
156
|
-
const x = pos
|
|
157
|
-
const y = pos
|
|
156
|
+
const { x } = pos;
|
|
157
|
+
const { y } = pos;
|
|
158
158
|
result.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id;
|
|
159
159
|
result.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id;
|
|
160
160
|
return result;
|
|
@@ -166,7 +166,7 @@ export class Matrix {
|
|
|
166
166
|
* @param {number} y - The amount to translate in the y direction.
|
|
167
167
|
* @returns {Matrix} This matrix instance for chaining.
|
|
168
168
|
*/
|
|
169
|
-
translate(x: number, y: number) {
|
|
169
|
+
public translate(x: number, y: number) {
|
|
170
170
|
this.tx += x;
|
|
171
171
|
this.ty += y;
|
|
172
172
|
return this;
|
|
@@ -178,7 +178,7 @@ export class Matrix {
|
|
|
178
178
|
* @param {number} y - The amount to scale in the y direction.
|
|
179
179
|
* @returns {Matrix} This matrix instance for chaining.
|
|
180
180
|
*/
|
|
181
|
-
scale(x: number, y: number) {
|
|
181
|
+
public scale(x: number, y: number) {
|
|
182
182
|
this.a *= x;
|
|
183
183
|
this.d *= y;
|
|
184
184
|
this.c *= x;
|
|
@@ -193,7 +193,7 @@ export class Matrix {
|
|
|
193
193
|
* @param {number} angle - The angle in radians to rotate by.
|
|
194
194
|
* @returns {Matrix} This matrix instance for chaining.
|
|
195
195
|
*/
|
|
196
|
-
rotate(angle: number) {
|
|
196
|
+
public rotate(angle: number) {
|
|
197
197
|
const cos = Math.cos(angle);
|
|
198
198
|
const sin = Math.sin(angle);
|
|
199
199
|
const a1 = this.a;
|
|
@@ -213,7 +213,7 @@ export class Matrix {
|
|
|
213
213
|
* @param {Matrix} matrix - The matrix to append.
|
|
214
214
|
* @returns {Matrix} This matrix instance for chaining.
|
|
215
215
|
*/
|
|
216
|
-
append(matrix: Matrix) {
|
|
216
|
+
public append(matrix: Matrix) {
|
|
217
217
|
const a1 = this.a;
|
|
218
218
|
const b1 = this.b;
|
|
219
219
|
const c1 = this.c;
|
|
@@ -231,7 +231,7 @@ export class Matrix {
|
|
|
231
231
|
* Sets this matrix to an identity matrix (no transformation).
|
|
232
232
|
* @returns {Matrix} This matrix instance for chaining.
|
|
233
233
|
*/
|
|
234
|
-
identity() {
|
|
234
|
+
public identity() {
|
|
235
235
|
return this.setTo(1, 0, 0, 1, 0, 0);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
1
|
+
import { expect, describe, it } from 'vitest';
|
|
2
2
|
import { Point } from './point.js';
|
|
3
3
|
|
|
4
4
|
describe('Point', () => {
|
|
@@ -68,7 +68,6 @@ describe('Point', () => {
|
|
|
68
68
|
|
|
69
69
|
it('should divide points', () => {
|
|
70
70
|
const point1 = new Point(10, 20);
|
|
71
|
-
const point2 = new Point(2, 3);
|
|
72
71
|
const quotient = point1.divide(2, 3);
|
|
73
72
|
expect(quotient.x).toBe(5);
|
|
74
73
|
expect(quotient.y).toBeCloseTo(6.67);
|