//>>built
define("dojox/gfx/gradient",["dojo/_base/lang","./matrix","dojo/_base/Color"],function(r,k,l){function p(a,d,g,e,m,c){a=k.multiplyPoint(g,a,d);e=k.multiplyPoint(e,a);return{r:a,p:e,o:k.multiplyPoint(m,e).x/c}}function t(a,d){return a.o-d.o}var q=r.getObject("dojox.gfx.gradient",!0);q.rescale=function(a,d,g){var e=a.length,m=g<d;if(m){var c=d;d=g;g=c}if(!e)return[];if(g<=a[0].offset)c=[{offset:0,color:a[0].color},{offset:1,color:a[0].color}];else if(d>=a[e-1].offset)c=[{offset:0,color:a[e-1].color},
{offset:1,color:a[e-1].color}];else{var f=g-d,b;c=[];0>d&&c.push({offset:0,color:new l(a[0].color)});for(b=0;b<e;++b){var h=a[b];if(h.offset>=d)break}if(b){var n=a[b-1];c.push({offset:0,color:l.blendColors(new l(n.color),new l(h.color),(d-n.offset)/(h.offset-n.offset))})}else c.push({offset:0,color:new l(h.color)});for(;b<e;++b){h=a[b];if(h.offset>=g)break;c.push({offset:(h.offset-d)/f,color:new l(h.color)})}b<e?(n=a[b-1],c.push({offset:1,color:l.blendColors(new l(n.color),new l(h.color),(g-n.offset)/
(h.offset-n.offset))})):c.push({offset:1,color:new l(a[e-1].color)})}if(m)for(c.reverse(),b=0,e=c.length;b<e;++b)h=c[b],h.offset=1-h.offset;return c};q.project=function(a,d,g,e,m,c){a=a||k.identity;var f=k.multiplyPoint(a,d.x1,d.y1),b=k.multiplyPoint(a,d.x2,d.y2);m=Math.atan2(b.y-f.y,b.x-f.x);c=k.project(b.x-f.x,b.y-f.y);f=k.multiplyPoint(c,f);b=k.multiplyPoint(c,b);f=new k.Matrix2D([k.rotate(-m),{dx:-f.x,dy:-f.y}]);b=k.multiplyPoint(f,b).x;a=[p(g.x,g.y,a,c,f,b),p(e.x,e.y,a,c,f,b),p(g.x,e.y,a,c,f,
b),p(e.x,g.y,a,c,f,b)].sort(t);d=q.rescale(d.colors,a[0].o,a[3].o);return{type:"linear",x1:a[0].p.x,y1:a[0].p.y,x2:a[3].p.x,y2:a[3].p.y,colors:d,angle:m}};return q});