UNPKG

convex-pixel

Version:

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

192 lines 5.79 kB
/** * Vector2D * Uses pooling for speed performance */ var Vector2D = /** @class */ (function () { function Vector2D(x, y) { if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } this.x = x; this.y = y; } Object.defineProperty(Vector2D, "poolCount", { get: function () { return this._pool.length; }, enumerable: true, configurable: true }); Vector2D.new = function (x, y) { if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } if (Vector2D._pool.length > 0) { var vect = Vector2D._pool.pop(); if (vect) { return vect.set(x, y); } } return new Vector2D(x, y); }; Vector2D.prototype.set = function (x, y) { this.x = x; this.y = y; return this; }; /** * @deprecated */ Vector2D.prototype.move = function (x, y) { this.x = x; this.y = y; return this; }; Vector2D.prototype.from = function (vector) { this.x = vector.x; this.y = vector.y; return this; }; Vector2D.prototype.free = function () { Vector2D._pool.push(this); }; Vector2D.prototype.valueOf = function () { return { x: this.x, y: this.y }; }; Vector2D.prototype.clone = function () { return Vector2D.new(this.x, this.y); }; Vector2D.prototype.add = function (vector, isClone) { if (isClone === void 0) { isClone = true; } if (!isClone) { this.x += vector.x; this.y += vector.y; return this; } return Vector2D.new(this.x + vector.x, this.y + vector.y); }; Vector2D.prototype.deduct = function (vector, isClone) { if (isClone === void 0) { isClone = true; } if (!isClone) { this.x -= vector.x; this.y -= vector.y; return this; } return Vector2D.new(this.x - vector.x, this.y - vector.y); }; Vector2D.prototype.measureDistance = function (vector, xAxis, yAxis) { if (xAxis === void 0) { xAxis = true; } if (yAxis === void 0) { yAxis = true; } var a = Math.max(this.x, vector.x) - Math.min(this.x, vector.x); var b = Math.max(this.y, vector.y) - Math.min(this.y, vector.y); if (xAxis && yAxis) return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); else if (xAxis) return a; else if (yAxis) return b; return 0; }; Vector2D.prototype.comparePoint = function (vector) { return this.x === vector.x && this.y === vector.y; }; Vector2D.prototype.empty = function () { this.x = this.y = 0; }; Vector2D._pool = new Array(); return Vector2D; }()); export { Vector2D }; // tslint:disable-next-line: max-classes-per-file var Vector3D = /** @class */ (function () { function Vector3D(x, y, z) { if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } if (z === void 0) { z = 0; } this.x = x; this.y = y; this.z = z; } Object.defineProperty(Vector3D, "poolCount", { get: function () { return this._pool.length; }, enumerable: true, configurable: true }); Vector3D.new = function (x, y, z) { if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } if (z === void 0) { z = 0; } if (Vector3D._pool.length > 0) { var vect = Vector3D._pool.pop(); if (vect) { return vect.set(x, y, z); } } return new Vector3D(x, y, z); }; Vector3D.prototype.set = function (x, y, z) { this.x = x; this.y = y; this.z = z; return this; }; Vector3D.prototype.free = function () { Vector3D._pool.push(this); }; Vector3D.prototype.valueOf = function () { return { x: this.x, y: this.y, z: this.z }; }; Vector3D._pool = new Array(); return Vector3D; }()); export { Vector3D }; // tslint:disable-next-line: max-classes-per-file var Vector4D = /** @class */ (function () { function Vector4D(x, y, z, t) { if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } if (z === void 0) { z = 0; } if (t === void 0) { t = 0; } this.x = x; this.y = y; this.z = z; this.t = t; } Object.defineProperty(Vector4D, "poolCount", { get: function () { return this._pool.length; }, enumerable: true, configurable: true }); Vector4D.new = function (x, y, z, t) { if (x === void 0) { x = 0; } if (y === void 0) { y = 0; } if (z === void 0) { z = 0; } if (t === void 0) { t = 0; } if (Vector4D._pool.length > 0) { var vect = Vector4D._pool.pop(); if (vect) { return vect.set(x, y, z, t); } } return new Vector4D(x, y, z, t); }; Vector4D.prototype.set = function (x, y, z, t) { this.x = x; this.y = y; this.z = z; this.t = t; return this; }; Vector4D.prototype.free = function () { Vector4D._pool.push(this); }; Vector4D.prototype.valueOf = function () { return { x: this.x, y: this.y, z: this.z, t: this.t }; }; Vector4D._pool = new Array(); return Vector4D; }()); export { Vector4D }; //# sourceMappingURL=vector.js.map