kld-affine
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -44,7 +44,10 @@ function _classCallCheck(instance, Constructor) { | ||
*/ | ||
function Point2D(x, y) { | ||
function Point2D() { | ||
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
_classCallCheck(this, Point2D); | ||
this.x = x !== undefined ? x : 0.0; | ||
this.y = y !== undefined ? y : 0.0; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
@@ -66,3 +69,3 @@ /** | ||
* | ||
* @param {Point2D|Vector2D} that | ||
* @param {module:kld-affine.Point2D} that | ||
* @returns {module:kld-affine.Point2D} | ||
@@ -79,3 +82,3 @@ */ | ||
* | ||
* @param { Vector2D | Point2D } that | ||
* @param {module:kld-affine.Point2D} that | ||
* @returns {module:kld-affine.Point2D} | ||
@@ -212,3 +215,3 @@ */ | ||
value: function toString() { | ||
return "point(" + this.x + "," + this.y + ")"; | ||
return "point(".concat(this.x, ",").concat(this.y, ")"); | ||
} | ||
@@ -241,7 +244,10 @@ }]); | ||
*/ | ||
function Vector2D(x, y) { | ||
function Vector2D() { | ||
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
_classCallCheck(this, Vector2D); | ||
this.x = x !== undefined ? x : 0.0; | ||
this.y = y !== undefined ? y : 0.0; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
@@ -472,3 +478,3 @@ /** | ||
value: function toString() { | ||
return "vector(" + this.x + "," + this.y + ")"; | ||
return "vector(".concat(this.x, ",").concat(this.y, ")"); | ||
} | ||
@@ -500,8 +506,7 @@ }], [{ | ||
/** | ||
* Matrix2D | ||
* A 2D Matrix of the form:<br> | ||
* [a c e]<br> | ||
* [b d f]<br> | ||
* [0 0 1]<br> | ||
* | ||
* [a c e] | ||
* [b d f] | ||
* [0 0 1] | ||
* | ||
* @param {number} a | ||
@@ -515,11 +520,18 @@ * @param {number} b | ||
*/ | ||
function Matrix2D(a, b, c, d, e, f) { | ||
function Matrix2D() { | ||
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; | ||
var e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; | ||
var f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0; | ||
_classCallCheck(this, Matrix2D); | ||
this.a = a !== undefined ? a : 1; | ||
this.b = b !== undefined ? b : 0; | ||
this.c = c !== undefined ? c : 0; | ||
this.d = d !== undefined ? d : 1; | ||
this.e = e !== undefined ? e : 0; | ||
this.f = f !== undefined ? f : 0; | ||
this.a = a; | ||
this.b = b; | ||
this.c = c; | ||
this.d = d; | ||
this.e = e; | ||
this.f = f; | ||
} | ||
@@ -787,8 +799,6 @@ /** | ||
/** | ||
* getDecomposition | ||
* | ||
* Calculates matrix Singular Value Decomposition | ||
* | ||
* The resulting matrices, translation, rotation, scale, and rotation0, return | ||
* this matrix when they are muliplied together in the listed order | ||
* The resulting matrices — translation, rotation, scale, and rotation0 — return | ||
* this matrix when they are multiplied together in the listed order | ||
* | ||
@@ -798,3 +808,8 @@ * @see Jim Blinn's article {@link http://dx.doi.org/10.1109/38.486688} | ||
* | ||
* @returns {{ translation: module:kld-affine.Matrix2D, rotation: module:kld-affine.Matrix2D, scale: module:kld-affine.Matrix2D, rotation0: module:kld-affine.Matrix2D }} | ||
* @returns {{ | ||
* translation: module:kld-affine.Matrix2D, | ||
* rotation: module:kld-affine.Matrix2D, | ||
* scale: module:kld-affine.Matrix2D, | ||
* rotation0: module:kld-affine.Matrix2D | ||
* }} | ||
*/ | ||
@@ -858,3 +873,3 @@ | ||
value: function toString() { | ||
return "matrix(" + [this.a, this.b, this.c, this.d, this.e, this.f].join(",") + ")"; | ||
return "matrix(".concat(this.a, ",").concat(this.b, ",").concat(this.c, ",").concat(this.d, ",").concat(this.e, ",").concat(this.f, ")"); | ||
} | ||
@@ -861,0 +876,0 @@ }], [{ |
@@ -1,2 +0,2 @@ | ||
function t(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}function i(t,i){for(var s=0;s<i.length;s++){var n=i[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function s(t,s,n){return s&&i(t.prototype,s),n&&i(t,n),t}var n=function(){function i(s,n){t(this,i),this.x=void 0!==s?s:0,this.y=void 0!==n?n:0}return s(i,[{key:"clone",value:function(){return new this.constructor(this.x,this.y)}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"lerp",value:function(t,i){var s=1-i;return new this.constructor(this.x*s+t.x*i,this.y*s+t.y*i)}},{key:"distanceFrom",value:function(t){var i=this.x-t.x,s=this.y-t.y;return Math.sqrt(i*i+s*s)}},{key:"min",value:function(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}},{key:"max",value:function(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}},{key:"toString",value:function(){return"point("+this.x+","+this.y+")"}}]),i}(),e=function(){function i(s,n){t(this,i),this.x=void 0!==s?s:0,this.y=void 0!==n?n:0}return s(i,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"magnitude",value:function(){return this.x*this.x+this.y*this.y}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"cross",value:function(t){return this.x*t.y-this.y*t.x}},{key:"determinant",value:function(t){return this.x*t.y-this.y*t.x}},{key:"unit",value:function(){return this.divide(this.length())}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"angleBetween",value:function(t){var i=this.dot(t)/(this.length()*t.length());i=Math.max(-1,Math.min(i,1));var s=Math.acos(i);return this.cross(t)<0?-s:s}},{key:"perp",value:function(){return new this.constructor(-this.y,this.x)}},{key:"perpendicular",value:function(t){return this.subtract(this.project(t))}},{key:"project",value:function(t){var i=this.dot(t)/t.dot(t);return t.multiply(i)}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"toString",value:function(){return"vector("+this.x+","+this.y+")"}}],[{key:"fromPoints",value:function(t,s){return new i(s.x-t.x,s.y-t.y)}}]),i}(),h=function(){function i(s,n,e,h,r,u){t(this,i),this.a=void 0!==s?s:1,this.b=void 0!==n?n:0,this.c=void 0!==e?e:0,this.d=void 0!==h?h:1,this.e=void 0!==r?r:0,this.f=void 0!==u?u:0}return s(i,[{key:"multiply",value:function(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}},{key:"inverse",value:function(){if(this.isIdentity())return this;var t=this.a*this.d-this.b*this.c;if(0===t)throw new Error("Matrix is not invertible");var i=1/t,s=this.f*this.c-this.e*this.d,n=this.e*this.b-this.f*this.a;return new this.constructor(this.d*i,-this.b*i,-this.c*i,this.a*i,s*i,n*i)}},{key:"translate",value:function(t,i){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*i+this.e,this.b*t+this.d*i+this.f)}},{key:"scale",value:function(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}},{key:"scaleAt",value:function(t,i){var s=i.x-t*i.x,n=i.y-t*i.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*s+this.c*n+this.e,this.b*s+this.d*n+this.f)}},{key:"scaleNonUniform",value:function(t,i){return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.e,this.f)}},{key:"scaleNonUniformAt",value:function(t,i,s){var n=s.x-t*s.x,e=s.y-i*s.y;return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.a*n+this.c*e+this.e,this.b*n+this.d*e+this.f)}},{key:"rotate",value:function(t){var i=Math.cos(t),s=Math.sin(t);return new this.constructor(this.a*i+this.c*s,this.b*i+this.d*s,this.a*-s+this.c*i,this.b*-s+this.d*i,this.e,this.f)}},{key:"rotateAt",value:function(t,i){var s=Math.cos(t),n=Math.sin(t),e=i.x,h=i.y,r=this.a*s+this.c*n,u=this.b*s+this.d*n,a=this.c*s-this.a*n,o=this.d*s-this.b*n;return new this.constructor(r,u,a,o,(this.a-r)*e+(this.c-a)*h+this.e,(this.b-u)*e+(this.d-o)*h+this.f)}},{key:"rotateFromVector",value:function(t){var i=t.unit(),s=i.x,n=i.y;return new this.constructor(this.a*s+this.c*n,this.b*s+this.d*n,this.a*-n+this.c*s,this.b*-n+this.d*s,this.e,this.f)}},{key:"flipX",value:function(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}},{key:"flipY",value:function(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}},{key:"skewX",value:function(t){var i=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*i,this.d+this.b*i,this.e,this.f)}},{key:"skewY",value:function(t){var i=Math.tan(t);return new this.constructor(this.a+this.c*i,this.b+this.d*i,this.c,this.d,this.e,this.f)}},{key:"isIdentity",value:function(){return 1===this.a&&0===this.b&&0===this.c&&1===this.d&&0===this.e&&0===this.f}},{key:"isInvertible",value:function(){return this.a*this.d-this.b*this.c!=0}},{key:"getScale",value:function(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}},{key:"getDecomposition",value:function(){var t=.5*(this.a+this.d),i=.5*(this.a-this.d),s=.5*(this.b+this.c),n=.5*(this.b-this.c),e=Math.sqrt(t*t+n*n),h=Math.sqrt(i*i+s*s),r=e+h,u=e-h,a=Math.atan2(s,i),o=Math.atan2(n,t),c=.5*(o-a),y=.5*(o+a);return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(y),scale:this.constructor.nonUniformScaling(r,u),rotation0:this.constructor.rotation(c)}}},{key:"equals",value:function(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.a-t.a)<i&&Math.abs(this.b-t.b)<i&&Math.abs(this.c-t.c)<i&&Math.abs(this.d-t.d)<i&&Math.abs(this.e-t.e)<i&&Math.abs(this.f-t.f)<i}},{key:"toString",value:function(){return"matrix("+[this.a,this.b,this.c,this.d,this.e,this.f].join(",")+")"}}],[{key:"translation",value:function(t,s){return new i(1,0,0,1,t,s)}},{key:"scaling",value:function(t){return new i(t,0,0,t,0,0)}},{key:"scalingAt",value:function(t,s){return new i(t,0,0,t,s.x-s.x*t,s.y-s.y*t)}},{key:"nonUniformScaling",value:function(t,s){return new i(t,0,0,s,0,0)}},{key:"nonUniformScalingAt",value:function(t,s,n){return new i(t,0,0,s,n.x-n.x*t,n.y-n.y*s)}},{key:"rotation",value:function(t){var s=Math.cos(t),n=Math.sin(t);return new i(s,n,-n,s,0,0)}},{key:"rotationAt",value:function(t,s){var n=Math.cos(t),e=Math.sin(t);return new i(n,e,-e,n,s.x-s.x*n+s.y*e,s.y-s.y*n-s.x*e)}},{key:"rotationFromVector",value:function(t){var s=t.unit(),n=s.x,e=s.y;return new i(n,e,-e,n,0,0)}},{key:"xFlip",value:function(){return new i(-1,0,0,1,0,0)}},{key:"yFlip",value:function(){return new i(1,0,0,-1,0,0)}},{key:"xSkew",value:function(t){return new i(1,0,Math.tan(t),1,0,0)}},{key:"ySkew",value:function(t){return new i(1,Math.tan(t),0,1,0,0)}}]),i}();h.IDENTITY=new h,h.IDENTITY.isIdentity=function(){return!0};export{h as Matrix2D,n as Point2D,e as Vector2D}; | ||
function t(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}function i(t,i){for(var n=0;n<i.length;n++){var s=i[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function n(t,n,s){return n&&i(t.prototype,n),s&&i(t,s),t}var s=function(){function i(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;t(this,i),this.x=n,this.y=s}return n(i,[{key:"clone",value:function(){return new this.constructor(this.x,this.y)}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"lerp",value:function(t,i){var n=1-i;return new this.constructor(this.x*n+t.x*i,this.y*n+t.y*i)}},{key:"distanceFrom",value:function(t){var i=this.x-t.x,n=this.y-t.y;return Math.sqrt(i*i+n*n)}},{key:"min",value:function(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}},{key:"max",value:function(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}},{key:"toString",value:function(){return"point(".concat(this.x,",").concat(this.y,")")}}]),i}(),e=function(){function i(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;t(this,i),this.x=n,this.y=s}return n(i,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"magnitude",value:function(){return this.x*this.x+this.y*this.y}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"cross",value:function(t){return this.x*t.y-this.y*t.x}},{key:"determinant",value:function(t){return this.x*t.y-this.y*t.x}},{key:"unit",value:function(){return this.divide(this.length())}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"angleBetween",value:function(t){var i=this.dot(t)/(this.length()*t.length());i=Math.max(-1,Math.min(i,1));var n=Math.acos(i);return this.cross(t)<0?-n:n}},{key:"perp",value:function(){return new this.constructor(-this.y,this.x)}},{key:"perpendicular",value:function(t){return this.subtract(this.project(t))}},{key:"project",value:function(t){var i=this.dot(t)/t.dot(t);return t.multiply(i)}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"toString",value:function(){return"vector(".concat(this.x,",").concat(this.y,")")}}],[{key:"fromPoints",value:function(t,n){return new i(n.x-t.x,n.y-t.y)}}]),i}(),h=function(){function i(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,h=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,u=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;t(this,i),this.a=n,this.b=s,this.c=e,this.d=h,this.e=r,this.f=u}return n(i,[{key:"multiply",value:function(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}},{key:"inverse",value:function(){if(this.isIdentity())return this;var t=this.a*this.d-this.b*this.c;if(0===t)throw new Error("Matrix is not invertible");var i=1/t,n=this.f*this.c-this.e*this.d,s=this.e*this.b-this.f*this.a;return new this.constructor(this.d*i,-this.b*i,-this.c*i,this.a*i,n*i,s*i)}},{key:"translate",value:function(t,i){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*i+this.e,this.b*t+this.d*i+this.f)}},{key:"scale",value:function(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}},{key:"scaleAt",value:function(t,i){var n=i.x-t*i.x,s=i.y-t*i.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*n+this.c*s+this.e,this.b*n+this.d*s+this.f)}},{key:"scaleNonUniform",value:function(t,i){return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.e,this.f)}},{key:"scaleNonUniformAt",value:function(t,i,n){var s=n.x-t*n.x,e=n.y-i*n.y;return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.a*s+this.c*e+this.e,this.b*s+this.d*e+this.f)}},{key:"rotate",value:function(t){var i=Math.cos(t),n=Math.sin(t);return new this.constructor(this.a*i+this.c*n,this.b*i+this.d*n,this.a*-n+this.c*i,this.b*-n+this.d*i,this.e,this.f)}},{key:"rotateAt",value:function(t,i){var n=Math.cos(t),s=Math.sin(t),e=i.x,h=i.y,r=this.a*n+this.c*s,u=this.b*n+this.d*s,a=this.c*n-this.a*s,c=this.d*n-this.b*s;return new this.constructor(r,u,a,c,(this.a-r)*e+(this.c-a)*h+this.e,(this.b-u)*e+(this.d-c)*h+this.f)}},{key:"rotateFromVector",value:function(t){var i=t.unit(),n=i.x,s=i.y;return new this.constructor(this.a*n+this.c*s,this.b*n+this.d*s,this.a*-s+this.c*n,this.b*-s+this.d*n,this.e,this.f)}},{key:"flipX",value:function(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}},{key:"flipY",value:function(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}},{key:"skewX",value:function(t){var i=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*i,this.d+this.b*i,this.e,this.f)}},{key:"skewY",value:function(t){var i=Math.tan(t);return new this.constructor(this.a+this.c*i,this.b+this.d*i,this.c,this.d,this.e,this.f)}},{key:"isIdentity",value:function(){return 1===this.a&&0===this.b&&0===this.c&&1===this.d&&0===this.e&&0===this.f}},{key:"isInvertible",value:function(){return this.a*this.d-this.b*this.c!=0}},{key:"getScale",value:function(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}},{key:"getDecomposition",value:function(){var t=.5*(this.a+this.d),i=.5*(this.a-this.d),n=.5*(this.b+this.c),s=.5*(this.b-this.c),e=Math.sqrt(t*t+s*s),h=Math.sqrt(i*i+n*n),r=e+h,u=e-h,a=Math.atan2(n,i),c=Math.atan2(s,t),o=.5*(c-a),y=.5*(c+a);return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(y),scale:this.constructor.nonUniformScaling(r,u),rotation0:this.constructor.rotation(o)}}},{key:"equals",value:function(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.a-t.a)<i&&Math.abs(this.b-t.b)<i&&Math.abs(this.c-t.c)<i&&Math.abs(this.d-t.d)<i&&Math.abs(this.e-t.e)<i&&Math.abs(this.f-t.f)<i}},{key:"toString",value:function(){return"matrix(".concat(this.a,",").concat(this.b,",").concat(this.c,",").concat(this.d,",").concat(this.e,",").concat(this.f,")")}}],[{key:"translation",value:function(t,n){return new i(1,0,0,1,t,n)}},{key:"scaling",value:function(t){return new i(t,0,0,t,0,0)}},{key:"scalingAt",value:function(t,n){return new i(t,0,0,t,n.x-n.x*t,n.y-n.y*t)}},{key:"nonUniformScaling",value:function(t,n){return new i(t,0,0,n,0,0)}},{key:"nonUniformScalingAt",value:function(t,n,s){return new i(t,0,0,n,s.x-s.x*t,s.y-s.y*n)}},{key:"rotation",value:function(t){var n=Math.cos(t),s=Math.sin(t);return new i(n,s,-s,n,0,0)}},{key:"rotationAt",value:function(t,n){var s=Math.cos(t),e=Math.sin(t);return new i(s,e,-e,s,n.x-n.x*s+n.y*e,n.y-n.y*s-n.x*e)}},{key:"rotationFromVector",value:function(t){var n=t.unit(),s=n.x,e=n.y;return new i(s,e,-e,s,0,0)}},{key:"xFlip",value:function(){return new i(-1,0,0,1,0,0)}},{key:"yFlip",value:function(){return new i(1,0,0,-1,0,0)}},{key:"xSkew",value:function(t){return new i(1,0,Math.tan(t),1,0,0)}},{key:"ySkew",value:function(t){return new i(1,Math.tan(t),0,1,0,0)}}]),i}();h.IDENTITY=new h,h.IDENTITY.isIdentity=function(){return!0};export{h as Matrix2D,s as Point2D,e as Vector2D}; | ||
//# sourceMappingURL=index-esm.min.js.map |
@@ -50,7 +50,10 @@ (function (global, factory) { | ||
*/ | ||
function Point2D(x, y) { | ||
function Point2D() { | ||
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
_classCallCheck(this, Point2D); | ||
this.x = x !== undefined ? x : 0.0; | ||
this.y = y !== undefined ? y : 0.0; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
@@ -72,3 +75,3 @@ /** | ||
* | ||
* @param {Point2D|Vector2D} that | ||
* @param {module:kld-affine.Point2D} that | ||
* @returns {module:kld-affine.Point2D} | ||
@@ -85,3 +88,3 @@ */ | ||
* | ||
* @param { Vector2D | Point2D } that | ||
* @param {module:kld-affine.Point2D} that | ||
* @returns {module:kld-affine.Point2D} | ||
@@ -218,3 +221,3 @@ */ | ||
value: function toString() { | ||
return "point(" + this.x + "," + this.y + ")"; | ||
return "point(".concat(this.x, ",").concat(this.y, ")"); | ||
} | ||
@@ -247,7 +250,10 @@ }]); | ||
*/ | ||
function Vector2D(x, y) { | ||
function Vector2D() { | ||
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
_classCallCheck(this, Vector2D); | ||
this.x = x !== undefined ? x : 0.0; | ||
this.y = y !== undefined ? y : 0.0; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
@@ -478,3 +484,3 @@ /** | ||
value: function toString() { | ||
return "vector(" + this.x + "," + this.y + ")"; | ||
return "vector(".concat(this.x, ",").concat(this.y, ")"); | ||
} | ||
@@ -506,8 +512,7 @@ }], [{ | ||
/** | ||
* Matrix2D | ||
* A 2D Matrix of the form:<br> | ||
* [a c e]<br> | ||
* [b d f]<br> | ||
* [0 0 1]<br> | ||
* | ||
* [a c e] | ||
* [b d f] | ||
* [0 0 1] | ||
* | ||
* @param {number} a | ||
@@ -521,11 +526,18 @@ * @param {number} b | ||
*/ | ||
function Matrix2D(a, b, c, d, e, f) { | ||
function Matrix2D() { | ||
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; | ||
var e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; | ||
var f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0; | ||
_classCallCheck(this, Matrix2D); | ||
this.a = a !== undefined ? a : 1; | ||
this.b = b !== undefined ? b : 0; | ||
this.c = c !== undefined ? c : 0; | ||
this.d = d !== undefined ? d : 1; | ||
this.e = e !== undefined ? e : 0; | ||
this.f = f !== undefined ? f : 0; | ||
this.a = a; | ||
this.b = b; | ||
this.c = c; | ||
this.d = d; | ||
this.e = e; | ||
this.f = f; | ||
} | ||
@@ -793,8 +805,6 @@ /** | ||
/** | ||
* getDecomposition | ||
* | ||
* Calculates matrix Singular Value Decomposition | ||
* | ||
* The resulting matrices, translation, rotation, scale, and rotation0, return | ||
* this matrix when they are muliplied together in the listed order | ||
* The resulting matrices — translation, rotation, scale, and rotation0 — return | ||
* this matrix when they are multiplied together in the listed order | ||
* | ||
@@ -804,3 +814,8 @@ * @see Jim Blinn's article {@link http://dx.doi.org/10.1109/38.486688} | ||
* | ||
* @returns {{ translation: module:kld-affine.Matrix2D, rotation: module:kld-affine.Matrix2D, scale: module:kld-affine.Matrix2D, rotation0: module:kld-affine.Matrix2D }} | ||
* @returns {{ | ||
* translation: module:kld-affine.Matrix2D, | ||
* rotation: module:kld-affine.Matrix2D, | ||
* scale: module:kld-affine.Matrix2D, | ||
* rotation0: module:kld-affine.Matrix2D | ||
* }} | ||
*/ | ||
@@ -864,3 +879,3 @@ | ||
value: function toString() { | ||
return "matrix(" + [this.a, this.b, this.c, this.d, this.e, this.f].join(",") + ")"; | ||
return "matrix(".concat(this.a, ",").concat(this.b, ",").concat(this.c, ",").concat(this.d, ",").concat(this.e, ",").concat(this.f, ")"); | ||
} | ||
@@ -867,0 +882,0 @@ }], [{ |
@@ -1,2 +0,2 @@ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).KldAffine={})}(this,function(t){"use strict";function i(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}function s(t,i){for(var s=0;s<i.length;s++){var n=i[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function n(t,i,n){return i&&s(t.prototype,i),n&&s(t,n),t}var e=function(){function t(s,n){i(this,t),this.x=void 0!==s?s:0,this.y=void 0!==n?n:0}return n(t,[{key:"clone",value:function(){return new this.constructor(this.x,this.y)}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"lerp",value:function(t,i){var s=1-i;return new this.constructor(this.x*s+t.x*i,this.y*s+t.y*i)}},{key:"distanceFrom",value:function(t){var i=this.x-t.x,s=this.y-t.y;return Math.sqrt(i*i+s*s)}},{key:"min",value:function(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}},{key:"max",value:function(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}},{key:"toString",value:function(){return"point("+this.x+","+this.y+")"}}]),t}(),h=function(){function t(s,n){i(this,t),this.x=void 0!==s?s:0,this.y=void 0!==n?n:0}return n(t,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"magnitude",value:function(){return this.x*this.x+this.y*this.y}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"cross",value:function(t){return this.x*t.y-this.y*t.x}},{key:"determinant",value:function(t){return this.x*t.y-this.y*t.x}},{key:"unit",value:function(){return this.divide(this.length())}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"angleBetween",value:function(t){var i=this.dot(t)/(this.length()*t.length());i=Math.max(-1,Math.min(i,1));var s=Math.acos(i);return this.cross(t)<0?-s:s}},{key:"perp",value:function(){return new this.constructor(-this.y,this.x)}},{key:"perpendicular",value:function(t){return this.subtract(this.project(t))}},{key:"project",value:function(t){var i=this.dot(t)/t.dot(t);return t.multiply(i)}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"toString",value:function(){return"vector("+this.x+","+this.y+")"}}],[{key:"fromPoints",value:function(i,s){return new t(s.x-i.x,s.y-i.y)}}]),t}(),r=function(){function t(s,n,e,h,r,u){i(this,t),this.a=void 0!==s?s:1,this.b=void 0!==n?n:0,this.c=void 0!==e?e:0,this.d=void 0!==h?h:1,this.e=void 0!==r?r:0,this.f=void 0!==u?u:0}return n(t,[{key:"multiply",value:function(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}},{key:"inverse",value:function(){if(this.isIdentity())return this;var t=this.a*this.d-this.b*this.c;if(0===t)throw new Error("Matrix is not invertible");var i=1/t,s=this.f*this.c-this.e*this.d,n=this.e*this.b-this.f*this.a;return new this.constructor(this.d*i,-this.b*i,-this.c*i,this.a*i,s*i,n*i)}},{key:"translate",value:function(t,i){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*i+this.e,this.b*t+this.d*i+this.f)}},{key:"scale",value:function(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}},{key:"scaleAt",value:function(t,i){var s=i.x-t*i.x,n=i.y-t*i.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*s+this.c*n+this.e,this.b*s+this.d*n+this.f)}},{key:"scaleNonUniform",value:function(t,i){return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.e,this.f)}},{key:"scaleNonUniformAt",value:function(t,i,s){var n=s.x-t*s.x,e=s.y-i*s.y;return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.a*n+this.c*e+this.e,this.b*n+this.d*e+this.f)}},{key:"rotate",value:function(t){var i=Math.cos(t),s=Math.sin(t);return new this.constructor(this.a*i+this.c*s,this.b*i+this.d*s,this.a*-s+this.c*i,this.b*-s+this.d*i,this.e,this.f)}},{key:"rotateAt",value:function(t,i){var s=Math.cos(t),n=Math.sin(t),e=i.x,h=i.y,r=this.a*s+this.c*n,u=this.b*s+this.d*n,a=this.c*s-this.a*n,o=this.d*s-this.b*n;return new this.constructor(r,u,a,o,(this.a-r)*e+(this.c-a)*h+this.e,(this.b-u)*e+(this.d-o)*h+this.f)}},{key:"rotateFromVector",value:function(t){var i=t.unit(),s=i.x,n=i.y;return new this.constructor(this.a*s+this.c*n,this.b*s+this.d*n,this.a*-n+this.c*s,this.b*-n+this.d*s,this.e,this.f)}},{key:"flipX",value:function(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}},{key:"flipY",value:function(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}},{key:"skewX",value:function(t){var i=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*i,this.d+this.b*i,this.e,this.f)}},{key:"skewY",value:function(t){var i=Math.tan(t);return new this.constructor(this.a+this.c*i,this.b+this.d*i,this.c,this.d,this.e,this.f)}},{key:"isIdentity",value:function(){return 1===this.a&&0===this.b&&0===this.c&&1===this.d&&0===this.e&&0===this.f}},{key:"isInvertible",value:function(){return this.a*this.d-this.b*this.c!=0}},{key:"getScale",value:function(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}},{key:"getDecomposition",value:function(){var t=.5*(this.a+this.d),i=.5*(this.a-this.d),s=.5*(this.b+this.c),n=.5*(this.b-this.c),e=Math.sqrt(t*t+n*n),h=Math.sqrt(i*i+s*s),r=e+h,u=e-h,a=Math.atan2(s,i),o=Math.atan2(n,t),c=.5*(o-a),y=.5*(o+a);return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(y),scale:this.constructor.nonUniformScaling(r,u),rotation0:this.constructor.rotation(c)}}},{key:"equals",value:function(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.a-t.a)<i&&Math.abs(this.b-t.b)<i&&Math.abs(this.c-t.c)<i&&Math.abs(this.d-t.d)<i&&Math.abs(this.e-t.e)<i&&Math.abs(this.f-t.f)<i}},{key:"toString",value:function(){return"matrix("+[this.a,this.b,this.c,this.d,this.e,this.f].join(",")+")"}}],[{key:"translation",value:function(i,s){return new t(1,0,0,1,i,s)}},{key:"scaling",value:function(i){return new t(i,0,0,i,0,0)}},{key:"scalingAt",value:function(i,s){return new t(i,0,0,i,s.x-s.x*i,s.y-s.y*i)}},{key:"nonUniformScaling",value:function(i,s){return new t(i,0,0,s,0,0)}},{key:"nonUniformScalingAt",value:function(i,s,n){return new t(i,0,0,s,n.x-n.x*i,n.y-n.y*s)}},{key:"rotation",value:function(i){var s=Math.cos(i),n=Math.sin(i);return new t(s,n,-n,s,0,0)}},{key:"rotationAt",value:function(i,s){var n=Math.cos(i),e=Math.sin(i);return new t(n,e,-e,n,s.x-s.x*n+s.y*e,s.y-s.y*n-s.x*e)}},{key:"rotationFromVector",value:function(i){var s=i.unit(),n=s.x,e=s.y;return new t(n,e,-e,n,0,0)}},{key:"xFlip",value:function(){return new t(-1,0,0,1,0,0)}},{key:"yFlip",value:function(){return new t(1,0,0,-1,0,0)}},{key:"xSkew",value:function(i){return new t(1,0,Math.tan(i),1,0,0)}},{key:"ySkew",value:function(i){return new t(1,Math.tan(i),0,1,0,0)}}]),t}();r.IDENTITY=new r,r.IDENTITY.isIdentity=function(){return!0},t.Matrix2D=r,t.Point2D=e,t.Vector2D=h,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).KldAffine={})}(this,function(t){"use strict";function i(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}function n(t,i){for(var n=0;n<i.length;n++){var s=i[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function s(t,i,s){return i&&n(t.prototype,i),s&&n(t,s),t}var e=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;i(this,t),this.x=n,this.y=s}return s(t,[{key:"clone",value:function(){return new this.constructor(this.x,this.y)}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"lerp",value:function(t,i){var n=1-i;return new this.constructor(this.x*n+t.x*i,this.y*n+t.y*i)}},{key:"distanceFrom",value:function(t){var i=this.x-t.x,n=this.y-t.y;return Math.sqrt(i*i+n*n)}},{key:"min",value:function(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}},{key:"max",value:function(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}},{key:"toString",value:function(){return"point(".concat(this.x,",").concat(this.y,")")}}]),t}(),h=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;i(this,t),this.x=n,this.y=s}return s(t,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"magnitude",value:function(){return this.x*this.x+this.y*this.y}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"cross",value:function(t){return this.x*t.y-this.y*t.x}},{key:"determinant",value:function(t){return this.x*t.y-this.y*t.x}},{key:"unit",value:function(){return this.divide(this.length())}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"angleBetween",value:function(t){var i=this.dot(t)/(this.length()*t.length());i=Math.max(-1,Math.min(i,1));var n=Math.acos(i);return this.cross(t)<0?-n:n}},{key:"perp",value:function(){return new this.constructor(-this.y,this.x)}},{key:"perpendicular",value:function(t){return this.subtract(this.project(t))}},{key:"project",value:function(t){var i=this.dot(t)/t.dot(t);return t.multiply(i)}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.x-t.x)<i&&Math.abs(this.y-t.y)<i}},{key:"toString",value:function(){return"vector(".concat(this.x,",").concat(this.y,")")}}],[{key:"fromPoints",value:function(i,n){return new t(n.x-i.x,n.y-i.y)}}]),t}(),r=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,h=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,u=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;i(this,t),this.a=n,this.b=s,this.c=e,this.d=h,this.e=r,this.f=u}return s(t,[{key:"multiply",value:function(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}},{key:"inverse",value:function(){if(this.isIdentity())return this;var t=this.a*this.d-this.b*this.c;if(0===t)throw new Error("Matrix is not invertible");var i=1/t,n=this.f*this.c-this.e*this.d,s=this.e*this.b-this.f*this.a;return new this.constructor(this.d*i,-this.b*i,-this.c*i,this.a*i,n*i,s*i)}},{key:"translate",value:function(t,i){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*i+this.e,this.b*t+this.d*i+this.f)}},{key:"scale",value:function(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}},{key:"scaleAt",value:function(t,i){var n=i.x-t*i.x,s=i.y-t*i.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*n+this.c*s+this.e,this.b*n+this.d*s+this.f)}},{key:"scaleNonUniform",value:function(t,i){return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.e,this.f)}},{key:"scaleNonUniformAt",value:function(t,i,n){var s=n.x-t*n.x,e=n.y-i*n.y;return new this.constructor(this.a*t,this.b*t,this.c*i,this.d*i,this.a*s+this.c*e+this.e,this.b*s+this.d*e+this.f)}},{key:"rotate",value:function(t){var i=Math.cos(t),n=Math.sin(t);return new this.constructor(this.a*i+this.c*n,this.b*i+this.d*n,this.a*-n+this.c*i,this.b*-n+this.d*i,this.e,this.f)}},{key:"rotateAt",value:function(t,i){var n=Math.cos(t),s=Math.sin(t),e=i.x,h=i.y,r=this.a*n+this.c*s,u=this.b*n+this.d*s,a=this.c*n-this.a*s,o=this.d*n-this.b*s;return new this.constructor(r,u,a,o,(this.a-r)*e+(this.c-a)*h+this.e,(this.b-u)*e+(this.d-o)*h+this.f)}},{key:"rotateFromVector",value:function(t){var i=t.unit(),n=i.x,s=i.y;return new this.constructor(this.a*n+this.c*s,this.b*n+this.d*s,this.a*-s+this.c*n,this.b*-s+this.d*n,this.e,this.f)}},{key:"flipX",value:function(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}},{key:"flipY",value:function(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}},{key:"skewX",value:function(t){var i=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*i,this.d+this.b*i,this.e,this.f)}},{key:"skewY",value:function(t){var i=Math.tan(t);return new this.constructor(this.a+this.c*i,this.b+this.d*i,this.c,this.d,this.e,this.f)}},{key:"isIdentity",value:function(){return 1===this.a&&0===this.b&&0===this.c&&1===this.d&&0===this.e&&0===this.f}},{key:"isInvertible",value:function(){return this.a*this.d-this.b*this.c!=0}},{key:"getScale",value:function(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}},{key:"getDecomposition",value:function(){var t=.5*(this.a+this.d),i=.5*(this.a-this.d),n=.5*(this.b+this.c),s=.5*(this.b-this.c),e=Math.sqrt(t*t+s*s),h=Math.sqrt(i*i+n*n),r=e+h,u=e-h,a=Math.atan2(n,i),o=Math.atan2(s,t),c=.5*(o-a),y=.5*(o+a);return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(y),scale:this.constructor.nonUniformScaling(r,u),rotation0:this.constructor.rotation(c)}}},{key:"equals",value:function(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}},{key:"precisionEquals",value:function(t,i){return Math.abs(this.a-t.a)<i&&Math.abs(this.b-t.b)<i&&Math.abs(this.c-t.c)<i&&Math.abs(this.d-t.d)<i&&Math.abs(this.e-t.e)<i&&Math.abs(this.f-t.f)<i}},{key:"toString",value:function(){return"matrix(".concat(this.a,",").concat(this.b,",").concat(this.c,",").concat(this.d,",").concat(this.e,",").concat(this.f,")")}}],[{key:"translation",value:function(i,n){return new t(1,0,0,1,i,n)}},{key:"scaling",value:function(i){return new t(i,0,0,i,0,0)}},{key:"scalingAt",value:function(i,n){return new t(i,0,0,i,n.x-n.x*i,n.y-n.y*i)}},{key:"nonUniformScaling",value:function(i,n){return new t(i,0,0,n,0,0)}},{key:"nonUniformScalingAt",value:function(i,n,s){return new t(i,0,0,n,s.x-s.x*i,s.y-s.y*n)}},{key:"rotation",value:function(i){var n=Math.cos(i),s=Math.sin(i);return new t(n,s,-s,n,0,0)}},{key:"rotationAt",value:function(i,n){var s=Math.cos(i),e=Math.sin(i);return new t(s,e,-e,s,n.x-n.x*s+n.y*e,n.y-n.y*s-n.x*e)}},{key:"rotationFromVector",value:function(i){var n=i.unit(),s=n.x,e=n.y;return new t(s,e,-e,s,0,0)}},{key:"xFlip",value:function(){return new t(-1,0,0,1,0,0)}},{key:"yFlip",value:function(){return new t(1,0,0,-1,0,0)}},{key:"xSkew",value:function(i){return new t(1,0,Math.tan(i),1,0,0)}},{key:"ySkew",value:function(i){return new t(1,Math.tan(i),0,1,0,0)}}]),t}();r.IDENTITY=new r,r.IDENTITY.isIdentity=function(){return!0},t.Matrix2D=r,t.Point2D=e,t.Vector2D=h,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index-umd.min.js.map |
@@ -14,8 +14,7 @@ /** | ||
/** | ||
* Matrix2D | ||
* A 2D Matrix of the form:<br> | ||
* [a c e]<br> | ||
* [b d f]<br> | ||
* [0 0 1]<br> | ||
* | ||
* [a c e] | ||
* [b d f] | ||
* [0 0 1] | ||
* | ||
* @param {number} a | ||
@@ -29,9 +28,9 @@ * @param {number} b | ||
*/ | ||
constructor(a, b, c, d, e, f) { | ||
this.a = (a !== undefined) ? a : 1; | ||
this.b = (b !== undefined) ? b : 0; | ||
this.c = (c !== undefined) ? c : 0; | ||
this.d = (d !== undefined) ? d : 1; | ||
this.e = (e !== undefined) ? e : 0; | ||
this.f = (f !== undefined) ? f : 0; | ||
constructor(a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) { | ||
this.a = a; | ||
this.b = b; | ||
this.c = c; | ||
this.d = d; | ||
this.e = e; | ||
this.f = f; | ||
} | ||
@@ -78,3 +77,2 @@ | ||
/** | ||
@@ -532,8 +530,6 @@ * nonUniformScaling | ||
/** | ||
* getDecomposition | ||
* | ||
* Calculates matrix Singular Value Decomposition | ||
* | ||
* The resulting matrices, translation, rotation, scale, and rotation0, return | ||
* this matrix when they are muliplied together in the listed order | ||
* The resulting matrices — translation, rotation, scale, and rotation0 — return | ||
* this matrix when they are multiplied together in the listed order | ||
* | ||
@@ -543,3 +539,8 @@ * @see Jim Blinn's article {@link http://dx.doi.org/10.1109/38.486688} | ||
* | ||
* @returns {{ translation: module:kld-affine.Matrix2D, rotation: module:kld-affine.Matrix2D, scale: module:kld-affine.Matrix2D, rotation0: module:kld-affine.Matrix2D }} | ||
* @returns {{ | ||
* translation: module:kld-affine.Matrix2D, | ||
* rotation: module:kld-affine.Matrix2D, | ||
* scale: module:kld-affine.Matrix2D, | ||
* rotation0: module:kld-affine.Matrix2D | ||
* }} | ||
*/ | ||
@@ -611,3 +612,3 @@ getDecomposition() { | ||
toString() { | ||
return "matrix(" + [this.a, this.b, this.c, this.d, this.e, this.f].join(",") + ")"; | ||
return `matrix(${this.a},${this.b},${this.c},${this.d},${this.e},${this.f})`; | ||
} | ||
@@ -614,0 +615,0 @@ } |
@@ -20,5 +20,5 @@ /** | ||
*/ | ||
constructor(x, y) { | ||
this.x = x !== undefined ? x : 0.0; | ||
this.y = y !== undefined ? y : 0.0; | ||
constructor(x = 0, y = 0) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
@@ -38,3 +38,3 @@ | ||
* | ||
* @param {Point2D|Vector2D} that | ||
* @param {module:kld-affine.Point2D} that | ||
* @returns {module:kld-affine.Point2D} | ||
@@ -49,3 +49,3 @@ */ | ||
* | ||
* @param { Vector2D | Point2D } that | ||
* @param {module:kld-affine.Point2D} that | ||
* @returns {module:kld-affine.Point2D} | ||
@@ -177,3 +177,3 @@ */ | ||
toString() { | ||
return "point(" + this.x + "," + this.y + ")"; | ||
return `point(${this.x},${this.y})`; | ||
} | ||
@@ -180,0 +180,0 @@ } |
@@ -20,5 +20,5 @@ /** | ||
*/ | ||
constructor(x, y) { | ||
this.x = x !== undefined ? x : 0.0; | ||
this.y = y !== undefined ? y : 0.0; | ||
constructor(x = 0, y = 0) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
@@ -229,3 +229,3 @@ | ||
toString() { | ||
return "vector(" + this.x + "," + this.y + ")"; | ||
return `vector(${this.x},${this.y})`; | ||
} | ||
@@ -232,0 +232,0 @@ } |
{ | ||
"name": "kld-affine", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A collection of classes used in affine geometry", | ||
@@ -5,0 +5,0 @@ "author": { |
# kld-affine | ||
- [Installation](#installation) | ||
- [Importing](#importing) | ||
- [API](#api) | ||
--- | ||
A collection of classes used for affine geometry. This currently consists of the following classes: | ||
@@ -9,6 +15,4 @@ | ||
These have been extracted from kld-intersections so they can stand alone. | ||
# Installation | ||
## Install | ||
``` | ||
@@ -18,2 +22,37 @@ npm install kld-affine | ||
# Importing | ||
The following sections indicate how you can import the code for use in various environments. | ||
## Node | ||
```javascript | ||
import {Point2D, Vector2D, Matrix2D} = require("kld-affine"); | ||
``` | ||
## ESM in Modern Browsers | ||
```javascript | ||
import {Point2D, Vector2D, Matrix2D} from './node_modules/kld-affine/dist/index-esm.js'; | ||
``` | ||
## Older Browsers | ||
```html | ||
<script src="./node_modules/kld-affine/dist/index-umd.js"></script> | ||
<script> | ||
var Point2D = KldAffine.Point2D; | ||
var Vector2D = KldAffine.Vector2D; | ||
var Matrix2D = KldAffine.Matrix2D; | ||
</script> | ||
``` | ||
## Bundlers | ||
```javascript | ||
import {Point2D, Vector2D, Matrix2D} from "kld-affine"; | ||
``` | ||
# API | ||
## Point2D | ||
@@ -20,0 +59,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
196954
40
3006
136
0