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.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)


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.23",
"version": "0.1.24",
"description": "Lightweight HTML5 boilerplate for quick 2D game prototyping",
"keywords": [
"lightweight",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
42 changes: 35 additions & 7 deletions src/utils/PointUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,48 @@ import * as MathUtil from './MathUtil';
* @param start The start point.
* @param end The end point.
* @param t The interpolation factor.
* @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,
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 `PIXI.Point` object to store the result.
* @returns A new `PIXI.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;
}
26 changes: 26 additions & 0 deletions tests/utils/PointUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});