@@ -5,7 +5,7 @@ import { createPool } from "../system/pool.ts";
5
5
import { XYPoint } from "../utils/types.ts" ;
6
6
import { earcut } from "./earcut.ts" ;
7
7
8
- type PolygonVertices =
8
+ export type PolygonVertices =
9
9
| [ XYPoint , XYPoint , XYPoint , ...XYPoint [ ] ]
10
10
| [ Vector2d , Vector2d , Vector2d , ...Vector2d [ ] ]
11
11
| [ number , number , number , number , number , number , ...number [ ] ] ;
@@ -69,16 +69,16 @@ export class Polygon {
69
69
/**
70
70
* @param [x=0] - origin point of the Polygon
71
71
* @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
73
73
*/
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 ) ;
76
76
this . points = [ ] ;
77
77
this . edges = [ ] ;
78
78
this . indices = [ ] ;
79
79
this . normals = [ ] ;
80
80
this . _bounds = boundsPool . get ( ) ;
81
- this . setShape ( x , y , points ) ;
81
+ this . setVertices ( vertices ) ;
82
82
}
83
83
84
84
/**
@@ -170,7 +170,7 @@ export class Polygon {
170
170
* @param [v] - an optional point to rotate around
171
171
* @returns Reference to this object for method chaining
172
172
*/
173
- rotate ( angle : number , v ?: Vector2d | undefined ) {
173
+ rotate ( angle : number , v ?: Vector2d | XYPoint | undefined ) {
174
174
if ( angle !== 0 ) {
175
175
const points = this . points ;
176
176
const len = points . length ;
@@ -459,13 +459,14 @@ export class Polygon {
459
459
460
460
export const polygonPool = createPool <
461
461
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 ) ;
465
465
return {
466
466
instance : polygon ,
467
467
reset ( x , y , points ) {
468
- polygon . setShape ( x , y , points ) ;
468
+ polygon . pos . set ( x , y ) ;
469
+ polygon . setVertices ( points ) ;
469
470
} ,
470
471
} ;
471
472
} ) ;
0 commit comments