@vpmedia/phaser 1.94.0 → 1.96.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/CHANGELOG.md +41 -0
- package/package.json +11 -11
- package/src/phaser/core/animation.js +79 -56
- package/src/phaser/core/animation_manager.js +55 -55
- package/src/phaser/core/animation_parser.js +2 -2
- package/src/phaser/core/cache.js +154 -154
- package/src/phaser/core/device.js +2 -1
- package/src/phaser/core/device_util.js +27 -27
- package/src/phaser/core/dom.js +43 -43
- package/src/phaser/core/event_manager.js +63 -63
- package/src/phaser/core/factory.js +47 -47
- package/src/phaser/core/frame.js +30 -30
- package/src/phaser/core/frame_data.js +30 -28
- package/src/phaser/core/frame_util.js +8 -8
- package/src/phaser/core/game.js +35 -19
- package/src/phaser/core/input_pointer.js +18 -0
- package/src/phaser/core/loader.js +171 -171
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scale_manager.js +3 -2
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +56 -52
- package/src/phaser/core/sound.js +54 -54
- package/src/phaser/core/sound_manager.js +49 -49
- package/src/phaser/core/stage.js +16 -16
- package/src/phaser/core/time.js +54 -30
- package/src/phaser/core/timer.js +82 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +106 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +32 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +72 -54
- package/src/phaser/display/button.js +48 -47
- package/src/phaser/display/canvas/buffer.js +8 -8
- package/src/phaser/display/canvas/graphics.js +8 -8
- package/src/phaser/display/canvas/masker.js +5 -5
- package/src/phaser/display/canvas/pool.js +18 -18
- package/src/phaser/display/canvas/renderer.js +17 -16
- package/src/phaser/display/canvas/tinter.js +22 -22
- package/src/phaser/display/canvas/util.js +42 -42
- package/src/phaser/display/display_object.js +119 -108
- package/src/phaser/display/graphics.js +129 -112
- package/src/phaser/display/graphics_data.js +10 -10
- package/src/phaser/display/graphics_data_util.js +3 -3
- package/src/phaser/display/group.js +63 -50
- package/src/phaser/display/image.js +68 -50
- package/src/phaser/display/sprite_batch.js +2 -2
- package/src/phaser/display/sprite_util.js +19 -19
- package/src/phaser/display/text.js +217 -187
- package/src/phaser/display/webgl/abstract_filter.js +4 -4
- package/src/phaser/display/webgl/base_texture.js +9 -9
- package/src/phaser/display/webgl/blend_manager.js +7 -7
- package/src/phaser/display/webgl/earcut.js +95 -95
- package/src/phaser/display/webgl/earcut_node.js +4 -4
- package/src/phaser/display/webgl/fast_sprite_batch.js +15 -15
- package/src/phaser/display/webgl/filter_manager.js +9 -9
- package/src/phaser/display/webgl/filter_texture.js +10 -10
- package/src/phaser/display/webgl/graphics.js +37 -37
- package/src/phaser/display/webgl/graphics_data.js +4 -4
- package/src/phaser/display/webgl/mask_manager.js +6 -6
- package/src/phaser/display/webgl/render_texture.js +16 -16
- package/src/phaser/display/webgl/renderer.js +21 -20
- package/src/phaser/display/webgl/shader/complex.js +4 -4
- package/src/phaser/display/webgl/shader/fast.js +4 -4
- package/src/phaser/display/webgl/shader/normal.js +8 -8
- package/src/phaser/display/webgl/shader/primitive.js +4 -4
- package/src/phaser/display/webgl/shader/strip.js +4 -4
- package/src/phaser/display/webgl/shader_manager.js +9 -9
- package/src/phaser/display/webgl/sprite_batch.js +18 -18
- package/src/phaser/display/webgl/stencil_manager.js +16 -16
- package/src/phaser/display/webgl/texture.js +13 -13
- package/src/phaser/display/webgl/texture_util.js +8 -8
- package/src/phaser/display/webgl/util.js +25 -25
- package/src/phaser/geom/circle.js +74 -69
- package/src/phaser/geom/ellipse.js +33 -28
- package/src/phaser/geom/line.js +96 -93
- package/src/phaser/geom/matrix.js +61 -54
- package/src/phaser/geom/point.js +99 -96
- package/src/phaser/geom/polygon.js +27 -22
- package/src/phaser/geom/rectangle.js +137 -132
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/util/math.js +81 -81
- package/types/phaser/core/animation.d.ts +79 -56
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +55 -55
- package/types/phaser/core/animation_parser.d.ts +3 -2
- package/types/phaser/core/animation_parser.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +51 -44
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/event_manager.d.ts +63 -63
- package/types/phaser/core/factory.d.ts +47 -47
- package/types/phaser/core/frame.d.ts +30 -30
- package/types/phaser/core/frame_data.d.ts +28 -27
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +54 -21
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input_pointer.d.ts +18 -0
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +175 -172
- package/types/phaser/core/loader.d.ts.map +1 -1
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +1 -1
- package/types/phaser/core/scale_manager.d.ts +6 -5
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +15 -9
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +51 -43
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +54 -51
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +54 -54
- package/types/phaser/core/sound_manager.d.ts +49 -49
- package/types/phaser/core/stage.d.ts +10 -10
- package/types/phaser/core/time.d.ts +54 -30
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +82 -64
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +106 -90
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +35 -67
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +4 -3
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +76 -53
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +47 -46
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +8 -8
- package/types/phaser/display/canvas/graphics.d.ts +3 -3
- package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +6 -3
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +18 -17
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts +6 -6
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +119 -108
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +118 -102
- package/types/phaser/display/graphics.d.ts.map +1 -1
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +59 -47
- package/types/phaser/display/group.d.ts.map +1 -1
- package/types/phaser/display/image.d.ts +58 -45
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +237 -188
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +4 -4
- package/types/phaser/display/webgl/base_texture.d.ts +10 -10
- package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/blend_manager.d.ts +6 -6
- package/types/phaser/display/webgl/earcut.d.ts +95 -95
- package/types/phaser/display/webgl/earcut_node.d.ts +4 -4
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +15 -15
- package/types/phaser/display/webgl/filter_manager.d.ts +8 -8
- package/types/phaser/display/webgl/filter_texture.d.ts +10 -10
- package/types/phaser/display/webgl/graphics.d.ts +2 -2
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +21 -20
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +4 -4
- package/types/phaser/display/webgl/shader/fast.d.ts +4 -4
- package/types/phaser/display/webgl/shader/normal.d.ts +8 -8
- package/types/phaser/display/webgl/shader/primitive.d.ts +4 -4
- package/types/phaser/display/webgl/shader/strip.d.ts +4 -4
- package/types/phaser/display/webgl/shader_manager.d.ts +8 -8
- package/types/phaser/display/webgl/sprite_batch.d.ts +17 -17
- package/types/phaser/display/webgl/stencil_manager.d.ts +15 -15
- package/types/phaser/display/webgl/texture.d.ts +12 -12
- package/types/phaser/display/webgl/texture_util.d.ts +4 -2
- package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +74 -69
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/ellipse.d.ts +33 -28
- package/types/phaser/geom/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/line.d.ts +96 -93
- package/types/phaser/geom/line.d.ts.map +1 -1
- package/types/phaser/geom/matrix.d.ts +61 -54
- package/types/phaser/geom/matrix.d.ts.map +1 -1
- package/types/phaser/geom/point.d.ts +99 -96
- package/types/phaser/geom/point.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +29 -23
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +137 -132
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/types/phaser/geom/util/point.d.ts +1 -1
- package/types/phaser/geom/util/point.d.ts.map +1 -1
- package/pnpm-workspace.yaml +0 -4
|
@@ -2,11 +2,11 @@ import { Point } from '../point.js';
|
|
|
2
2
|
import { Rectangle } from '../rectangle.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {Rectangle} a -
|
|
7
|
-
* @param {number} dx -
|
|
8
|
-
* @param {number} dy -
|
|
9
|
-
* @returns {Rectangle}
|
|
5
|
+
* Inflates the rectangle by the specified amounts on each axis.
|
|
6
|
+
* @param {Rectangle} a - The rectangle to inflate.
|
|
7
|
+
* @param {number} dx - The amount to inflate the rectangle horizontally.
|
|
8
|
+
* @param {number} dy - The amount to inflate the rectangle vertically.
|
|
9
|
+
* @returns {Rectangle} The inflated rectangle.
|
|
10
10
|
*/
|
|
11
11
|
export const inflate = (a, dx, dy) => {
|
|
12
12
|
a.x -= dx;
|
|
@@ -17,20 +17,20 @@ export const inflate = (a, dx, dy) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param {Rectangle} a -
|
|
22
|
-
* @param {object} point -
|
|
23
|
-
* @returns {Rectangle}
|
|
20
|
+
* Inflates the rectangle by the specified point values on each axis.
|
|
21
|
+
* @param {Rectangle} a - The rectangle to inflate.
|
|
22
|
+
* @param {object} point - The point containing x and y values to inflate the rectangle by.
|
|
23
|
+
* @returns {Rectangle} The inflated rectangle.
|
|
24
24
|
*/
|
|
25
25
|
export const inflatePoint = (a, point) => {
|
|
26
26
|
return inflate(a, point.x, point.y);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {Rectangle} a -
|
|
32
|
-
* @param {Point} output -
|
|
33
|
-
* @returns {Point}
|
|
30
|
+
* Gets the size of the rectangle as a point.
|
|
31
|
+
* @param {Rectangle} a - The rectangle to get the size of.
|
|
32
|
+
* @param {Point} output - Optional point to store the result in.
|
|
33
|
+
* @returns {Point} The size of the rectangle as a point (width, height).
|
|
34
34
|
*/
|
|
35
35
|
export const size = (a, output = null) => {
|
|
36
36
|
const result = output || new Point();
|
|
@@ -39,10 +39,10 @@ export const size = (a, output = null) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param {Rectangle} input -
|
|
44
|
-
* @param {Rectangle} output -
|
|
45
|
-
* @returns {Rectangle}
|
|
42
|
+
* Clones a rectangle.
|
|
43
|
+
* @param {Rectangle} input - The rectangle to clone.
|
|
44
|
+
* @param {Rectangle} output - Optional rectangle to store the result in.
|
|
45
|
+
* @returns {Rectangle} The cloned rectangle.
|
|
46
46
|
*/
|
|
47
47
|
export const clone = (input, output = null) => {
|
|
48
48
|
const result = output || new Rectangle();
|
|
@@ -51,11 +51,11 @@ export const clone = (input, output = null) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @param {Rectangle} a -
|
|
56
|
-
* @param {number} x -
|
|
57
|
-
* @param {number} y -
|
|
58
|
-
* @returns {boolean}
|
|
54
|
+
* Checks if a point is contained within the rectangle.
|
|
55
|
+
* @param {Rectangle} a - The rectangle to check.
|
|
56
|
+
* @param {number} x - The x coordinate of the point.
|
|
57
|
+
* @param {number} y - The y coordinate of the point.
|
|
58
|
+
* @returns {boolean} True if the point is contained within the rectangle, false otherwise.
|
|
59
59
|
*/
|
|
60
60
|
export const contains = (a, x, y) => {
|
|
61
61
|
if (a.width <= 0 || a.height <= 0) {
|
|
@@ -65,34 +65,34 @@ export const contains = (a, x, y) => {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {number} rx -
|
|
70
|
-
* @param {number} ry -
|
|
71
|
-
* @param {number} rw -
|
|
72
|
-
* @param {number} rh -
|
|
73
|
-
* @param {number} x -
|
|
74
|
-
* @param {number} y -
|
|
75
|
-
* @returns {boolean}
|
|
68
|
+
* Checks if a point is contained within the rectangle (raw version).
|
|
69
|
+
* @param {number} rx - The x coordinate of the rectangle.
|
|
70
|
+
* @param {number} ry - The y coordinate of the rectangle.
|
|
71
|
+
* @param {number} rw - The width of the rectangle.
|
|
72
|
+
* @param {number} rh - The height of the rectangle.
|
|
73
|
+
* @param {number} x - The x coordinate of the point.
|
|
74
|
+
* @param {number} y - The y coordinate of the point.
|
|
75
|
+
* @returns {boolean} True if the point is contained within the rectangle, false otherwise.
|
|
76
76
|
*/
|
|
77
77
|
export const containsRaw = (rx, ry, rw, rh, x, y) => {
|
|
78
78
|
return x >= rx && x < rx + rw && y >= ry && y < ry + rh;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param {Rectangle} a -
|
|
84
|
-
* @param {Point} point -
|
|
85
|
-
* @returns {boolean}
|
|
82
|
+
* Checks if a point is contained within the rectangle.
|
|
83
|
+
* @param {Rectangle} a - The rectangle to check.
|
|
84
|
+
* @param {Point} point - The point to check.
|
|
85
|
+
* @returns {boolean} True if the point is contained within the rectangle, false otherwise.
|
|
86
86
|
*/
|
|
87
87
|
export const containsPoint = (a, point) => {
|
|
88
88
|
return contains(a, point.x, point.y);
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param {Rectangle} a -
|
|
94
|
-
* @param {Rectangle} b -
|
|
95
|
-
* @returns {boolean}
|
|
92
|
+
* Checks if rectangle a contains rectangle b.
|
|
93
|
+
* @param {Rectangle} a - The first rectangle to check.
|
|
94
|
+
* @param {Rectangle} b - The second rectangle to check.
|
|
95
|
+
* @returns {boolean} True if rectangle a contains rectangle b, false otherwise.
|
|
96
96
|
*/
|
|
97
97
|
export const containsRect = (a, b) => {
|
|
98
98
|
if (a.volume > b.volume) {
|
|
@@ -102,30 +102,30 @@ export const containsRect = (a, b) => {
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @param {Rectangle} a -
|
|
107
|
-
* @param {Rectangle} b -
|
|
108
|
-
* @returns {boolean}
|
|
105
|
+
* Checks if two rectangles are equal.
|
|
106
|
+
* @param {Rectangle} a - The first rectangle to compare.
|
|
107
|
+
* @param {Rectangle} b - The second rectangle to compare.
|
|
108
|
+
* @returns {boolean} True if the rectangles are equal, false otherwise.
|
|
109
109
|
*/
|
|
110
110
|
export const equals = (a, b) => {
|
|
111
111
|
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param {Rectangle} a -
|
|
117
|
-
* @param {Rectangle} b -
|
|
118
|
-
* @returns {boolean}
|
|
115
|
+
* Checks if two rectangles have the same dimensions.
|
|
116
|
+
* @param {Rectangle} a - The first rectangle to compare.
|
|
117
|
+
* @param {Rectangle} b - The second rectangle to compare.
|
|
118
|
+
* @returns {boolean} True if the rectangles have the same dimensions, false otherwise.
|
|
119
119
|
*/
|
|
120
120
|
export const sameDimensions = (a, b) => {
|
|
121
121
|
return a.width === b.width && a.height === b.height;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
|
-
* @param {Rectangle} a -
|
|
127
|
-
* @param {Rectangle} b -
|
|
128
|
-
* @returns {boolean}
|
|
125
|
+
* Checks if two rectangles intersect.
|
|
126
|
+
* @param {Rectangle} a - The first rectangle to check.
|
|
127
|
+
* @param {Rectangle} b - The second rectangle to check.
|
|
128
|
+
* @returns {boolean} True if the rectangles intersect, false otherwise.
|
|
129
129
|
*/
|
|
130
130
|
export const intersects = (a, b) => {
|
|
131
131
|
if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) {
|
|
@@ -135,11 +135,11 @@ export const intersects = (a, b) => {
|
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
139
|
-
* @param {Rectangle} a -
|
|
140
|
-
* @param {Rectangle} b -
|
|
141
|
-
* @param {Rectangle} output -
|
|
142
|
-
* @returns {Rectangle}
|
|
138
|
+
* Gets the intersection of two rectangles.
|
|
139
|
+
* @param {Rectangle} a - The first rectangle.
|
|
140
|
+
* @param {Rectangle} b - The second rectangle.
|
|
141
|
+
* @param {Rectangle} output - Optional rectangle to store the result in.
|
|
142
|
+
* @returns {Rectangle} The intersection of the rectangles, or an empty rectangle if they don't intersect.
|
|
143
143
|
*/
|
|
144
144
|
export const intersection = (a, b, output = null) => {
|
|
145
145
|
const result = output || new Rectangle();
|
|
@@ -153,14 +153,14 @@ export const intersection = (a, b, output = null) => {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @param {Rectangle} a -
|
|
158
|
-
* @param {number} left -
|
|
159
|
-
* @param {number} right -
|
|
160
|
-
* @param {number} top -
|
|
161
|
-
* @param {number} bottom -
|
|
162
|
-
* @param {number} tolerance -
|
|
163
|
-
* @returns {boolean}
|
|
156
|
+
* Checks if a rectangle intersects with a set of raw coordinates.
|
|
157
|
+
* @param {Rectangle} a - The rectangle to check.
|
|
158
|
+
* @param {number} left - The left coordinate of the area to check.
|
|
159
|
+
* @param {number} right - The right coordinate of the area to check.
|
|
160
|
+
* @param {number} top - The top coordinate of the area to check.
|
|
161
|
+
* @param {number} bottom - The bottom coordinate of the area to check.
|
|
162
|
+
* @param {number} tolerance - Optional tolerance value for intersection.
|
|
163
|
+
* @returns {boolean} True if the rectangle intersects with the area, false otherwise.
|
|
164
164
|
*/
|
|
165
165
|
export const intersectsRaw = (a, left, right, top, bottom, tolerance = 0) => {
|
|
166
166
|
return !(
|
|
@@ -172,11 +172,11 @@ export const intersectsRaw = (a, left, right, top, bottom, tolerance = 0) => {
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
176
|
-
* @param {Rectangle} a -
|
|
177
|
-
* @param {Rectangle} b -
|
|
178
|
-
* @param {Rectangle} output -
|
|
179
|
-
* @returns {Rectangle}
|
|
175
|
+
* Gets the union of two rectangles.
|
|
176
|
+
* @param {Rectangle} a - The first rectangle.
|
|
177
|
+
* @param {Rectangle} b - The second rectangle.
|
|
178
|
+
* @param {Rectangle} output - Optional rectangle to store the result in.
|
|
179
|
+
* @returns {Rectangle} The union of the rectangles.
|
|
180
180
|
*/
|
|
181
181
|
export const union = (a, b, output = null) => {
|
|
182
182
|
const result = output || new Rectangle();
|
|
@@ -189,10 +189,10 @@ export const union = (a, b, output = null) => {
|
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param {Point[]} points -
|
|
194
|
-
* @param {Rectangle} output -
|
|
195
|
-
* @returns {Rectangle}
|
|
192
|
+
* Gets the axis-aligned bounding box (AABB) of a set of points.
|
|
193
|
+
* @param {Point[]} points - The array of points to calculate the AABB for.
|
|
194
|
+
* @param {Rectangle} output - Optional rectangle to store the result in.
|
|
195
|
+
* @returns {Rectangle} The AABB of the points.
|
|
196
196
|
*/
|
|
197
197
|
export const aabb = (points, output = null) => {
|
|
198
198
|
const result = output || new Rectangle();
|
|
@@ -219,8 +219,8 @@ export const aabb = (points, output = null) => {
|
|
|
219
219
|
};
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
223
|
-
* @returns {Rectangle}
|
|
222
|
+
* Gets an empty rectangle instance.
|
|
223
|
+
* @returns {Rectangle} An empty rectangle.
|
|
224
224
|
*/
|
|
225
225
|
export const getEmptyRectangle = () => {
|
|
226
226
|
if (!window.PhaserRegistry) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RoundedRectangle } from '../rounded_rectangle.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {RoundedRectangle} input -
|
|
6
|
-
* @param {RoundedRectangle} output -
|
|
7
|
-
* @returns {RoundedRectangle}
|
|
4
|
+
* Clones a rounded rectangle.
|
|
5
|
+
* @param {RoundedRectangle} input - The rounded rectangle to clone.
|
|
6
|
+
* @param {RoundedRectangle} output - Optional rounded rectangle to store the result in.
|
|
7
|
+
* @returns {RoundedRectangle} The cloned rounded rectangle.
|
|
8
8
|
*/
|
|
9
9
|
export const clone = (input, output = null) => {
|
|
10
10
|
const result = output || new RoundedRectangle();
|
package/src/phaser/util/math.js
CHANGED
|
@@ -3,27 +3,27 @@ export const RAD_TO_DEG = 180 / Math.PI;
|
|
|
3
3
|
export const PI_2 = Math.PI * 2;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {number} hex -
|
|
8
|
-
* @returns {number[]}
|
|
6
|
+
* Converts a hexadecimal color value to RGB components.
|
|
7
|
+
* @param {number} hex - The hexadecimal color value.
|
|
8
|
+
* @returns {number[]} An array containing the RGB components [r, g, b].
|
|
9
9
|
*/
|
|
10
10
|
export const hex2rgb = (hex) => {
|
|
11
11
|
return [((hex >> 16) & 0xff) / 255, ((hex >> 8) & 0xff) / 255, (hex & 0xff) / 255];
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {number} rgb -
|
|
17
|
-
* @returns {number}
|
|
15
|
+
* Converts RGB components to a hexadecimal color value.
|
|
16
|
+
* @param {number} rgb - The RGB components array [r, g, b].
|
|
17
|
+
* @returns {number} The hexadecimal color value.
|
|
18
18
|
*/
|
|
19
19
|
export const rgb2hex = (rgb) => {
|
|
20
20
|
return ((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + rgb[2] * 255;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @param {number} value -
|
|
26
|
-
* @returns {number}
|
|
24
|
+
* Gets the next power of two greater than or equal to a value.
|
|
25
|
+
* @param {number} value - The input value.
|
|
26
|
+
* @returns {number} The next power of two.
|
|
27
27
|
*/
|
|
28
28
|
export const getNextPowerOfTwo = (value) => {
|
|
29
29
|
// see: https://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_check_if_a_positive_number_is_a_power_of_two
|
|
@@ -38,49 +38,49 @@ export const getNextPowerOfTwo = (value) => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param {number} width -
|
|
43
|
-
* @param {number} height -
|
|
44
|
-
* @returns {boolean}
|
|
41
|
+
* Checks if both width and height are powers of two.
|
|
42
|
+
* @param {number} width - The width to check.
|
|
43
|
+
* @param {number} height - The height to check.
|
|
44
|
+
* @returns {boolean} True if both width and height are powers of two, false otherwise.
|
|
45
45
|
*/
|
|
46
46
|
export const isPowerOfTwo = (width, height) => {
|
|
47
47
|
return width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @param {number} degrees -
|
|
53
|
-
* @returns {number}
|
|
51
|
+
* Converts degrees to radians.
|
|
52
|
+
* @param {number} degrees - The angle in degrees.
|
|
53
|
+
* @returns {number} The angle in radians.
|
|
54
54
|
*/
|
|
55
55
|
export const degToRad = (degrees) => {
|
|
56
56
|
return degrees * DEG_TO_RAD;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {number} radians -
|
|
62
|
-
* @returns {number}
|
|
60
|
+
* Converts radians to degrees.
|
|
61
|
+
* @param {number} radians - The angle in radians.
|
|
62
|
+
* @returns {number} The angle in degrees.
|
|
63
63
|
*/
|
|
64
64
|
export const radToDeg = (radians) => {
|
|
65
65
|
return radians * RAD_TO_DEG;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
70
|
-
* @param {number} min -
|
|
71
|
-
* @param {number} max -
|
|
72
|
-
* @returns {number}
|
|
69
|
+
* Gets a random integer between min and max (inclusive).
|
|
70
|
+
* @param {number} min - The minimum value.
|
|
71
|
+
* @param {number} max - The maximum value.
|
|
72
|
+
* @returns {number} A random integer between min and max.
|
|
73
73
|
*/
|
|
74
74
|
export const between = (min, max) => {
|
|
75
75
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @param {number} input -
|
|
81
|
-
* @param {number} gap -
|
|
82
|
-
* @param {number} start -
|
|
83
|
-
* @returns {number}
|
|
79
|
+
* Snaps a value to the nearest multiple of gap, starting from start.
|
|
80
|
+
* @param {number} input - The value to snap.
|
|
81
|
+
* @param {number} gap - The gap size to snap to.
|
|
82
|
+
* @param {number} start - The starting offset for snapping.
|
|
83
|
+
* @returns {number} The snapped value.
|
|
84
84
|
*/
|
|
85
85
|
export const snapToCeil = (input, gap = 0, start = 0) => {
|
|
86
86
|
if (gap === 0) {
|
|
@@ -92,11 +92,11 @@ export const snapToCeil = (input, gap = 0, start = 0) => {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param {number} value -
|
|
97
|
-
* @param {number} min -
|
|
98
|
-
* @param {number} max -
|
|
99
|
-
* @returns {number}
|
|
95
|
+
* Wraps a value within a range.
|
|
96
|
+
* @param {number} value - The value to wrap.
|
|
97
|
+
* @param {number} min - The minimum value of the range.
|
|
98
|
+
* @param {number} max - The maximum value of the range.
|
|
99
|
+
* @returns {number} The wrapped value.
|
|
100
100
|
*/
|
|
101
101
|
export const wrap = (value, min, max) => {
|
|
102
102
|
const range = max - min;
|
|
@@ -111,31 +111,31 @@ export const wrap = (value, min, max) => {
|
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @param {number} p0 -
|
|
116
|
-
* @param {number} p1 -
|
|
117
|
-
* @param {number} t -
|
|
118
|
-
* @returns {number}
|
|
114
|
+
* Performs linear interpolation between two values.
|
|
115
|
+
* @param {number} p0 - The first point.
|
|
116
|
+
* @param {number} p1 - The second point.
|
|
117
|
+
* @param {number} t - The interpolation factor (0 to 1).
|
|
118
|
+
* @returns {number} The interpolated value.
|
|
119
119
|
*/
|
|
120
120
|
export const linear = (p0, p1, t) => {
|
|
121
121
|
return (p1 - p0) * t + p0;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
|
-
* @param {number} a -
|
|
127
|
-
* @param {number} b -
|
|
128
|
-
* @returns {number}
|
|
125
|
+
* Calculates the absolute difference between two numbers.
|
|
126
|
+
* @param {number} a - The first number.
|
|
127
|
+
* @param {number} b - The second number.
|
|
128
|
+
* @returns {number} The absolute difference between a and b.
|
|
129
129
|
*/
|
|
130
130
|
export const difference = (a, b) => {
|
|
131
131
|
return Math.abs(a - b);
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
136
|
-
* @param {number[]} v -
|
|
137
|
-
* @param {number} k -
|
|
138
|
-
* @returns {number}
|
|
135
|
+
* Performs linear interpolation on an array of values.
|
|
136
|
+
* @param {number[]} v - The array of values.
|
|
137
|
+
* @param {number} k - The interpolation factor (0 to 1).
|
|
138
|
+
* @returns {number} The interpolated value.
|
|
139
139
|
*/
|
|
140
140
|
export const linearInterpolation = (v, k) => {
|
|
141
141
|
const m = v.length - 1;
|
|
@@ -151,12 +151,12 @@ export const linearInterpolation = (v, k) => {
|
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
|
-
*
|
|
155
|
-
* @param {number} x1 -
|
|
156
|
-
* @param {number} y1 -
|
|
157
|
-
* @param {number} x2 -
|
|
158
|
-
* @param {number} y2 -
|
|
159
|
-
* @returns {number}
|
|
154
|
+
* Calculates the distance between two points.
|
|
155
|
+
* @param {number} x1 - The x-coordinate of the first point.
|
|
156
|
+
* @param {number} y1 - The y-coordinate of the first point.
|
|
157
|
+
* @param {number} x2 - The x-coordinate of the second point.
|
|
158
|
+
* @param {number} y2 - The y-coordinate of the second point.
|
|
159
|
+
* @returns {number} The distance between the two points.
|
|
160
160
|
*/
|
|
161
161
|
export const distance = (x1, y1, x2, y2) => {
|
|
162
162
|
const dx = x1 - x2;
|
|
@@ -165,43 +165,43 @@ export const distance = (x1, y1, x2, y2) => {
|
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
169
|
-
* @param {number} a -
|
|
170
|
-
* @param {number} b -
|
|
171
|
-
* @param {number} tolerance -
|
|
172
|
-
* @returns {boolean}
|
|
168
|
+
* Checks if two numbers are within a tolerance of each other.
|
|
169
|
+
* @param {number} a - The first number.
|
|
170
|
+
* @param {number} b - The second number.
|
|
171
|
+
* @param {number} tolerance - The tolerance value.
|
|
172
|
+
* @returns {boolean} True if the numbers are within tolerance, false otherwise.
|
|
173
173
|
*/
|
|
174
174
|
export const within = (a, b, tolerance) => {
|
|
175
175
|
return Math.abs(a - b) <= tolerance;
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param {number} a -
|
|
181
|
-
* @param {number} r -
|
|
182
|
-
* @param {number} g -
|
|
183
|
-
* @param {number} b -
|
|
184
|
-
* @returns {number}
|
|
179
|
+
* Creates a 32-bit color value from alpha, red, green, and blue components.
|
|
180
|
+
* @param {number} a - The alpha component (0-255).
|
|
181
|
+
* @param {number} r - The red component (0-255).
|
|
182
|
+
* @param {number} g - The green component (0-255).
|
|
183
|
+
* @param {number} b - The blue component (0-255).
|
|
184
|
+
* @returns {number} The 32-bit color value.
|
|
185
185
|
*/
|
|
186
186
|
export const getColor32 = (a, r, g, b) => {
|
|
187
187
|
return (a << 24) | (r << 16) | (g << 8) | b;
|
|
188
188
|
};
|
|
189
189
|
|
|
190
190
|
/**
|
|
191
|
-
*
|
|
192
|
-
* @param {number} r -
|
|
193
|
-
* @param {number} g -
|
|
194
|
-
* @param {number} b -
|
|
195
|
-
* @returns {number}
|
|
191
|
+
* Creates a 24-bit color value from red, green, and blue components.
|
|
192
|
+
* @param {number} r - The red component (0-255).
|
|
193
|
+
* @param {number} g - The green component (0-255).
|
|
194
|
+
* @param {number} b - The blue component (0-255).
|
|
195
|
+
* @returns {number} The 24-bit color value.
|
|
196
196
|
*/
|
|
197
197
|
export const getColor = (r, g, b) => {
|
|
198
198
|
return (r << 16) | (g << 8) | b;
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
203
|
-
* @param {string} value -
|
|
204
|
-
* @param {{r?: number, g?: number, b?: number}} out -
|
|
202
|
+
* Converts a hex color string to RGB components.
|
|
203
|
+
* @param {string} value - The hex color string (e.g. "#FF0000").
|
|
204
|
+
* @param {{r?: number, g?: number, b?: number}} out - The object to store the result in.
|
|
205
205
|
*/
|
|
206
206
|
export const hexToColor = (value, out) => {
|
|
207
207
|
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
|
@@ -215,9 +215,9 @@ export const hexToColor = (value, out) => {
|
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @param {string} value -
|
|
220
|
-
* @param {{r?: number, g?: number, b?: number, a?: number}} out -
|
|
218
|
+
* Converts a web color string (e.g. "rgb(255, 0, 0)") to RGB components with alpha.
|
|
219
|
+
* @param {string} value - The web color string (e.g. "rgba(255, 0, 0, 0.5)").
|
|
220
|
+
* @param {{r?: number, g?: number, b?: number, a?: number}} out - The object to store the result in.
|
|
221
221
|
*/
|
|
222
222
|
export const webToColor = (value, out) => {
|
|
223
223
|
const result = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec(value);
|
|
@@ -230,9 +230,9 @@ export const webToColor = (value, out) => {
|
|
|
230
230
|
};
|
|
231
231
|
|
|
232
232
|
/**
|
|
233
|
-
*
|
|
234
|
-
* @param {number} color -
|
|
235
|
-
* @returns {{ alpha: number, red: number, green: number, blue: number, a: number, r: number, g: number, b: number}}
|
|
233
|
+
* Extracts RGB components from a 32-bit color value.
|
|
234
|
+
* @param {number} color - The 32-bit color value.
|
|
235
|
+
* @returns {{ alpha: number, red: number, green: number, blue: number, a: number, r: number, g: number, b: number}} An object containing the color components.
|
|
236
236
|
*/
|
|
237
237
|
export const getRGB = (color) => {
|
|
238
238
|
if (color > 16777215) {
|
|
@@ -261,10 +261,10 @@ export const getRGB = (color) => {
|
|
|
261
261
|
};
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
|
-
*
|
|
265
|
-
* @param {string|number} value -
|
|
266
|
-
* @param {{a?: number, r?: number, g?: number, b?: number, rgba?: string, color?: number, color32?: number}} out -
|
|
267
|
-
* @returns {{a?: number, r?: number, g?: number, b?: number, rgba?: string, color?: number, color32?: number}}
|
|
264
|
+
* Converts a color value (string or number) to an object with various color formats.
|
|
265
|
+
* @param {string|number} value - The color value (e.g. "#FF0000" or 0xFF0000).
|
|
266
|
+
* @param {{a?: number, r?: number, g?: number, b?: number, rgba?: string, color?: number, color32?: number}} out - The object to store the result in.
|
|
267
|
+
* @returns {{a?: number, r?: number, g?: number, b?: number, rgba?: string, color?: number, color32?: number}} The updated out object.
|
|
268
268
|
*/
|
|
269
269
|
export const valueToColor = (value, out) => {
|
|
270
270
|
if (typeof value === 'string') {
|