From 41562237f0b21a84c78e5b2eb412df6152dcae7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Darida?= Date: Tue, 23 Sep 2025 21:31:48 +0200 Subject: [PATCH 1/3] feat: implement PointUtil.qerp function --- src/index.ts | 2 +- src/utils/PointUtil.ts | 40 +++++++++++++++++++++++++++++------ tests/utils/PointUtil.test.ts | 26 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index bc3d7d5..110497a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ export * as Pixi from 'pixi.js'; export * as PixiSound from '@pixi/sound'; -export { default as WebFontLoader} from 'webfontloader'; +export { default as WebFontLoader } from 'webfontloader'; export * from './animation'; export * from './events'; diff --git a/src/utils/PointUtil.ts b/src/utils/PointUtil.ts index d716bde..890fdcc 100644 --- a/src/utils/PointUtil.ts +++ b/src/utils/PointUtil.ts @@ -8,20 +8,48 @@ import * as MathUtil from './MathUtil'; * @param start The start point. * @param end The end point. * @param t The interpolation factor. + * @param result A `Point` object to store the result. * @returns A new `Point` representing the interpolated position. */ export function lerp( start: Point, end: Point, t: number, - point?: Point + result?: Point ): Point { - if (!point) { - point = new Point(); + if (!result) { + result = new Point(); } - point.x = MathUtil.lerp(start.x, end.x, t); - point.y = MathUtil.lerp(start.y, end.y, t); + result.x = MathUtil.lerp(start.x, end.x, t); + result.y = MathUtil.lerp(start.y, end.y, t); - return point; + return result; +} + +/** + * Quadratic interpolation between two `PIXI.Point` objects. + * + * @param start The start point. + * @param control The control point. + * @param end The end point. + * @param t The interpolation factor. + * @param result A `Point` object to store the result. + * @returns A new `Point` representing the interpolated position. + */ +export function qerp( + start: Point, + control: Point, + end: Point, + t: number, + result?: Point +): Point { + if (!result) { + 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; } diff --git a/tests/utils/PointUtil.test.ts b/tests/utils/PointUtil.test.ts index cc81b0e..968fbe1 100644 --- a/tests/utils/PointUtil.test.ts +++ b/tests/utils/PointUtil.test.ts @@ -27,4 +27,30 @@ describe('Test PointUtil functions', () => { expect(actual.x).toBe(5.1); expect(actual.y).toBe(-5.1); }); + + it('should compute quadratic interpolation between two numbers', () => { + const start = new Point(-5, 5); + const control = new Point(0, 0); + const end = new Point(5, -5); + + let actual = PointUtil.qerp(start, control, end, -0.01); + expect(actual.x).toBeCloseTo(-5.1); + expect(actual.y).toBeCloseTo(5.1); + + actual = PointUtil.qerp(start, control, end, 0); + expect(actual.x).toBe(-5); + expect(actual.y).toBe(5); + + actual = PointUtil.qerp(start, control, end, 0.5); + expect(actual.x).toBe(0); + expect(actual.y).toBe(0); + + PointUtil.qerp(start, control, end, 1, actual); + expect(actual.x).toBe(5); + expect(actual.y).toBe(-5); + + PointUtil.qerp(start, control, end, 1.01, actual); + expect(actual.x).toBeCloseTo(5.1); + expect(actual.y).toBeCloseTo(-5.1); + }); }); From 48954a86a2f17183415b39059ef7224562608e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Darida?= Date: Tue, 23 Sep 2025 21:31:54 +0200 Subject: [PATCH 2/3] chore(release): 0.1.24 --- 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 7e75602..205ee13 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.24](https://github.com/rdarida/gameforge/compare/v0.1.23...v0.1.24) (2025-09-23) + + +### Features + +* implement PointUtil.qerp function ([4156223](https://github.com/rdarida/gameforge/commit/41562237f0b21a84c78e5b2eb412df6152dcae7f)) + ### [0.1.23](https://github.com/rdarida/gameforge/compare/v0.1.22...v0.1.23) (2025-09-23) diff --git a/package-lock.json b/package-lock.json index bcf9a14..029a3cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gameforge", - "version": "0.1.23", + "version": "0.1.24", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gameforge", - "version": "0.1.23", + "version": "0.1.24", "license": "MIT", "dependencies": { "@pixi/sound": ">=5.2.3 <6.0.0", diff --git a/package.json b/package.json index e27111a..1c42c29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gameforge", - "version": "0.1.23", + "version": "0.1.24", "description": "Lightweight HTML5 boilerplate for quick 2D game prototyping", "keywords": [ "lightweight", From 49e36ab7f9ac7b16909b52487fa7abe7f688aa3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Darida?= Date: Tue, 23 Sep 2025 21:33:10 +0200 Subject: [PATCH 3/3] chore: update documentation of PointUtil functions --- src/utils/PointUtil.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/PointUtil.ts b/src/utils/PointUtil.ts index 890fdcc..a77f1d1 100644 --- a/src/utils/PointUtil.ts +++ b/src/utils/PointUtil.ts @@ -8,8 +8,8 @@ import * as MathUtil from './MathUtil'; * @param start The start point. * @param end The end point. * @param t The interpolation factor. - * @param result A `Point` object to store the result. - * @returns A new `Point` representing the interpolated position. + * @param result A `PIXI.Point` object to store the result. + * @returns A new `PIXI.Point` representing the interpolated position. */ export function lerp( start: Point, @@ -34,8 +34,8 @@ export function lerp( * @param control The control point. * @param end The end point. * @param t The interpolation factor. - * @param result A `Point` object to store the result. - * @returns A new `Point` representing the interpolated position. + * @param result A `PIXI.Point` object to store the result. + * @returns A new `PIXI.Point` representing the interpolated position. */ export function qerp( start: Point,