gl2d
Version:
2D graphics package for WebGL
333 lines • 10.4 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
var struct_1 = require("gulp-structify/struct");
var buffer_1 = require("gulp-structify/buffer");
var mixin_1 = require("gulp-structify/mixin");
/**
* Point with x and y coordinates.
*/
var Point = (function () {
/**
* Point with x and y coordinates.
*/
function Point(x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
this.x = x;
this.y = y;
}
Point.midpoint = function (p1, p2) {
var point = new Point();
point.setMidpoint(p1, p2);
return point;
};
Point.create = function (other) {
var point = new Point();
point.set(other);
return point;
};
/**
* Sets this point to the midpoint of p1 and p2.
*/
Point.prototype.setMidpoint = function (p1, p2) {
this.x = 0.5 * (p1.x + p2.x);
this.y = 0.5 * (p1.y + p2.y);
};
/**
* Computes the distance between this point and the other point.
* @param other defaults to origin.
*/
Point.prototype.distance = function (other) {
return Math.sqrt(this.distance2(other));
};
/**
* Computes the distance squared from this point to the other point.
* @param other defaults to origin.
*/
Point.prototype.distance2 = function (other) {
var dx = other ? other.x - this.x : this.x;
var dy = other ? other.y - this.y : this.y;
return dx * dx + dy * dy;
};
/**
* Sets each component of this Point to that of the other Point.
*/
Point.prototype.set = function (other) {
this.x = other.x;
this.y = other.y;
};
/**
* Sets each component of this Point.
*/
Point.prototype.set$ = function (x, y) {
this.x = x;
this.y = y;
};
/**
* Sets each component of this Point to the specified scalar.
*/
Point.prototype.setScalar = function (k) {
this.x = k;
this.y = k;
};
/**
* Adds the other Point to this Point componentwise.
*/
Point.prototype.add = function (other) {
this.x += other.x;
this.y += other.y;
};
/**
* Adds the specified values to this Point componentwise.
*/
Point.prototype.add$ = function (x, y) {
this.x += x;
this.y += y;
};
/**
* Subtracts the other Point from this Point componentwise.
*/
Point.prototype.subtract = function (other) {
this.x -= other.x;
this.y -= other.y;
};
/**
* Subtracts the specified values from this Point componentwise.
*/
Point.prototype.subtract$ = function (x, y) {
this.x -= x;
this.y -= y;
};
/**
* Multiplies each component of this Point by the specified scalar.
*/
Point.prototype.mulScalar = function (k) {
this.x *= k;
this.y *= k;
};
/**
* Divides each component of this Point by the specified scalar.
*/
Point.prototype.divScalar = function (k) {
this.x /= k;
this.y /= k;
};
/**
* Checks if each component of this Point is exactly equal to that of the other Point.
*/
Point.prototype.equals = function (other) {
return this.x === other.x && this.y === other.y;
};
/**
* Checks if each component of this Point is exactly equal to the specified scalar.
*/
Point.prototype.equalsScalar = function (k) {
return this.x === k && this.y === k;
};
/**
* Checks if each component of this Point is approximately equal to that of the other Point.
*/
Point.prototype.epsilonEquals = function (other, e) {
return Math.abs(this.x - other.x) <= e && Math.abs(this.y - other.y) <= e;
};
/**
* Checks if each component of this Point is approximately equal to the specified scalar.
*/
Point.prototype.epsilonEqualsScalar = function (k, e) {
return Math.abs(this.x - k) <= e && Math.abs(this.y - k) <= e;
};
/**
* Returns a string representation of this Point.
*/
Point.prototype.toString = function () {
return "{ x: " + this.x + ", y: " + this.y + " }";
};
return Point;
}());
exports.Point = Point;
/**
* A Point backed by a Float32Array.
*/
var PointStruct = (function (_super) {
__extends(PointStruct, _super);
/**
* Creates a Point struct backed by the specified data.
*/
function PointStruct(data) {
if (data === void 0) { data = new Float32Array(2); }
return _super.call(this, data) || this;
}
PointStruct.midpoint = function (p1, p2) {
var point = new PointStruct();
point.setMidpoint(p1, p2);
return point;
};
PointStruct.create = function (other) {
var point = new PointStruct();
point.set(other);
return point;
};
PointStruct.create$ = function (x, y) {
var point = new PointStruct();
point.set$(x, y);
return point;
};
Object.defineProperty(PointStruct.prototype, "x", {
/**
* The X coordinate of this point.
*/
get: function () {
return this.data[0];
},
/**
* The X coordinate of this point.
*/
set: function (value) {
this.data[0] = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PointStruct.prototype, "y", {
/**
* The Y coordinate of this point.
*/
get: function () {
return this.data[1];
},
/**
* The Y coordinate of this point.
*/
set: function (value) {
this.data[1] = value;
},
enumerable: true,
configurable: true
});
return PointStruct;
}(struct_1.Struct));
exports.PointStruct = PointStruct;
mixin_1.applyMixins(PointStruct, Point);
/**
* A Point buffer backed by a Float32Array.
*/
var PointBuffer = (function (_super) {
__extends(PointBuffer, _super);
function PointBuffer() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Creates an empty Point buffer with the specified Point capacity.
*/
PointBuffer.create = function (capacity) {
return new PointBuffer(new Float32Array(capacity * 2));
};
Object.defineProperty(PointBuffer.prototype, "x", {
/**
* The X coordinate of this point.
*/
get: function () {
return this.data[this.dataPosition + 0];
},
/**
* The X coordinate of this point.
*/
set: function (value) {
this.data[this.dataPosition + 0] = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(PointBuffer.prototype, "y", {
/**
* The Y coordinate of this point.
*/
get: function () {
return this.data[this.dataPosition + 1];
},
/**
* The Y coordinate of this point.
*/
set: function (value) {
this.data[this.dataPosition + 1] = value;
},
enumerable: true,
configurable: true
});
/**
* Gets the number of properties in a Point, namely 2.
*/
PointBuffer.prototype.structLength = function () {
return 2;
};
/**
* Gets the components of the Point at the specified position of this buffer.
*/
PointBuffer.prototype.aget = function (position, dst) {
if (dst === void 0) {
dst = new Point();
}
;
var dataPos = position * this.structLength();
dst.x = this.data[dataPos++];
dst.y = this.data[dataPos++];
return dst;
};
/**
* Gets the components of the current Point, then moves to the next position of this buffer.
*/
PointBuffer.prototype.rget = function (dst) {
if (dst === void 0) {
dst = new Point();
}
;
dst.x = this.data[this.dataPosition++];
dst.y = this.data[this.dataPosition++];
return dst;
};
/**
* Sets each component of the Point at the specified position to that of the src Point.
*/
PointBuffer.prototype.aset = function (position, src) {
var dataPos = position * this.structLength();
this.data[dataPos++] = src.x;
this.data[dataPos++] = src.y;
};
/**
* Sets each component of the Point at the specified position.
*/
PointBuffer.prototype.aset$ = function (position, x, y) {
var dataPos = position * this.structLength();
this.data[dataPos++] = x;
this.data[dataPos++] = y;
};
/**
* Sets each component of the current Point to that of the src Point, then moves to the next position of this buffer.
*/
PointBuffer.prototype.rset = function (src) {
this.data[this.dataPosition++] = src.x;
this.data[this.dataPosition++] = src.y;
};
/**
* Sets each component of the current Point, then moves to the next position of this buffer.
*/
PointBuffer.prototype.rset$ = function (x, y) {
this.data[this.dataPosition++] = x;
this.data[this.dataPosition++] = y;
};
return PointBuffer;
}(buffer_1.StructBuffer));
exports.PointBuffer = PointBuffer;
mixin_1.applyMixins(PointBuffer, Point);
//# sourceMappingURL=point.js.map