-
Notifications
You must be signed in to change notification settings - Fork 8
/
matrix-1.2.0.min.js
1 lines (1 loc) · 1.7 KB
/
matrix-1.2.0.min.js
1
(function(){function b(c,d){return{x:c||0,y:d||0,equal:function(e){return this.x===e.x&&this.y===e.y},add:function(e){return b(this.x+e.x,this.y+e.y)},subtract:function(e){return b(this.x-e.x,this.y-e.y)},scale:function(e){return b(this.x*e,this.y*e)},magnitude:function(){return b.distance(b(0,0),this)}}}b.distance=function(d,c){return Math.sqrt(Math.pow(c.x-d.x,2)+Math.pow(c.y-d.y,2))};b.direction=function(d,c){return Math.atan2(c.y-d.y,c.x-d.x)};function a(h,f,j,i,g,e){h=h!==undefined?h:1;i=i!==undefined?i:1;return{a:h,b:f||0,c:j||0,d:i,tx:g||0,ty:e||0,concat:function(c){return a(this.a*c.a+this.c*c.b,this.b*c.a+this.d*c.b,this.a*c.c+this.c*c.d,this.b*c.c+this.d*c.d,this.a*c.tx+this.c*c.ty+this.tx,this.b*c.tx+this.d*c.ty+this.ty)},deltaTransformPoint:function(c){return b(this.a*c.x+this.c*c.y,this.b*c.x+this.d*c.y)},inverse:function(){var c=this.a*this.d-this.b*this.c;return a(this.d/c,-this.b/c,-this.c/c,this.a/c,(this.c*this.ty-this.d*this.tx)/c,(this.b*this.tx-this.a*this.ty)/c)},rotate:function(c,d){return this.concat(a.rotation(c,d))},scale:function(k,d,c){return this.concat(a.scale(k,d,c))},transformPoint:function(c){return b(this.a*c.x+this.c*c.y+this.tx,this.b*c.x+this.d*c.y+this.ty)},translate:function(d,c){return this.concat(a.translation(d,c))}}}a.rotation=function(d,e){var c=a(Math.cos(d),Math.sin(d),-Math.sin(d),Math.cos(d));if(e){c=a.translation(e.x,e.y).concat(c).concat(a.translation(-e.x,-e.y))}return c};a.scale=function(f,e,d){e=e||f;var c=a(f,0,0,e);if(d){c=a.translation(d.x,d.y).concat(c).concat(a.translation(-d.x,-d.y))}return c};a.translation=function(d,c){return a(1,0,0,1,d,c)};a.IDENTITY=a();a.HORIZONTAL_FLIP=a(-1,0,0,1);a.VERTICAL_FLIP=a(1,0,0,-1);window.Point=b;window.Matrix=a}());