@vpmedia/phaser 1.123.0 → 1.125.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +635 -623
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +3 -3
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +27 -2
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts +11 -11
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/callback.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +125 -19
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +3 -2
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +3 -2
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +5 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +3 -3
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +8 -8
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +11 -2
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +14 -1
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +1 -1
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +16 -6
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +13 -5
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +9 -7
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +6 -5
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +9 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +5 -3
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +1 -1
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +1 -1
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +6 -5
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +3 -2
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +2 -16
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +2 -2
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +8 -4
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +10 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts +2 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +11 -11
- package/src/phaser/core/animation_manager.ts +12 -12
- package/src/phaser/core/animation_parser.ts +39 -37
- package/src/phaser/core/array_set.ts +28 -28
- package/src/phaser/core/cache.test.ts +33 -33
- package/src/phaser/core/cache.ts +7 -7
- package/src/phaser/core/callback.ts +1 -0
- package/src/phaser/core/callback_context.test.ts +8 -8
- package/src/phaser/core/device_util.ts +4 -4
- package/src/phaser/core/dom.ts +38 -24
- package/src/phaser/core/factory.ts +9 -2
- package/src/phaser/core/frame_data.test.ts +23 -23
- package/src/phaser/core/frame_data.ts +2 -5
- package/src/phaser/core/game.ts +12 -12
- package/src/phaser/core/input.ts +11 -10
- package/src/phaser/core/input_handler.test.ts +18 -18
- package/src/phaser/core/input_handler.ts +14 -14
- package/src/phaser/core/input_mouse.ts +13 -12
- package/src/phaser/core/input_pointer.test.ts +26 -26
- package/src/phaser/core/input_pointer.ts +4 -4
- package/src/phaser/core/input_touch.ts +8 -8
- package/src/phaser/core/loader.test.ts +26 -26
- package/src/phaser/core/loader.ts +63 -75
- package/src/phaser/core/loader_parser.test.ts +16 -16
- package/src/phaser/core/loader_parser.ts +16 -6
- package/src/phaser/core/raf.ts +1 -1
- package/src/phaser/core/registry.test.ts +6 -6
- package/src/phaser/core/scale_manager.ts +12 -11
- package/src/phaser/core/scene_manager.test.ts +30 -30
- package/src/phaser/core/scene_manager.ts +3 -3
- package/src/phaser/core/signal.test.ts +8 -8
- package/src/phaser/core/signal.ts +3 -3
- package/src/phaser/core/signal_dispatch.test.ts +30 -30
- package/src/phaser/core/sound.ts +45 -40
- package/src/phaser/core/sound_manager.ts +18 -22
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +22 -12
- package/src/phaser/core/time.ts +1 -1
- package/src/phaser/core/timer.test.ts +47 -47
- package/src/phaser/core/timer.ts +2 -2
- package/src/phaser/core/tween.ts +34 -36
- package/src/phaser/core/tween_data.test.ts +119 -0
- package/src/phaser/core/tween_data.ts +54 -39
- package/src/phaser/core/tween_easing.test.ts +5 -5
- package/src/phaser/core/tween_manager.ts +2 -2
- package/src/phaser/display/bitmap_text.test.ts +30 -30
- package/src/phaser/display/bitmap_text.ts +3 -3
- package/src/phaser/display/button.ts +20 -18
- package/src/phaser/display/canvas/buffer.ts +2 -2
- package/src/phaser/display/canvas/graphics.ts +2 -2
- package/src/phaser/display/canvas/masker.ts +1 -1
- package/src/phaser/display/canvas/pool.test.ts +20 -20
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +18 -16
- package/src/phaser/display/canvas/tinter.ts +1 -1
- package/src/phaser/display/canvas/util.test.ts +25 -25
- package/src/phaser/display/canvas/util.ts +2 -2
- package/src/phaser/display/display_object.ts +16 -15
- package/src/phaser/display/graphics.test.ts +70 -20
- package/src/phaser/display/graphics.ts +46 -42
- package/src/phaser/display/group.ts +13 -12
- package/src/phaser/display/image.ts +35 -31
- package/src/phaser/display/sprite_util.ts +4 -3
- package/src/phaser/display/text.test.ts +28 -25
- package/src/phaser/display/text.ts +56 -62
- package/src/phaser/display/webgl/abstract_filter.ts +21 -11
- package/src/phaser/display/webgl/blend_manager.ts +4 -5
- package/src/phaser/display/webgl/earcut.test.ts +20 -20
- package/src/phaser/display/webgl/earcut.ts +46 -42
- package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
- package/src/phaser/display/webgl/filter_manager.ts +7 -4
- package/src/phaser/display/webgl/filter_texture.ts +5 -5
- package/src/phaser/display/webgl/graphics.ts +3 -3
- package/src/phaser/display/webgl/mask_manager.ts +9 -14
- package/src/phaser/display/webgl/render_texture.ts +15 -14
- package/src/phaser/display/webgl/renderer.ts +10 -9
- package/src/phaser/display/webgl/shader/normal.ts +45 -35
- package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
- package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
- package/src/phaser/display/webgl/shader_manager.ts +1 -1
- package/src/phaser/display/webgl/sprite_batch.ts +10 -10
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +2 -1
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +4 -4
- package/src/phaser/geom/circle.test.ts +38 -38
- package/src/phaser/geom/circle.ts +7 -7
- package/src/phaser/geom/ellipse.test.ts +12 -12
- package/src/phaser/geom/line.test.ts +15 -15
- package/src/phaser/geom/line.ts +5 -2
- package/src/phaser/geom/matrix.test.ts +31 -31
- package/src/phaser/geom/point.test.ts +31 -31
- package/src/phaser/geom/polygon.test.ts +27 -27
- package/src/phaser/geom/polygon.ts +2 -2
- package/src/phaser/geom/rectangle.test.ts +87 -87
- package/src/phaser/geom/rectangle.ts +12 -13
- package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +5 -5
- package/src/phaser/geom/util/circle.ts +8 -11
- package/src/phaser/geom/util/ellipse.test.ts +2 -2
- package/src/phaser/geom/util/line.test.ts +2 -2
- package/src/phaser/geom/util/matrix.test.ts +4 -4
- package/src/phaser/geom/util/point.test.ts +2 -2
- package/src/phaser/geom/util/point.ts +6 -8
- package/src/phaser/geom/util/polygon.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.ts +1 -1
- package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
- package/src/phaser/util/math.test.ts +41 -41
- package/src/phaser/util/math.ts +7 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { degToRad, distance } from '../../util/math.js';
|
|
2
2
|
import { Circle } from '../circle.js';
|
|
3
3
|
import { Point } from '../point.js';
|
|
4
|
+
import type { Rectangle } from '../rectangle.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Clones a circle.
|
|
@@ -58,11 +59,9 @@ export const intersects = (a: Circle, b: Circle): boolean => distance(a.x, a.y,
|
|
|
58
59
|
*/
|
|
59
60
|
export const circumferencePoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null): Point => {
|
|
60
61
|
const result = output ?? new Point();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result.x = a.x + a.radius * Math.cos(angle);
|
|
65
|
-
result.y = a.y + a.radius * Math.sin(angle);
|
|
62
|
+
const radians = asDegrees ? degToRad(angle) : angle;
|
|
63
|
+
result.x = a.x + a.radius * Math.cos(radians);
|
|
64
|
+
result.y = a.y + a.radius * Math.sin(radians);
|
|
66
65
|
return result;
|
|
67
66
|
};
|
|
68
67
|
|
|
@@ -76,11 +75,9 @@ export const circumferencePoint = (a: Circle, angle: number, asDegrees = false,
|
|
|
76
75
|
*/
|
|
77
76
|
export const intersectsPoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null): Point => {
|
|
78
77
|
const result = output ?? new Point();
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result.x = a.x + a.radius * Math.cos(angle);
|
|
83
|
-
result.y = a.y + a.radius * Math.sin(angle);
|
|
78
|
+
const radians = asDegrees ? degToRad(angle) : angle;
|
|
79
|
+
result.x = a.x + a.radius * Math.cos(radians);
|
|
80
|
+
result.y = a.y + a.radius * Math.sin(radians);
|
|
84
81
|
return result;
|
|
85
82
|
};
|
|
86
83
|
|
|
@@ -90,7 +87,7 @@ export const intersectsPoint = (a: Circle, angle: number, asDegrees = false, out
|
|
|
90
87
|
* @param {object} r - The rectangle to check.
|
|
91
88
|
* @returns {boolean} True if the circle intersects with the rectangle, false otherwise.
|
|
92
89
|
*/
|
|
93
|
-
export const intersectsRectangle = (c: Circle, r:
|
|
90
|
+
export const intersectsRectangle = (c: Circle, r: Rectangle): boolean => {
|
|
94
91
|
const cx = Math.abs(c.x - r.x - r.halfWidth);
|
|
95
92
|
const xDist = r.halfWidth + c.radius;
|
|
96
93
|
if (cx > xDist) {
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { Ellipse } from '../ellipse.js';
|
|
3
3
|
import { contains } from './ellipse.js';
|
|
4
4
|
|
|
5
|
-
describe('ellipse utils', () => {
|
|
6
|
-
it('should contain an ellipse the given coordinates', () => {
|
|
5
|
+
describe('ellipse utils', (): void => {
|
|
6
|
+
it('should contain an ellipse the given coordinates', (): void => {
|
|
7
7
|
const ellipse = new Ellipse(0, 0, 10, 10);
|
|
8
8
|
expect(contains(ellipse, 5, 5)).toBe(true);
|
|
9
9
|
expect(contains(ellipse, 15, 15)).toBe(false);
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { Line } from '../line.js';
|
|
3
3
|
import { clone } from './line.js';
|
|
4
4
|
|
|
5
|
-
describe('line utils', () => {
|
|
6
|
-
it('should clone a line', () => {
|
|
5
|
+
describe('line utils', (): void => {
|
|
6
|
+
it('should clone a line', (): void => {
|
|
7
7
|
const line1 = new Line(0, 0, 10, 0);
|
|
8
8
|
const line2 = clone(line1);
|
|
9
9
|
expect(line1.start.x).toBe(line2.start.x);
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { Matrix } from '../matrix.js';
|
|
3
3
|
import { clone, getIdentityMatrix, getTempMatrix } from './matrix.js';
|
|
4
4
|
|
|
5
|
-
describe('matrix utils', () => {
|
|
6
|
-
it('should clone a matrix', () => {
|
|
5
|
+
describe('matrix utils', (): void => {
|
|
6
|
+
it('should clone a matrix', (): void => {
|
|
7
7
|
const matrix1 = new Matrix(2, 0, 0, 2, 0, 0);
|
|
8
8
|
const matrix2 = clone(matrix1);
|
|
9
9
|
expect(matrix1.a).toBe(matrix2.a);
|
|
@@ -14,12 +14,12 @@ describe('matrix utils', () => {
|
|
|
14
14
|
expect(matrix1.ty).toBe(matrix2.ty);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
it('should create an identity matrix', () => {
|
|
17
|
+
it('should create an identity matrix', (): void => {
|
|
18
18
|
const matrix = getIdentityMatrix();
|
|
19
19
|
expect(matrix.a).toBe(1);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it('should create a temporary matrix', () => {
|
|
22
|
+
it('should create a temporary matrix', (): void => {
|
|
23
23
|
const matrix = getTempMatrix();
|
|
24
24
|
expect(matrix.a).toBe(1);
|
|
25
25
|
});
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { Point } from '../point.js';
|
|
3
3
|
import { clone } from './point.js';
|
|
4
4
|
|
|
5
|
-
describe('point utils', () => {
|
|
6
|
-
it('should clone a point', () => {
|
|
5
|
+
describe('point utils', (): void => {
|
|
6
|
+
it('should clone a point', (): void => {
|
|
7
7
|
const point1 = new Point(1, 2);
|
|
8
8
|
const point2 = clone(point1);
|
|
9
9
|
expect(point1.x).toBe(point2.x);
|
|
@@ -221,13 +221,11 @@ export const rotate = (
|
|
|
221
221
|
asDegrees: boolean,
|
|
222
222
|
dist: number | null | undefined
|
|
223
223
|
): Point => {
|
|
224
|
-
|
|
225
|
-
ang *= Math.PI / 180;
|
|
226
|
-
}
|
|
224
|
+
const radians = asDegrees ? ang * (Math.PI / 180) : ang;
|
|
227
225
|
if (dist === undefined || dist === null) {
|
|
228
226
|
a.subtract(x, y);
|
|
229
|
-
const s = Math.sin(
|
|
230
|
-
const c = Math.cos(
|
|
227
|
+
const s = Math.sin(radians);
|
|
228
|
+
const c = Math.cos(radians);
|
|
231
229
|
const tx = c * a.x - s * a.y;
|
|
232
230
|
const ty = s * a.x + c * a.y;
|
|
233
231
|
a.x = tx + x;
|
|
@@ -271,12 +269,12 @@ export const centroid = (points: Point[], output: Point | null = null): Point =>
|
|
|
271
269
|
* @param {string} yProp - The name of the property containing the y value (default: 'y').
|
|
272
270
|
* @returns {Point} A new point with parsed x and y values.
|
|
273
271
|
*/
|
|
274
|
-
export const parse = (obj:
|
|
272
|
+
export const parse = (obj: Record<string, unknown>, xProp = 'x', yProp = 'y'): Point => {
|
|
275
273
|
const point = new Point();
|
|
276
|
-
if (obj[xProp]) {
|
|
274
|
+
if (obj[xProp] !== undefined) {
|
|
277
275
|
point.x = Math.trunc(Number(obj[xProp]));
|
|
278
276
|
}
|
|
279
|
-
if (obj[yProp]) {
|
|
277
|
+
if (obj[yProp] !== undefined) {
|
|
280
278
|
point.y = Math.trunc(Number(obj[yProp]));
|
|
281
279
|
}
|
|
282
280
|
return point;
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { Polygon } from '../polygon.js';
|
|
3
3
|
import { clone } from './polygon.js';
|
|
4
4
|
|
|
5
|
-
describe('polygon utils', () => {
|
|
6
|
-
it('should clone a polygon', () => {
|
|
5
|
+
describe('polygon utils', (): void => {
|
|
6
|
+
it('should clone a polygon', (): void => {
|
|
7
7
|
const polygon = new Polygon([0, 0, 1, 0, 1, 1]);
|
|
8
8
|
const points = clone(polygon).toNumberArray();
|
|
9
9
|
expect(points[0]).toBe(0);
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { Rectangle } from '../rectangle.js';
|
|
3
3
|
import { clone } from './rectangle.js';
|
|
4
4
|
|
|
5
|
-
describe('rectangle utils', () => {
|
|
6
|
-
it('should clone a rectangle', () => {
|
|
5
|
+
describe('rectangle utils', (): void => {
|
|
6
|
+
it('should clone a rectangle', (): void => {
|
|
7
7
|
const rectangle1 = new Rectangle(0, 0, 10, 10);
|
|
8
8
|
const rectangle2 = clone(rectangle1);
|
|
9
9
|
expect(rectangle1.x).toBe(rectangle2.x);
|
|
@@ -23,7 +23,7 @@ export const inflate = (a: Rectangle, dx: number, dy: number): Rectangle => {
|
|
|
23
23
|
* @param {object} point - The point containing x and y values to inflate the rectangle by.
|
|
24
24
|
* @returns {Rectangle} The inflated rectangle.
|
|
25
25
|
*/
|
|
26
|
-
export const inflatePoint = (a: Rectangle, point:
|
|
26
|
+
export const inflatePoint = (a: Rectangle, point: Point): Rectangle => inflate(a, point.x, point.y);
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Gets the size of the rectangle as a point.
|
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { RoundedRectangle } from '../rounded_rectangle.js';
|
|
3
3
|
import { clone } from './rounded_rectangle.js';
|
|
4
4
|
|
|
5
|
-
describe('rounded rectangle utils', () => {
|
|
6
|
-
it('should clone a rounded rectangle', () => {
|
|
5
|
+
describe('rounded rectangle utils', (): void => {
|
|
6
|
+
it('should clone a rounded rectangle', (): void => {
|
|
7
7
|
const rectangle1 = new RoundedRectangle(0, 0, 10, 10, 2);
|
|
8
8
|
const rectangle2 = clone(rectangle1);
|
|
9
9
|
expect(rectangle1.x).toBe(rectangle2.x);
|
|
@@ -17,66 +17,66 @@ import {
|
|
|
17
17
|
wrap,
|
|
18
18
|
} from './math.js';
|
|
19
19
|
|
|
20
|
-
describe('DEG_TO_RAD', () => {
|
|
21
|
-
it('returns the correct value', () => {
|
|
20
|
+
describe('DEG_TO_RAD', (): void => {
|
|
21
|
+
it('returns the correct value', (): void => {
|
|
22
22
|
expect(DEG_TO_RAD).toBeCloseTo(Math.PI / 180);
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
describe('RAD_TO_DEG', () => {
|
|
27
|
-
it('returns the correct value', () => {
|
|
26
|
+
describe('RAD_TO_DEG', (): void => {
|
|
27
|
+
it('returns the correct value', (): void => {
|
|
28
28
|
expect(RAD_TO_DEG).toBeCloseTo(180 / Math.PI);
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
describe('PI_2', () => {
|
|
33
|
-
it('returns the correct value', () => {
|
|
32
|
+
describe('PI_2', (): void => {
|
|
33
|
+
it('returns the correct value', (): void => {
|
|
34
34
|
expect(PI_2).toBeCloseTo(Math.PI * 2);
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
describe('getNextPowerOfTwo', () => {
|
|
39
|
-
it('returns the correct power of two value for a valid input', () => {
|
|
38
|
+
describe('getNextPowerOfTwo', (): void => {
|
|
39
|
+
it('returns the correct power of two value for a valid input', (): void => {
|
|
40
40
|
expect(getNextPowerOfTwo(10)).toBe(16);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('returns the correct power of two value for an invalid input', () => {
|
|
43
|
+
it('returns the correct power of two value for an invalid input', (): void => {
|
|
44
44
|
expect(getNextPowerOfTwo(-5)).toBe(1);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
describe('isPowerOfTwo', () => {
|
|
49
|
-
it('returns true for a valid power of two value', () => {
|
|
48
|
+
describe('isPowerOfTwo', (): void => {
|
|
49
|
+
it('returns true for a valid power of two value', (): void => {
|
|
50
50
|
expect(isPowerOfTwo(8, 16)).toBe(true);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
it('returns false for an invalid power of two value', () => {
|
|
53
|
+
it('returns false for an invalid power of two value', (): void => {
|
|
54
54
|
expect(isPowerOfTwo(7, 15)).toBe(false);
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
describe('degToRad', () => {
|
|
59
|
-
it('returns the correct radian value for a valid degree input', () => {
|
|
58
|
+
describe('degToRad', (): void => {
|
|
59
|
+
it('returns the correct radian value for a valid degree input', (): void => {
|
|
60
60
|
expect(degToRad(90)).toBeCloseTo(Math.PI / 2);
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
it('returns the correct radian value for an invalid degree input', () => {
|
|
63
|
+
it('returns the correct radian value for an invalid degree input', (): void => {
|
|
64
64
|
expect(degToRad(-45)).toBeCloseTo(-0.7853);
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
describe('radToDeg', () => {
|
|
69
|
-
it('returns the correct degree value for a valid radian input', () => {
|
|
68
|
+
describe('radToDeg', (): void => {
|
|
69
|
+
it('returns the correct degree value for a valid radian input', (): void => {
|
|
70
70
|
expect(radToDeg(Math.PI / 2)).toBe(90);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
it('returns the correct degree value for an invalid radian input', () => {
|
|
73
|
+
it('returns the correct degree value for an invalid radian input', (): void => {
|
|
74
74
|
expect(radToDeg(-Math.PI / 10)).toBe(-18);
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
describe('between', () => {
|
|
79
|
-
it('returns a random value within the specified range', () => {
|
|
78
|
+
describe('between', (): void => {
|
|
79
|
+
it('returns a random value within the specified range', (): void => {
|
|
80
80
|
const min = 1;
|
|
81
81
|
const max = 100;
|
|
82
82
|
const result = between(min, max);
|
|
@@ -85,18 +85,18 @@ describe('between', () => {
|
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
describe('snapToCeil', () => {
|
|
89
|
-
it('returns the correct snapped value for a valid input with a gap of 1', () => {
|
|
88
|
+
describe('snapToCeil', (): void => {
|
|
89
|
+
it('returns the correct snapped value for a valid input with a gap of 1', (): void => {
|
|
90
90
|
expect(snapToCeil(3.7, 1)).toBe(4);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
it('returns the correct snapped value for a valid input with a gap of 2', () => {
|
|
93
|
+
it('returns the correct snapped value for a valid input with a gap of 2', (): void => {
|
|
94
94
|
expect(snapToCeil(5.3, 2)).toBe(6);
|
|
95
95
|
});
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
describe('wrap', () => {
|
|
99
|
-
it('returns the correct wrapped value for a valid input', () => {
|
|
98
|
+
describe('wrap', (): void => {
|
|
99
|
+
it('returns the correct wrapped value for a valid input', (): void => {
|
|
100
100
|
const min = 0;
|
|
101
101
|
const max = 100;
|
|
102
102
|
const result = wrap(150, min, max);
|
|
@@ -104,7 +104,7 @@ describe('wrap', () => {
|
|
|
104
104
|
expect(result).toBeLessThanOrEqual(max);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
it('returns the correct wrapped value for an invalid input', () => {
|
|
107
|
+
it('returns the correct wrapped value for an invalid input', (): void => {
|
|
108
108
|
const min = -1;
|
|
109
109
|
const max = 10;
|
|
110
110
|
const result = wrap(-20, min, max);
|
|
@@ -113,15 +113,15 @@ describe('wrap', () => {
|
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
describe('linear', () => {
|
|
117
|
-
it('returns the correct interpolated value for a valid input', () => {
|
|
116
|
+
describe('linear', (): void => {
|
|
117
|
+
it('returns the correct interpolated value for a valid input', (): void => {
|
|
118
118
|
const p0 = 1;
|
|
119
119
|
const p1 = 2;
|
|
120
120
|
const t = 0.5;
|
|
121
121
|
expect(linear(p0, p1, t)).toStrictEqual(1.5);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
it('returns the correct interpolated value for an invalid input', () => {
|
|
124
|
+
it('returns the correct interpolated value for an invalid input', (): void => {
|
|
125
125
|
const p0 = 1;
|
|
126
126
|
const p1 = 2;
|
|
127
127
|
const t = 2;
|
|
@@ -129,32 +129,32 @@ describe('linear', () => {
|
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
describe('difference', () => {
|
|
133
|
-
it('returns the correct difference value for a valid input', () => {
|
|
132
|
+
describe('difference', (): void => {
|
|
133
|
+
it('returns the correct difference value for a valid input', (): void => {
|
|
134
134
|
expect(difference(10, 5)).toBe(5);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
it('returns the correct difference value for an invalid input', () => {
|
|
137
|
+
it('returns the correct difference value for an invalid input', (): void => {
|
|
138
138
|
expect(difference(-10, -15)).toBe(5);
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
describe('linearInterpolation', () => {
|
|
143
|
-
it('returns the correct interpolated value for a valid input', () => {
|
|
142
|
+
describe('linearInterpolation', (): void => {
|
|
143
|
+
it('returns the correct interpolated value for a valid input', (): void => {
|
|
144
144
|
const v = [1, 2, 3];
|
|
145
145
|
const k = 0.5;
|
|
146
146
|
expect(linearInterpolation(v, k)).toBe(2);
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
-
it('returns the correct interpolated value for an invalid input', () => {
|
|
149
|
+
it('returns the correct interpolated value for an invalid input', (): void => {
|
|
150
150
|
const v = [-10, -20, -30];
|
|
151
151
|
const k = -1;
|
|
152
152
|
expect(linearInterpolation(v, k)).toBe(10);
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
-
describe('distance', () => {
|
|
157
|
-
it('returns the correct distance value for a valid input', () => {
|
|
156
|
+
describe('distance', (): void => {
|
|
157
|
+
it('returns the correct distance value for a valid input', (): void => {
|
|
158
158
|
const x1 = 0;
|
|
159
159
|
const y1 = 0;
|
|
160
160
|
const x2 = 3;
|
|
@@ -162,7 +162,7 @@ describe('distance', () => {
|
|
|
162
162
|
expect(distance(x1, y1, x2, y2)).toBeCloseTo(5);
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
it('returns the correct distance value for an invalid input', () => {
|
|
165
|
+
it('returns the correct distance value for an invalid input', (): void => {
|
|
166
166
|
const x1 = -10;
|
|
167
167
|
const y1 = -20;
|
|
168
168
|
const x2 = 100;
|
|
@@ -171,15 +171,15 @@ describe('distance', () => {
|
|
|
171
171
|
});
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
describe('within', () => {
|
|
175
|
-
it('returns true for a valid input within the specified tolerance', () => {
|
|
174
|
+
describe('within', (): void => {
|
|
175
|
+
it('returns true for a valid input within the specified tolerance', (): void => {
|
|
176
176
|
const a = 6;
|
|
177
177
|
const b = 5;
|
|
178
178
|
const tolerance = 1;
|
|
179
179
|
expect(within(a, b, tolerance)).toBe(true);
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
it('returns false for an invalid input outside the specified tolerance', () => {
|
|
182
|
+
it('returns false for an invalid input outside the specified tolerance', (): void => {
|
|
183
183
|
const a = -10;
|
|
184
184
|
const b = -15;
|
|
185
185
|
const tolerance = 0.001;
|
package/src/phaser/util/math.ts
CHANGED
|
@@ -63,9 +63,8 @@ export const snapToCeil = (input: number, gap = 0, start = 0): number => {
|
|
|
63
63
|
if (gap === 0) {
|
|
64
64
|
return input;
|
|
65
65
|
}
|
|
66
|
-
input
|
|
67
|
-
|
|
68
|
-
return start + input;
|
|
66
|
+
const offset = gap * Math.ceil((input - start) / gap);
|
|
67
|
+
return start + offset;
|
|
69
68
|
};
|
|
70
69
|
|
|
71
70
|
/** Wraps a value within a range. */
|
|
@@ -115,8 +114,11 @@ export const getColor = (r: number, g: number, b: number): number => (r << 16) |
|
|
|
115
114
|
|
|
116
115
|
/** Converts a hex color string to RGB components. */
|
|
117
116
|
export const hexToColor = (value: string, out: ColorTarget): void => {
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const expanded = value.replace(
|
|
118
|
+
/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i,
|
|
119
|
+
(_match: string, r: string, g: string, b: string): string => r + r + g + g + b + b
|
|
120
|
+
);
|
|
121
|
+
const result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(expanded);
|
|
120
122
|
if (result) {
|
|
121
123
|
out.r = Number.parseInt(result[1]!, 16);
|
|
122
124
|
out.g = Number.parseInt(result[2]!, 16);
|