Skip to content

Commit 4d185c9

Browse files
committedJul 16, 2024·
refactor: typescriptify reactangle and line
1 parent 6088afb commit 4d185c9

20 files changed

+433
-441
lines changed
 

‎eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export default tseslint.config(
179179
...jsDocConfig.rules,
180180
"jsdoc/require-jsdoc": "off",
181181
"jsdoc/no-defaults": "off",
182+
"jsdoc/require-returns": "off",
182183
},
183184
languageOptions: {
184185
parserOptions: {

‎packages/melonjs/src/camera/camera2d.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Vector2d, vector2dPool } from "../math/vector2d.ts";
22
import { Vector3d } from "../math/vector3d.ts";
33
import { Matrix2d } from "../math/matrix2d.ts";
44
import { Matrix3d } from "../math/matrix3d.ts";
5-
import Rect from "./../geometries/rectangle.js";
5+
import { Rect } from "./../geometries/rectangle.ts";
66
import { renderer } from "./../video/video.js";
77
import pool from "./../system/pooling.js";
88
import Renderable from "./../renderable/renderable.js";

‎packages/melonjs/src/geometries/line.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ export const linePool = createPool<
104104
return {
105105
instance: line,
106106
reset(x, y, points) {
107-
line.setShape(x, y, points);
107+
line.pos.set(x, y);
108+
line.setVertices(points);
108109
},
109110
};
110111
});

‎packages/melonjs/src/geometries/polygon.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createPool } from "../system/pool.ts";
55
import { XYPoint } from "../utils/types.ts";
66
import { earcut } from "./earcut.ts";
77

8-
type PolygonVertices =
8+
export type PolygonVertices =
99
| [XYPoint, XYPoint, XYPoint, ...XYPoint[]]
1010
| [Vector2d, Vector2d, Vector2d, ...Vector2d[]]
1111
| [number, number, number, number, number, number, ...number[]];
@@ -69,16 +69,16 @@ export class Polygon {
6969
/**
7070
* @param [x=0] - origin point of the Polygon
7171
* @param [y=0] - origin point of the Polygon
72-
* @param points - array of vector defining the Polygon
72+
* @param vertices - array of vector defining the Polygon
7373
*/
74-
constructor(x = 0, y = 0, points: PolygonVertices | LineVertices) {
75-
this.pos = vector2dPool.get();
74+
constructor(x = 0, y = 0, vertices: PolygonVertices | LineVertices) {
75+
this.pos = vector2dPool.get(x, y);
7676
this.points = [];
7777
this.edges = [];
7878
this.indices = [];
7979
this.normals = [];
8080
this._bounds = boundsPool.get();
81-
this.setShape(x, y, points);
81+
this.setVertices(vertices);
8282
}
8383

8484
/**
@@ -170,7 +170,7 @@ export class Polygon {
170170
* @param [v] - an optional point to rotate around
171171
* @returns Reference to this object for method chaining
172172
*/
173-
rotate(angle: number, v?: Vector2d | undefined) {
173+
rotate(angle: number, v?: Vector2d | XYPoint | undefined) {
174174
if (angle !== 0) {
175175
const points = this.points;
176176
const len = points.length;
@@ -459,13 +459,14 @@ export class Polygon {
459459

460460
export const polygonPool = createPool<
461461
Polygon,
462-
[x: number, y: number, points: PolygonVertices]
463-
>((x, y, points) => {
464-
const polygon = new Polygon(x, y, points);
462+
[x: number, y: number, vertices: PolygonVertices]
463+
>((x, y, vertices) => {
464+
const polygon = new Polygon(x, y, vertices);
465465
return {
466466
instance: polygon,
467467
reset(x, y, points) {
468-
polygon.setShape(x, y, points);
468+
polygon.pos.set(x, y);
469+
polygon.setVertices(points);
469470
},
470471
};
471472
});

0 commit comments

Comments
 (0)
Please sign in to comment.