dommetry
Version:
The W3C Geometry Interfaces implemented in JavaScript and polyfilled.
318 lines (286 loc) • 10.6 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _DOMMatrix = require('./DOMMatrix');
var _DOMMatrix2 = _interopRequireDefault(_DOMMatrix);
var _utilities = require('./utilities');
var DOMMatrixReadOnly = (function () {
/**
* @param {Array.number} numberSequence An array of numbers. If the array
* has 6 items, then those items set the values of m11, m12, m21, m22, m41,
* m42 in that order (or the values a, b, c, d, e, f if you're using those
* aliases) and this.is2D is true. If the array has 16 items (in
* column-major order), then they set all the values of the underlying
* matrix (m11 to m44) and this.is2D is set false. Arrays of other lengths
* throw an error.
*/
function DOMMatrixReadOnly(numberSequence) {
_classCallCheck(this, DOMMatrixReadOnly);
if (!this instanceof _DOMMatrix2['default']) throw new TypeError('Expected \'this\' to be an instance of DOMMatrix. DOMMatrixReadOnly can\'t be instantiated directly.');
// TODO, make these private: {{
// `this._matrix` defaults to the identity matrix.
// `this._matrix` is represented internally in row-major format so that
// it is easy to look at visually. In a pair of coordinates (as in
// "m23") the first number is the column and the second is the row (so
// "m23" means column 2 row 3).
this._matrix = new Float64Array([
/*m11*/1, /*m21*/0, /*m31*/0, /*m41*/0,
/*m12*/0, /*m22*/1, /*m32*/0, /*m42*/0,
/*m13*/0, /*m23*/0, /*m33*/1, /*m43*/0,
/*m14*/0, /*m24*/0, /*m34*/0, /*m44*/1]);
this._is2D = true;
this._isIdentity = true;
// }}
// TODO
//if (!Match.test(numberSequence, [Number]))
//throw new TypeError('DOMMatrixReadOnly constructor argument "numberSequence" must contain numbers.')
if (numberSequence.length === 6) {
(0, _utilities.applyArrayValuesToDOMMatrix)(numberSequence, this);
} else if (numberSequence.length === 16) {
(0, _utilities.applyArrayValuesToDOMMatrix)(numberSequence, this);
this._is2D = false;
} else {
throw new TypeError('DOMMatrixReadOnly constructor argument "numberSequence" must have length 6 or 16.');
}
}
// Immutable transform methods -------------------------------------------
_createClass(DOMMatrixReadOnly, [{
key: 'translate',
value: function translate(tx, ty) {
var tz = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
return new _DOMMatrix2['default'](this).translateSelf(tx, ty, tz);
}
}, {
key: 'scale',
value: function scale(_scale) {
var originX = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
var originY = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
return new _DOMMatrix2['default'](this).scaleSelf(_scale, originX, originY);
}
}, {
key: 'scale3d',
value: function scale3d(scale) {
var originX = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
var originY = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
var originZ = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
return new _DOMMatrix2['default'](this).scale3dSelf(scale, originX, originY, originZ);
}
}, {
key: 'scaleNonUniform',
value: function scaleNonUniform(scaleX) {
var scaleY = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
var scaleZ = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2];
var originX = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
var originY = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
var originZ = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
return new _DOMMatrix2['default'](this).scaleNonUniformSelf(scaleX, scaleY, scaleZ, originX, originY, originZ);
}
}, {
key: 'rotate',
value: function rotate(angle) {
var originX = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
var originY = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
return new _DOMMatrix2['default'](this).rotateSelf(angle, originX, originY);
}
// TODO
}, {
key: 'rotateFromVector',
value: function rotateFromVector(x, y) {
throw new Error('rotateFromVector is not implemented yet.');
}
}, {
key: 'rotateAxisAngle',
value: function rotateAxisAngle(x, y, z, angle) {
return new _DOMMatrix2['default'](this).rotateAxisAngleSelf(x, y, z, angle);
}
}, {
key: 'skewX',
value: function skewX(sx) {
throw new Error('skewX is not implemented yet.');
}
}, {
key: 'skewY',
value: function skewY(sy) {
throw new Error('skewY is not implemented yet.');
}
}, {
key: 'multiply',
value: function multiply(other) {
return new _DOMMatrix2['default'](this).multiplySelf(other);
}
}, {
key: 'flipX',
value: function flipX() {
throw new Error('flipX is not implemented yet.');
}
}, {
key: 'flipY',
value: function flipY() {
throw new Error('flipY is not implemented yet.');
}
}, {
key: 'inverse',
value: function inverse() {
throw new Error('inverse is not implemented yet.');
}
}, {
key: 'transformPoint',
value: function transformPoint( /*optional DOMPointInit*/point) {
throw new Error('transformPoint is not implemented yet.');
}
}, {
key: 'toFloat32Array',
value: function toFloat32Array() {
throw new Error('toFloat32Array is not implemented yet.');
}
}, {
key: 'toFloat64Array',
value: function toFloat64Array() {
throw new Error('toFloat64Array is not implemented yet.');
}
//stringifier() {} // What's this?
}, {
key: 'is2D',
get: function get() {
return this._is2D;
}
/*
* TODO: make sure this matches the spec.
* TODO: Instead of calculating here, perhaps calculate and set
* this._isIdentity in other operations, and simply return the internal one
* here.
*/
}, {
key: 'isIdentity',
get: function get() {
var identity = [
/*m11*/1, /*m21*/0, /*m31*/0, /*m41*/0,
/*m12*/0, /*m22*/1, /*m32*/0, /*m42*/0,
/*m13*/0, /*m23*/0, /*m33*/1, /*m43*/0,
/*m14*/0, /*m24*/0, /*m34*/0, /*m44*/1];
this._isIdentity = true;
for (var i = 0, len = this._matrix.length; i < len; i += 1) {
if (this._matrix[i] != identity[i]) this._isIdentity = false;
}
return this._isIdentity;
}
}, {
key: 'a',
get: function get() {
return this.m11;
}
}, {
key: 'b',
get: function get() {
return this.m12;
}
}, {
key: 'c',
get: function get() {
return this.m21;
}
}, {
key: 'd',
get: function get() {
return this.m22;
}
}, {
key: 'e',
get: function get() {
return this.m41;
}
}, {
key: 'f',
get: function get() {
return this.m42;
}
}, {
key: 'm11',
get: function get() {
return this._matrix[0];
}
}, {
key: 'm12',
get: function get() {
return this._matrix[4];
}
}, {
key: 'm13',
get: function get() {
return this._matrix[8];
}
}, {
key: 'm14',
get: function get() {
return this._matrix[12];
}
}, {
key: 'm21',
get: function get() {
return this._matrix[1];
}
}, {
key: 'm22',
get: function get() {
return this._matrix[5];
}
}, {
key: 'm23',
get: function get() {
return this._matrix[9];
}
}, {
key: 'm24',
get: function get() {
return this._matrix[13];
}
}, {
key: 'm31',
get: function get() {
return this._matrix[2];
}
}, {
key: 'm32',
get: function get() {
return this._matrix[6];
}
}, {
key: 'm33',
get: function get() {
return this._matrix[10];
}
}, {
key: 'm34',
get: function get() {
return this._matrix[14];
}
}, {
key: 'm41',
get: function get() {
return this._matrix[3];
}
}, {
key: 'm42',
get: function get() {
return this._matrix[7];
}
}, {
key: 'm43',
get: function get() {
return this._matrix[11];
}
}, {
key: 'm44',
get: function get() {
return this._matrix[15];
}
}]);
return DOMMatrixReadOnly;
})();
exports['default'] = DOMMatrixReadOnly;
module.exports = exports['default'];
//# sourceMappingURL=DOMMatrixReadOnly.js.map