Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 6 additions & 4 deletions src/animation/Tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class Tween<T> {
private _delay: number;
private _transition: Transition;
private _onComplete: () => void;
private _ticker: Ticker;
private _startValues: Map<string, number>;
private _endValues: Map<string, number>;
private readonly _ticker: Ticker;
private readonly _startValues: Map<string, number>;
private readonly _endValues: Map<string, number>;
private _elapsedTime: number;
private _isComplete: boolean;

Expand Down Expand Up @@ -228,7 +228,9 @@ export class Tween<T> {
* Update function called on every ticker frame.
* Handles time progression, easing, and property interpolation.
*/
private update: TickerCallback<this> = <K extends keyof T>(): void => {
private readonly update: TickerCallback<this> = <
K extends keyof T
>(): void => {
this._elapsedTime += this._ticker.deltaMS;

if (this._elapsedTime < 0) return;
Expand Down
23 changes: 15 additions & 8 deletions src/utils/PointUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
10 changes: 9 additions & 1 deletion tests/utils/PointUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
});