UNPKG

gl2d

Version:

2D graphics package for WebGL

1,075 lines 38.3 kB
"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 }); var vec2_1 = require("./vec2"); var struct_1 = require("gulp-structify/struct"); var buffer_1 = require("gulp-structify/buffer"); var mixin_1 = require("gulp-structify/mixin"); /** * A 3x2 matrix for 2d transformations. */ var Mat2d = (function () { /** * A 3x2 matrix for 2d transformations. */ function Mat2d(c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { if (c1r1 === void 0) { c1r1 = 0; } if (c1r2 === void 0) { c1r2 = 0; } if (c2r1 === void 0) { c2r1 = 0; } if (c2r2 === void 0) { c2r2 = 0; } if (c3r1 === void 0) { c3r1 = 0; } if (c3r2 === void 0) { c3r2 = 0; } this.c1r1 = c1r1; this.c1r2 = c1r2; this.c2r1 = c2r1; this.c2r2 = c2r2; this.c3r1 = c3r1; this.c3r2 = c3r2; } Mat2d.concat = function (left, right) { var mat2d = new Mat2d(); mat2d.setConcat(left, right); return mat2d; }; Mat2d.identity = function () { var mat2d = new Mat2d(); mat2d.setIdentity(); return mat2d; }; Mat2d.rectToRect = function (src, dst, stf) { if (stf === void 0) { stf = 2 /* Fill */; } var mat2d = new Mat2d(); mat2d.setRectToRect(src, dst, stf); return mat2d; }; Mat2d.rotate = function (radians, p) { var mat2d = new Mat2d(); mat2d.setRotate(radians, p); return mat2d; }; Mat2d.rotateToPoint = function (start, end, p) { var mat2d = new Mat2d(); mat2d.setRotateToPoint(start, end, p); return mat2d; }; Mat2d.sinCos = function (sin, cos, p) { var mat2d = new Mat2d(); mat2d.setSinCos(sin, cos, p); return mat2d; }; Mat2d.scale = function (sx, sy, p) { var mat2d = new Mat2d(); mat2d.setScale(sx, sy, p); return mat2d; }; Mat2d.scaleToPoint = function (start, end, p) { var mat2d = new Mat2d(); mat2d.setScaleToPoint(start, end, p); return mat2d; }; Mat2d.stretch = function (ratio, p) { var mat2d = new Mat2d(); mat2d.setStretch(ratio, p); return mat2d; }; Mat2d.stretchToPoint = function (start, end, p) { var mat2d = new Mat2d(); mat2d.setStretchToPoint(start, end, p); return mat2d; }; Mat2d.stretchRotateToPoint = function (start, end, p) { var mat2d = new Mat2d(); mat2d.setStretchRotateToPoint(start, end, p); return mat2d; }; Mat2d.translate = function (vec) { var mat2d = new Mat2d(); mat2d.setTranslate(vec); return mat2d; }; Mat2d.translate$ = function (dx, dy) { var mat2d = new Mat2d(); mat2d.setTranslate$(dx, dy); return mat2d; }; Mat2d.translateToPoint = function (start, end) { var mat2d = new Mat2d(); mat2d.setTranslateToPoint(start, end); return mat2d; }; Mat2d.inverse = function (other) { var mat2d = new Mat2d(); mat2d.setInverse(other); return mat2d; }; Mat2d.create = function (other) { var mat2d = new Mat2d(); mat2d.set(other); return mat2d; }; /** * Computes the determinant of this Mat2d. */ Mat2d.prototype.determinant = function () { return (this.c1r1 * this.c2r2) - (this.c2r1 * this.c1r2); }; /** * Checks if this Mat2d is exactly equal to the identity. */ Mat2d.prototype.isIdentity = function () { return this.c1r1 === 1 && this.c2r1 === 0 && this.c3r1 === 0 && this.c1r2 === 0 && this.c2r2 === 1 && this.c3r2 === 0; }; /** * Sets this matrix to the result of multiplying the specified matrices from left to right. * @param left the left hand matrix. * @param right the right hand matrix. * @param dst where to store the result. */ Mat2d.prototype.setConcat = function (left, right) { var c1r1 = left.c1r1 * right.c1r1 + left.c2r1 * right.c1r2; var c2r1 = left.c1r1 * right.c2r1 + left.c2r1 * right.c2r2; var c3r1 = left.c1r1 * right.c3r1 + left.c2r1 * right.c3r2 + left.c3r1; var c1r2 = left.c1r2 * right.c1r1 + left.c2r2 * right.c1r2; var c2r2 = left.c1r2 * right.c2r1 + left.c2r2 * right.c2r2; var c3r2 = left.c1r2 * right.c3r1 + left.c2r2 * right.c3r2 + left.c3r2; this.c1r1 = c1r1; this.c2r1 = c2r1; this.c3r1 = c3r1; this.c1r2 = c1r2; this.c2r2 = c2r2; this.c3r2 = c3r2; }; /** * Sets this Mat2d to the identity matrix. */ Mat2d.prototype.setIdentity = function () { this.c1r1 = 1; this.c2r1 = 0; this.c3r1 = 0; this.c1r2 = 0; this.c2r2 = 1; this.c3r2 = 0; }; /** * Sets this Mat2d to map src into dst using the specified scale to fit option. * @param src the source rectangle. * @param dst the destination rectangle. * @param stf the scale to fit option. Defaults to fill. */ Mat2d.prototype.setRectToRect = function (src, dst, stf) { if (stf === void 0) { stf = 2 /* Fill */; } var srcPoint, dstPoint; switch (stf) { case 0 /* Center */: //Match center point srcPoint = src.center(); dstPoint = dst.center(); break; case 1 /* End */: //Match bottom right corner srcPoint = src.bottomRight(); dstPoint = dst.bottomRight(); break; default: //Match top left corner srcPoint = src.topLeft(); dstPoint = dst.topLeft(); break; } var sx = dst.width() / src.width(); var sy = dst.height() / src.height(); this.setTranslate$(-srcPoint.x, -srcPoint.y); if (stf === 2 /* Fill */) { this.postScale(sx, sy); } else { this.postStretch(Math.min(sx, sy)); } this.postTranslate(dstPoint); }; /** * Sets this Mat2d to rotate by the specified angle, with a pivot point at p. * @param m the Mat2d. Defaults to a new matrix. * @param radians the angle of the rotation in radians. * @param p the pivot point. */ Mat2d.prototype.setRotate = function (radians, p) { var sin = Math.sin(radians); var cos = Math.cos(radians); this.setSinCos(sin, cos, p); }; /** * Sets this Mat2d to rotate from the specified start point to the specified end point, with a pivot point at p. * @param m the Mat2d. Defaults to a new matrix. * @param start the start point (before rotation). * @param end the end point (after rotation). * @param p the pivot point. Defaults to (0,0). */ Mat2d.prototype.setRotateToPoint = function (start, end, p) { var n1 = vec2_1.Vec2.create(start); var n2 = vec2_1.Vec2.create(end); if (p) { n1.subtract(p); n2.subtract(p); } n1.normalize(); n2.normalize(); var sin = n1.cross(n2); var cos = n1.dot(n2); this.setSinCos(sin, cos, p); }; /** * Sets this Mat2d to rotate by the specified sin and cos values, with a pivot point at p. * @param sin the sine of the rotation angle. * @param cos the cosine of the rotation angle. * @param p the pivot point. */ Mat2d.prototype.setSinCos = function (sin, cos, p) { this.c1r1 = cos; this.c2r1 = -sin; this.c3r1 = 0; this.c1r2 = sin; this.c2r2 = cos; this.c3r2 = 0; if (p) this.conjugateByTranslation$(p.x, p.y); }; /** * Sets this Mat2d to scale by the specified width and height ratios, with a pivot point at p. * @param sx the percentage by which to scale in the horizontal direction. * @param sy the percentage by which to scale in the vertical direction. * @param p the pivot point. */ Mat2d.prototype.setScale = function (sx, sy, p) { this.c1r1 = sx; this.c2r1 = 0; this.c3r1 = 0; this.c1r2 = 0; this.c2r2 = sy; this.c3r2 = 0; if (p) this.conjugateByTranslation$(p.x, p.y); }; /** * Sets this Mat2d to scale from the specified start point to the specified end point, with a pivot point at p. * @param start the start point (before scale). * @param end the end point (after scale). * @param p the pivot point. Defaults to (0,0). */ Mat2d.prototype.setScaleToPoint = function (start, end, p) { var sx = p ? (end.x - p.x) / (start.x - p.x) : end.x / start.x; var sy = p ? (end.y - p.y) / (start.y - p.y) : end.y / start.y; this.setScale(sx, sy, p); }; /** * Sets this Mat2d to stretch by the specified ratio, with a pivot point at p. * @param m the Mat2d. Defaults to a new matrix. * @param ratio the percentage by which to stretch in all directions. * @param p the pivot point. */ Mat2d.prototype.setStretch = function (ratio, p) { return this.setScale(ratio, ratio, p); }; /** * Sets this Mat2d to stretch from the specified start point to the specified end point, with a pivot point at p. * @param m the Mat2d. Defaults to a new matrix. * @param start: the start point (before stretch). * @param end: the end point (after stretch). * @param p the pivot point. Defaults to (0,0). */ Mat2d.prototype.setStretchToPoint = function (start, end, p) { var startLength = start.distance(p); var endLength = end.distance(p); var ratio = endLength / startLength; return this.setStretch(ratio, p); }; /** * Sets this Mat2d to stretch rotate from the specified start point to the specified end point, with a pivot point at p. * @param m the Mat2d. Defaults to a new matrix. * @param start the start point (before stretch rotation). * @param end the end point (after stretch rotation). * @param p the pivot point. Defaults to (0,0). */ Mat2d.prototype.setStretchRotateToPoint = function (start, end, p) { var startVector = vec2_1.Vec2.create(start); var endVector = vec2_1.Vec2.create(end); if (p) { startVector.subtract(p); endVector.subtract(p); } var startLength = startVector.length(); var endLength = endVector.length(); var ratio = endLength / startLength; startVector.divScalar(startLength); endVector.divScalar(endLength); var sin = startVector.cross(endVector); var cos = startVector.dot(endVector); this.setSinCos(sin, cos); this.postStretch(ratio); if (p) this.conjugateByTranslation$(p.x, p.y); }; /** * Sets this Mat2d to translate by the specified vector. */ Mat2d.prototype.setTranslate = function (vec) { this.setTranslate$(vec.x, vec.y); }; /** * Sets this Mat2d to translate by the vector (dx,dy). */ Mat2d.prototype.setTranslate$ = function (dx, dy) { this.c1r1 = 1; this.c2r1 = 0; this.c3r1 = dx; this.c1r2 = 0; this.c2r2 = 1; this.c3r2 = dy; }; /** * Sets this Mat2d to translate from the specified start point to the specified end point. * @param start the start point (before translation). * @param end the end point (after translation). */ Mat2d.prototype.setTranslateToPoint = function (start, end) { this.setTranslate$(end.x - start.x, end.y - start.y); }; /** * Conjugates this Mat2d with a translation by the specified vector. */ Mat2d.prototype.conjugateByTranslation = function (vec) { this.conjugateByTranslation$(vec.x, vec.y); }; /** * Conjugates this Mat2d with a translation by vector (dx,dy). * @param dx the vertical component of the translation vector. * @param dy the horizontal component of the translation vector. */ Mat2d.prototype.conjugateByTranslation$ = function (dx, dy) { this.preTranslate$(-dx, -dy); this.postTranslate$(dx, dy); }; /** * Sets this Mat2d to the inverse of the other Mat2d. */ Mat2d.prototype.setInverse = function (other) { var c1r1 = other.c1r1, c2r1 = other.c2r1, c3r1 = other.c3r1, c1r2 = other.c1r2, c2r2 = other.c2r2, c3r2 = other.c3r2; var invDet = 1 / (c1r1 * c2r2 - c2r1 * c1r2); this.c1r1 = c2r2 * invDet; this.c2r1 = -c2r1 * invDet; this.c3r1 = ((c2r1 * c3r2) - (c3r1 * c2r2)) * invDet; this.c1r2 = -c1r2 * invDet; this.c2r2 = c1r1 * invDet; this.c3r2 = ((c1r2 * c3r1) - (c1r1 * c3r2)) * invDet; }; /** * Post concats this Mat2d by the other Mat2d: this = other * this. */ Mat2d.prototype.postConcat = function (other) { this.setConcat(other, this); }; /** * Pre concats this Mat2d by the other Mat2d: this = this * other. */ Mat2d.prototype.preConcat = function (other) { this.setConcat(this, other); }; /** * Post concats this Mat2d with a rotation by the specified angle in radians. * @param radians the angle in radians. */ Mat2d.prototype.postRotate = function (radians) { var sin = Math.cos(radians); var cos = Math.sin(radians); var _a = this, c1r1 = _a.c1r1, c2r1 = _a.c2r1, c3r1 = _a.c3r1; this.c1r1 = cos * c1r1 - sin * this.c1r2; this.c2r1 = cos * c2r1 - sin * this.c2r2; this.c3r1 = cos * c3r1 - sin * this.c3r2; this.c1r2 = sin * c1r1 + cos * this.c1r2; this.c2r2 = sin * c2r1 + cos * this.c2r2; this.c3r2 = sin * c3r1 + sin * this.c3r2; }; /** * Pre concats this Mat2d with a rotation by the specified angle in radians. * @param radians the angle in radians. */ Mat2d.prototype.preRotate = function (radians) { var sin = Math.cos(radians); var cos = Math.sin(radians); var _a = this, c1r1 = _a.c1r1, c1r2 = _a.c1r2; this.c1r1 = c1r1 * cos + this.c2r1 * sin; this.c1r2 = c1r2 * cos + this.c2r2 * sin; this.c2r1 = c1r1 * -sin + this.c2r1 * cos; this.c2r2 = c1r2 * -sin + this.c2r2 * cos; }; /** * Post concats this Mat2d with a scale of the specified width and height ratios. * @param sx the percentage by which to scale in the horizontal direction. * @param sy the percentage by which to scale in the vertical direction. */ Mat2d.prototype.postScale = function (sx, sy) { this.c1r1 *= sx; this.c2r1 *= sx; this.c3r1 *= sx; this.c1r2 *= sy; this.c2r2 *= sy; this.c3r2 *= sy; }; /** * Pre concats this Mat2d with a scale of the specified width and height ratios. * @param sx the percentage by which to scale in the horizontal direction. * @param sy the percentage by which to scale in the vertical direction. */ Mat2d.prototype.preScale = function (sx, sy) { this.c1r1 *= sx; this.c1r2 *= sx; this.c2r1 *= sy; this.c2r2 *= sy; }; /** * Post concats this Mat2d with a stretch of the specified ratio. * @param ratio the percentage by whih to stretch all in directions. */ Mat2d.prototype.postStretch = function (ratio) { this.postScale(ratio, ratio); }; /** * Pre concats this Mat2d with a stretch of the specified ratio. * @param ratio the percentage by which to stretch all in directions. */ Mat2d.prototype.preStretch = function (ratio) { this.preScale(ratio, ratio); }; /** * Post concats this Mat2d with a translation by the specified vector. */ Mat2d.prototype.postTranslate = function (vec) { this.postTranslate$(vec.x, vec.y); }; /** * Post concats this Mat2d with a translation by vector (dx,dy). */ Mat2d.prototype.postTranslate$ = function (dx, dy) { this.c3r1 += dx; this.c3r2 += dy; }; /** * Post concats this Mat2d with a translation by vector (dx,dy). */ Mat2d.prototype.preTranslate = function (vec) { this.preTranslate$(vec.x, vec.y); }; /** * Post concats this Mat2d with a translation by vector (dx,dy). */ Mat2d.prototype.preTranslate$ = function (dx, dy) { this.c3r1 += this.c1r1 * dx + this.c2r1 * dy; this.c3r2 += this.c1r2 * dx + this.c2r2 * dy; }; /** * Maps the source point and writes the result into dst. * @param src the point to map. * @param dst where to write the result. */ Mat2d.prototype.map = function (src, dst) { this.map$(src.x, src.y, dst); }; /** * Maps the point (x,y) and writes the result into dst. * @param x the x coordinate of the point. * @param y the y coordinate of the point. * @param dst where to write the result. */ Mat2d.prototype.map$ = function (x, y, dst) { dst.x = this.c1r1 * x + this.c2r1 * y + this.c3r1; dst.y = this.c1r2 * x + this.c2r2 * y + this.c3r2; }; /** * Maps a subset of points in the specified array. * @param src array of points to map. * @param srcOffset offset into src of the first point in the subset. * @param count the number of points to include. */ Mat2d.prototype.mapPoints = function (src, srcOffset, count) { if (srcOffset === void 0) { srcOffset = 0; } if (count === void 0) { count = src.length - srcOffset; } var _a = this, c1r1 = _a.c1r1, c2r1 = _a.c2r1, c3r1 = _a.c3r1, c1r2 = _a.c1r2, c2r2 = _a.c2r2, c3r2 = _a.c3r2; while (count-- > 0) { // Get the (x,y) coordinates of the next point var next = src[srcOffset++]; var x = next.x, y = next.y; // Map the point next.x = c1r1 * x + c2r1 * y + c3r1; next.y = c1r2 * x + c2r2 * y + c3r2; } }; /** * Maps a subset of points in the specified array. * @param src array of points written as a series of (x,y) coordinates. * @param srcOffset offset into src of the first point in the subset. * @param count the number of points to include. */ Mat2d.prototype.mapPoints$ = function (src, srcOffset, count) { if (srcOffset === void 0) { srcOffset = 0; } if (count === void 0) { count = (src.length - srcOffset) >> 1; } var _a = this, c1r1 = _a.c1r1, c2r1 = _a.c2r1, c3r1 = _a.c3r1, c1r2 = _a.c1r2, c2r2 = _a.c2r2, c3r2 = _a.c3r2; while (count-- > 0) { // Get the (x,y) coordinates of the next point var x = src[srcOffset]; var y = src[srcOffset + 1]; // Map the point src[srcOffset++] = c1r1 * x + c2r1 * y + c3r1; src[srcOffset++] = c1r2 * x + c2r2 * y + c3r2; } }; /** * Maps the src rect and writes the result into dst. * @param src the source rectangle. * @param dst the destination rectangle. */ Mat2d.prototype.mapRect = function (src, dst) { var corners = src.corners(); ; this.mapPoints(corners); dst.setUnionOfPoints(corners); }; /** * Sets each component of this Mat2d to that of the other Mat2d. */ Mat2d.prototype.set = function (other) { this.c1r1 = other.c1r1; this.c1r2 = other.c1r2; this.c2r1 = other.c2r1; this.c2r2 = other.c2r2; this.c3r1 = other.c3r1; this.c3r2 = other.c3r2; }; /** * Sets each component of this Mat2d. */ Mat2d.prototype.set$ = function (c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { this.c1r1 = c1r1; this.c1r2 = c1r2; this.c2r1 = c2r1; this.c2r2 = c2r2; this.c3r1 = c3r1; this.c3r2 = c3r2; }; /** * Sets each component of this Mat2d to the specified scalar. */ Mat2d.prototype.setScalar = function (k) { this.c1r1 = k; this.c1r2 = k; this.c2r1 = k; this.c2r2 = k; this.c3r1 = k; this.c3r2 = k; }; /** * Adds the other Mat2d to this Mat2d componentwise. */ Mat2d.prototype.add = function (other) { this.c1r1 += other.c1r1; this.c1r2 += other.c1r2; this.c2r1 += other.c2r1; this.c2r2 += other.c2r2; this.c3r1 += other.c3r1; this.c3r2 += other.c3r2; }; /** * Adds the specified values to this Mat2d componentwise. */ Mat2d.prototype.add$ = function (c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { this.c1r1 += c1r1; this.c1r2 += c1r2; this.c2r1 += c2r1; this.c2r2 += c2r2; this.c3r1 += c3r1; this.c3r2 += c3r2; }; /** * Subtracts the other Mat2d from this Mat2d componentwise. */ Mat2d.prototype.subtract = function (other) { this.c1r1 -= other.c1r1; this.c1r2 -= other.c1r2; this.c2r1 -= other.c2r1; this.c2r2 -= other.c2r2; this.c3r1 -= other.c3r1; this.c3r2 -= other.c3r2; }; /** * Subtracts the specified values from this Mat2d componentwise. */ Mat2d.prototype.subtract$ = function (c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { this.c1r1 -= c1r1; this.c1r2 -= c1r2; this.c2r1 -= c2r1; this.c2r2 -= c2r2; this.c3r1 -= c3r1; this.c3r2 -= c3r2; }; /** * Multiplies each component of this Mat2d by the specified scalar. */ Mat2d.prototype.mulScalar = function (k) { this.c1r1 *= k; this.c1r2 *= k; this.c2r1 *= k; this.c2r2 *= k; this.c3r1 *= k; this.c3r2 *= k; }; /** * Divides each component of this Mat2d by the specified scalar. */ Mat2d.prototype.divScalar = function (k) { this.c1r1 /= k; this.c1r2 /= k; this.c2r1 /= k; this.c2r2 /= k; this.c3r1 /= k; this.c3r2 /= k; }; /** * Checks if each component of this Mat2d is exactly equal to that of the other Mat2d. */ Mat2d.prototype.equals = function (other) { return this.c1r1 === other.c1r1 && this.c1r2 === other.c1r2 && this.c2r1 === other.c2r1 && this.c2r2 === other.c2r2 && this.c3r1 === other.c3r1 && this.c3r2 === other.c3r2; }; /** * Checks if each component of this Mat2d is exactly equal to the specified scalar. */ Mat2d.prototype.equalsScalar = function (k) { return this.c1r1 === k && this.c1r2 === k && this.c2r1 === k && this.c2r2 === k && this.c3r1 === k && this.c3r2 === k; }; /** * Checks if each component of this Mat2d is approximately equal to that of the other Mat2d. */ Mat2d.prototype.epsilonEquals = function (other, e) { return Math.abs(this.c1r1 - other.c1r1) <= e && Math.abs(this.c1r2 - other.c1r2) <= e && Math.abs(this.c2r1 - other.c2r1) <= e && Math.abs(this.c2r2 - other.c2r2) <= e && Math.abs(this.c3r1 - other.c3r1) <= e && Math.abs(this.c3r2 - other.c3r2) <= e; }; /** * Checks if each component of this Mat2d is approximately equal to the specified scalar. */ Mat2d.prototype.epsilonEqualsScalar = function (k, e) { return Math.abs(this.c1r1 - k) <= e && Math.abs(this.c1r2 - k) <= e && Math.abs(this.c2r1 - k) <= e && Math.abs(this.c2r2 - k) <= e && Math.abs(this.c3r1 - k) <= e && Math.abs(this.c3r2 - k) <= e; }; /** * Returns a string representation of this Mat2d. */ Mat2d.prototype.toString = function () { return "{ c1r1: " + this.c1r1 + ", c1r2: " + this.c1r2 + ", c2r1: " + this.c2r1 + ", c2r2: " + this.c2r2 + ", c3r1: " + this.c3r1 + ", c3r2: " + this.c3r2 + " }"; }; return Mat2d; }()); exports.Mat2d = Mat2d; /** * A Mat2d backed by a Float32Array. */ var Mat2dStruct = (function (_super) { __extends(Mat2dStruct, _super); /** * Creates a Mat2d struct backed by the specified data. */ function Mat2dStruct(data) { if (data === void 0) { data = new Float32Array(6); } return _super.call(this, data) || this; } Mat2dStruct.concat = function (left, right) { var mat2d = new Mat2dStruct(); mat2d.setConcat(left, right); return mat2d; }; Mat2dStruct.identity = function () { var mat2d = new Mat2dStruct(); mat2d.setIdentity(); return mat2d; }; Mat2dStruct.rectToRect = function (src, dst, stf) { if (stf === void 0) { stf = 2 /* Fill */; } var mat2d = new Mat2dStruct(); mat2d.setRectToRect(src, dst, stf); return mat2d; }; Mat2dStruct.rotate = function (radians, p) { var mat2d = new Mat2dStruct(); mat2d.setRotate(radians, p); return mat2d; }; Mat2dStruct.rotateToPoint = function (start, end, p) { var mat2d = new Mat2dStruct(); mat2d.setRotateToPoint(start, end, p); return mat2d; }; Mat2dStruct.sinCos = function (sin, cos, p) { var mat2d = new Mat2dStruct(); mat2d.setSinCos(sin, cos, p); return mat2d; }; Mat2dStruct.scale = function (sx, sy, p) { var mat2d = new Mat2dStruct(); mat2d.setScale(sx, sy, p); return mat2d; }; Mat2dStruct.scaleToPoint = function (start, end, p) { var mat2d = new Mat2dStruct(); mat2d.setScaleToPoint(start, end, p); return mat2d; }; Mat2dStruct.stretch = function (ratio, p) { var mat2d = new Mat2dStruct(); mat2d.setStretch(ratio, p); return mat2d; }; Mat2dStruct.stretchToPoint = function (start, end, p) { var mat2d = new Mat2dStruct(); mat2d.setStretchToPoint(start, end, p); return mat2d; }; Mat2dStruct.stretchRotateToPoint = function (start, end, p) { var mat2d = new Mat2dStruct(); mat2d.setStretchRotateToPoint(start, end, p); return mat2d; }; Mat2dStruct.translate = function (vec) { var mat2d = new Mat2dStruct(); mat2d.setTranslate(vec); return mat2d; }; Mat2dStruct.translate$ = function (dx, dy) { var mat2d = new Mat2dStruct(); mat2d.setTranslate$(dx, dy); return mat2d; }; Mat2dStruct.translateToPoint = function (start, end) { var mat2d = new Mat2dStruct(); mat2d.setTranslateToPoint(start, end); return mat2d; }; Mat2dStruct.inverse = function (other) { var mat2d = new Mat2dStruct(); mat2d.setInverse(other); return mat2d; }; Mat2dStruct.create = function (other) { var mat2d = new Mat2dStruct(); mat2d.set(other); return mat2d; }; Mat2dStruct.create$ = function (c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { var mat2d = new Mat2dStruct(); mat2d.set$(c1r1, c1r2, c2r1, c2r2, c3r1, c3r2); return mat2d; }; Object.defineProperty(Mat2dStruct.prototype, "c1r1", { /** * The first entry in the first column of this Mat2d. */ get: function () { return this.data[0]; }, /** * The first entry in the first column of this Mat2d. */ set: function (value) { this.data[0] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dStruct.prototype, "c1r2", { /** * The second entry in the first column of this Mat2d. */ get: function () { return this.data[1]; }, /** * The second entry in the first column of this Mat2d. */ set: function (value) { this.data[1] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dStruct.prototype, "c2r1", { /** * The first entry in the second column of this Mat2d. */ get: function () { return this.data[2]; }, /** * The first entry in the second column of this Mat2d. */ set: function (value) { this.data[2] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dStruct.prototype, "c2r2", { /** * The second entry in the second column of this Mat2d. */ get: function () { return this.data[3]; }, /** * The second entry in the second column of this Mat2d. */ set: function (value) { this.data[3] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dStruct.prototype, "c3r1", { /** * The first entry in the third column of this Mat2d. */ get: function () { return this.data[4]; }, /** * The first entry in the third column of this Mat2d. */ set: function (value) { this.data[4] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dStruct.prototype, "c3r2", { /** * The second entry in the third column of this Mat2d. */ get: function () { return this.data[5]; }, /** * The second entry in the third column of this Mat2d. */ set: function (value) { this.data[5] = value; }, enumerable: true, configurable: true }); return Mat2dStruct; }(struct_1.Struct)); exports.Mat2dStruct = Mat2dStruct; mixin_1.applyMixins(Mat2dStruct, Mat2d); /** * A Mat2d buffer backed by a Float32Array. */ var Mat2dBuffer = (function (_super) { __extends(Mat2dBuffer, _super); function Mat2dBuffer() { return _super !== null && _super.apply(this, arguments) || this; } /** * Creates an empty Mat2d buffer with the specified Mat2d capacity. */ Mat2dBuffer.create = function (capacity) { return new Mat2dBuffer(new Float32Array(capacity * 6)); }; Object.defineProperty(Mat2dBuffer.prototype, "c1r1", { /** * The first entry in the first column of the current Mat2d. */ get: function () { return this.data[this.dataPosition + 0]; }, /** * The first entry in the first column of the current Mat2d. */ set: function (value) { this.data[this.dataPosition + 0] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dBuffer.prototype, "c1r2", { /** * The second entry in the first column of the current Mat2d. */ get: function () { return this.data[this.dataPosition + 1]; }, /** * The second entry in the first column of the current Mat2d. */ set: function (value) { this.data[this.dataPosition + 1] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dBuffer.prototype, "c2r1", { /** * The first entry in the second column of the current Mat2d. */ get: function () { return this.data[this.dataPosition + 2]; }, /** * The first entry in the second column of the current Mat2d. */ set: function (value) { this.data[this.dataPosition + 2] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dBuffer.prototype, "c2r2", { /** * The second entry in the second column of the current Mat2d. */ get: function () { return this.data[this.dataPosition + 3]; }, /** * The second entry in the second column of the current Mat2d. */ set: function (value) { this.data[this.dataPosition + 3] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dBuffer.prototype, "c3r1", { /** * The first entry in the third column of the current Mat2d. */ get: function () { return this.data[this.dataPosition + 4]; }, /** * The first entry in the third column of the current Mat2d. */ set: function (value) { this.data[this.dataPosition + 4] = value; }, enumerable: true, configurable: true }); Object.defineProperty(Mat2dBuffer.prototype, "c3r2", { /** * The second entry in the third column of the current Mat2d. */ get: function () { return this.data[this.dataPosition + 5]; }, /** * The second entry in the third column of the current Mat2d. */ set: function (value) { this.data[this.dataPosition + 5] = value; }, enumerable: true, configurable: true }); /** * Gets the number of properties in a Mat2d, namely 6. */ Mat2dBuffer.prototype.structLength = function () { return 6; }; /** * Gets the components of the Mat2d at the specified position of this buffer. */ Mat2dBuffer.prototype.aget = function (position, dst) { if (dst === void 0) { dst = new Mat2d(); } ; var dataPos = position * this.structLength(); dst.c1r1 = this.data[dataPos++]; dst.c1r2 = this.data[dataPos++]; dst.c2r1 = this.data[dataPos++]; dst.c2r2 = this.data[dataPos++]; dst.c3r1 = this.data[dataPos++]; dst.c3r2 = this.data[dataPos++]; return dst; }; /** * Gets the components of the current Mat2d, then moves to the next position of this buffer. */ Mat2dBuffer.prototype.rget = function (dst) { if (dst === void 0) { dst = new Mat2d(); } ; dst.c1r1 = this.data[this.dataPosition++]; dst.c1r2 = this.data[this.dataPosition++]; dst.c2r1 = this.data[this.dataPosition++]; dst.c2r2 = this.data[this.dataPosition++]; dst.c3r1 = this.data[this.dataPosition++]; dst.c3r2 = this.data[this.dataPosition++]; return dst; }; /** * Sets each component of the Mat2d at the specified position to that of the src Mat2d. */ Mat2dBuffer.prototype.aset = function (position, src) { var dataPos = position * this.structLength(); this.data[dataPos++] = src.c1r1; this.data[dataPos++] = src.c1r2; this.data[dataPos++] = src.c2r1; this.data[dataPos++] = src.c2r2; this.data[dataPos++] = src.c3r1; this.data[dataPos++] = src.c3r2; }; /** * Sets each component of the Mat2d at the specified position. */ Mat2dBuffer.prototype.aset$ = function (position, c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { var dataPos = position * this.structLength(); this.data[dataPos++] = c1r1; this.data[dataPos++] = c1r2; this.data[dataPos++] = c2r1; this.data[dataPos++] = c2r2; this.data[dataPos++] = c3r1; this.data[dataPos++] = c3r2; }; /** * Sets each component of the current Mat2d to that of the src Mat2d, then moves to the next position of this buffer. */ Mat2dBuffer.prototype.rset = function (src) { this.data[this.dataPosition++] = src.c1r1; this.data[this.dataPosition++] = src.c1r2; this.data[this.dataPosition++] = src.c2r1; this.data[this.dataPosition++] = src.c2r2; this.data[this.dataPosition++] = src.c3r1; this.data[this.dataPosition++] = src.c3r2; }; /** * Sets each component of the current Mat2d, then moves to the next position of this buffer. */ Mat2dBuffer.prototype.rset$ = function (c1r1, c1r2, c2r1, c2r2, c3r1, c3r2) { this.data[this.dataPosition++] = c1r1; this.data[this.dataPosition++] = c1r2; this.data[this.dataPosition++] = c2r1; this.data[this.dataPosition++] = c2r2; this.data[this.dataPosition++] = c3r1; this.data[this.dataPosition++] = c3r2; }; return Mat2dBuffer; }(buffer_1.StructBuffer)); exports.Mat2dBuffer = Mat2dBuffer; mixin_1.applyMixins(Mat2dBuffer, Mat2d); //# sourceMappingURL=mat2d.js.map