convex-pixel
Version:
The library for creating pseudo 3d interactive scenes based on webgl
65 lines • 1.98 kB
JavaScript
var Rect = /** @class */ (function () {
function Rect(x, y, width, height) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (width === void 0) { width = 0; }
if (height === void 0) { height = 0; }
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
Object.defineProperty(Rect, "poolCount", {
get: function () {
return this._pool.length;
},
enumerable: true,
configurable: true
});
Rect.new = function (x, y, width, height) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (width === void 0) { width = 0; }
if (height === void 0) { height = 0; }
if (Rect._pool.length > 0) {
var rect = Rect._pool.pop();
if (rect) {
return rect
.setPosition(x, y)
.setSize(width, height);
}
}
return new Rect(x, y, width, height);
};
Rect.prototype.set = function (x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
return this;
};
Rect.prototype.setPosition = function (x, y) {
this.x = x;
this.y = y;
return this;
};
Rect.prototype.setSize = function (width, height) {
this.width = width;
this.height = height;
return this;
};
Rect.prototype.reset = function () {
this.x = this.y = this.width = this.height;
};
Rect.prototype.free = function () {
this.reset();
Rect._pool.push(this);
};
Rect.prototype.valueOf = function () {
return { x: this.x, y: this.y, width: this.width, height: this.height };
};
Rect._pool = new Array();
return Rect;
}());
export { Rect };
//# sourceMappingURL=rect.js.map