From 757e0f984c9f86a9d7f0de387a70c4cc45b72be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Darida?= Date: Tue, 23 Sep 2025 21:47:57 +0200 Subject: [PATCH 1/2] feat: implement PointUtil.distance function --- src/animation/Tween.ts | 10 ++++++---- src/utils/PointUtil.ts | 23 +++++++++++++++-------- tests/utils/PointUtil.test.ts | 10 +++++++++- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/animation/Tween.ts b/src/animation/Tween.ts index aeeb507..dbbefa8 100644 --- a/src/animation/Tween.ts +++ b/src/animation/Tween.ts @@ -55,9 +55,9 @@ export class Tween { private _delay: number; private _transition: Transition; private _onComplete: () => void; - private _ticker: Ticker; - private _startValues: Map; - private _endValues: Map; + private readonly _ticker: Ticker; + private readonly _startValues: Map; + private readonly _endValues: Map; private _elapsedTime: number; private _isComplete: boolean; @@ -228,7 +228,9 @@ export class Tween { * Update function called on every ticker frame. * Handles time progression, easing, and property interpolation. */ - private update: TickerCallback = (): void => { + private readonly update: TickerCallback = < + K extends keyof T + >(): void => { this._elapsedTime += this._ticker.deltaMS; if (this._elapsedTime < 0) return; diff --git a/src/utils/PointUtil.ts b/src/utils/PointUtil.ts index a77f1d1..55c8aea 100644 --- a/src/utils/PointUtil.ts +++ b/src/utils/PointUtil.ts @@ -17,10 +17,7 @@ export function lerp( t: number, result?: Point ): Point { - if (!result) { - result = new Point(); - } - + result ??= new Point(); result.x = MathUtil.lerp(start.x, end.x, t); result.y = MathUtil.lerp(start.y, end.y, t); @@ -44,12 +41,22 @@ export function qerp( t: number, result?: Point ): Point { - if (!result) { - result = new Point(); - } - + result ??= new Point(); result.x = MathUtil.qerp(start.x, control.x, end.x, t); result.y = MathUtil.qerp(start.y, control.y, end.y, t); return result; } + +/** + * Calculates the Euclidean distance between two `PIXI.Point` objects. + * + * @param a The first point. + * @param b The second point. + * @returns The distance between the two points. + */ +export function distance(a: Point, b: Point): number { + const dx = b.x - a.x; + const dy = b.y - a.y; + return Math.sqrt(dx * dx + dy * dy); +} diff --git a/tests/utils/PointUtil.test.ts b/tests/utils/PointUtil.test.ts index 968fbe1..8603ef6 100644 --- a/tests/utils/PointUtil.test.ts +++ b/tests/utils/PointUtil.test.ts @@ -28,7 +28,7 @@ describe('Test PointUtil functions', () => { expect(actual.y).toBe(-5.1); }); - it('should compute quadratic interpolation between two numbers', () => { + it('should compute quadratic interpolation between two points', () => { const start = new Point(-5, 5); const control = new Point(0, 0); const end = new Point(5, -5); @@ -53,4 +53,12 @@ describe('Test PointUtil functions', () => { expect(actual.x).toBeCloseTo(5.1); expect(actual.y).toBeCloseTo(-5.1); }); + + it('should compute the distance between two points', () => { + const a = new Point(0, 0); + const b = new Point(3, 4); + + const actual = PointUtil.distance(a, b); + expect(actual).toBe(5); + }); }); From 4a6351f2ca52c5a7fb46f15b3a55205bf99e079e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Darida?= Date: Tue, 23 Sep 2025 21:48:02 +0200 Subject: [PATCH 2/2] chore(release): 0.1.25 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 205ee13..72f2cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.1.25](https://github.com/rdarida/gameforge/compare/v0.1.24...v0.1.25) (2025-09-23) + + +### Features + +* implement PointUtil.distance function ([757e0f9](https://github.com/rdarida/gameforge/commit/757e0f984c9f86a9d7f0de387a70c4cc45b72be9)) + ### [0.1.24](https://github.com/rdarida/gameforge/compare/v0.1.23...v0.1.24) (2025-09-23) diff --git a/package-lock.json b/package-lock.json index 029a3cd..19c6012 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gameforge", - "version": "0.1.24", + "version": "0.1.25", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gameforge", - "version": "0.1.24", + "version": "0.1.25", "license": "MIT", "dependencies": { "@pixi/sound": ">=5.2.3 <6.0.0", diff --git a/package.json b/package.json index 1c42c29..4de092d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gameforge", - "version": "0.1.24", + "version": "0.1.25", "description": "Lightweight HTML5 boilerplate for quick 2D game prototyping", "keywords": [ "lightweight",