UNPKG

convex-pixel

Version:

The library for creating pseudo 3d interactive scenes based on webgl

51 lines 1.31 kB
export class Rect { constructor(x = 0, y = 0, width = 0, height = 0) { this.x = x; this.y = y; this.width = width; this.height = height; } static get poolCount() { return this._pool.length; } static new(x = 0, y = 0, width = 0, height = 0) { if (Rect._pool.length > 0) { const rect = Rect._pool.pop(); if (rect) { return rect .setPosition(x, y) .setSize(width, height); } } return new Rect(x, y, width, height); } set(x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; return this; } setPosition(x, y) { this.x = x; this.y = y; return this; } setSize(width, height) { this.width = width; this.height = height; return this; } reset() { this.x = this.y = this.width = this.height; } free() { this.reset(); Rect._pool.push(this); } valueOf() { return { x: this.x, y: this.y, width: this.width, height: this.height }; } } Rect._pool = new Array(); //# sourceMappingURL=rect.js.map