//>>built
define("dojox/gfx/matrix",["./_base","dojo/_base/lang"],function(k,h){var c=k.matrix={},l={};c._degToRad=function(a){return l[a]||(l[a]=Math.PI*a/180)};c._radToDeg=function(a){return a/Math.PI*180};c.Matrix2D=function(a){if(a)if("number"==typeof a)this.xx=this.yy=a;else if(a instanceof Array){if(0<a.length){for(var b=c.normalize(a[0]),d=1;d<a.length;++d){var e=b,f=c.normalize(a[d]);b=new c.Matrix2D;b.xx=e.xx*f.xx+e.xy*f.yx;b.xy=e.xx*f.xy+e.xy*f.yy;b.yx=e.yx*f.xx+e.yy*f.yx;b.yy=e.yx*f.xy+e.yy*f.yy;
b.dx=e.xx*f.dx+e.xy*f.dy+e.dx;b.dy=e.yx*f.dx+e.yy*f.dy+e.dy}h.mixin(this,b)}}else h.mixin(this,a)};h.extend(c.Matrix2D,{xx:1,xy:0,yx:0,yy:1,dx:0,dy:0});h.mixin(c,{identity:new c.Matrix2D,flipX:new c.Matrix2D({xx:-1}),flipY:new c.Matrix2D({yy:-1}),flipXY:new c.Matrix2D({xx:-1,yy:-1}),translate:function(a,b){return 1<arguments.length?new c.Matrix2D({dx:a,dy:b}):new c.Matrix2D({dx:a.x,dy:a.y})},scale:function(a,b){return 1<arguments.length?new c.Matrix2D({xx:a,yy:b}):"number"==typeof a?new c.Matrix2D({xx:a,
yy:a}):new c.Matrix2D({xx:a.x,yy:a.y})},rotate:function(a){var b=Math.cos(a);a=Math.sin(a);return new c.Matrix2D({xx:b,xy:-a,yx:a,yy:b})},rotateg:function(a){return c.rotate(c._degToRad(a))},skewX:function(a){return new c.Matrix2D({xy:Math.tan(a)})},skewXg:function(a){return c.skewX(c._degToRad(a))},skewY:function(a){return new c.Matrix2D({yx:Math.tan(a)})},skewYg:function(a){return c.skewY(c._degToRad(a))},reflect:function(a,b){1==arguments.length&&(b=a.y,a=a.x);var d=a*a,e=b*b,f=d+e,g=2*a*b/f;return new c.Matrix2D({xx:2*
d/f-1,xy:g,yx:g,yy:2*e/f-1})},project:function(a,b){1==arguments.length&&(b=a.y,a=a.x);var d=a*a,e=b*b,f=d+e,g=a*b/f;return new c.Matrix2D({xx:d/f,xy:g,yx:g,yy:e/f})},normalize:function(a){return a instanceof c.Matrix2D?a:new c.Matrix2D(a)},isIdentity:function(a){return 1==a.xx&&0==a.xy&&0==a.yx&&1==a.yy&&0==a.dx&&0==a.dy},clone:function(a){var b=new c.Matrix2D,d;for(d in a)"number"==typeof a[d]&&"number"==typeof b[d]&&b[d]!=a[d]&&(b[d]=a[d]);return b},invert:function(a){a=c.normalize(a);var b=a.xx*
a.yy-a.xy*a.yx;return a=new c.Matrix2D({xx:a.yy/b,xy:-a.xy/b,yx:-a.yx/b,yy:a.xx/b,dx:(a.xy*a.dy-a.yy*a.dx)/b,dy:(a.yx*a.dx-a.xx*a.dy)/b})},_multiplyPoint:function(a,b,d){return{x:a.xx*b+a.xy*d+a.dx,y:a.yx*b+a.yy*d+a.dy}},multiplyPoint:function(a,b,d){a=c.normalize(a);return"number"==typeof b&&"number"==typeof d?c._multiplyPoint(a,b,d):c._multiplyPoint(a,b.x,b.y)},multiplyRectangle:function(a,b){var d=c.normalize(a);b=b||{x:0,y:0,width:0,height:0};if(c.isIdentity(d))return{x:b.x,y:b.y,width:b.width,
height:b.height};var e=c.multiplyPoint(d,b.x,b.y),f=c.multiplyPoint(d,b.x,b.y+b.height),g=c.multiplyPoint(d,b.x+b.width,b.y);d=c.multiplyPoint(d,b.x+b.width,b.y+b.height);var m=Math.min(e.x,f.x,g.x,d.x),n=Math.min(e.y,f.y,g.y,d.y);return{x:m,y:n,width:Math.max(e.x,f.x,g.x,d.x)-m,height:Math.max(e.y,f.y,g.y,d.y)-n}},multiply:function(a){for(var b=c.normalize(a),d=1;d<arguments.length;++d){var e=b,f=c.normalize(arguments[d]);b=new c.Matrix2D;b.xx=e.xx*f.xx+e.xy*f.yx;b.xy=e.xx*f.xy+e.xy*f.yy;b.yx=e.yx*
f.xx+e.yy*f.yx;b.yy=e.yx*f.xy+e.yy*f.yy;b.dx=e.xx*f.dx+e.xy*f.dy+e.dx;b.dy=e.yx*f.dx+e.yy*f.dy+e.dy}return b},_sandwich:function(a,b,d){return c.multiply(c.translate(b,d),a,c.translate(-b,-d))},scaleAt:function(a,b,d,e){switch(arguments.length){case 4:return c._sandwich(c.scale(a,b),d,e);case 3:return"number"==typeof d?c._sandwich(c.scale(a),b,d):c._sandwich(c.scale(a,b),d.x,d.y)}return c._sandwich(c.scale(a),b.x,b.y)},rotateAt:function(a,b,d){return 2<arguments.length?c._sandwich(c.rotate(a),b,d):
c._sandwich(c.rotate(a),b.x,b.y)},rotategAt:function(a,b,d){return 2<arguments.length?c._sandwich(c.rotateg(a),b,d):c._sandwich(c.rotateg(a),b.x,b.y)},skewXAt:function(a,b,d){return 2<arguments.length?c._sandwich(c.skewX(a),b,d):c._sandwich(c.skewX(a),b.x,b.y)},skewXgAt:function(a,b,d){return 2<arguments.length?c._sandwich(c.skewXg(a),b,d):c._sandwich(c.skewXg(a),b.x,b.y)},skewYAt:function(a,b,d){return 2<arguments.length?c._sandwich(c.skewY(a),b,d):c._sandwich(c.skewY(a),b.x,b.y)},skewYgAt:function(a,
b,d){return 2<arguments.length?c._sandwich(c.skewYg(a),b,d):c._sandwich(c.skewYg(a),b.x,b.y)}});k.Matrix2D=c.Matrix2D;return c});