Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / gfx / arc.js @ 12

History | View | Annotate | Download (1.81 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.gfx.arc"]){
9
dojo._hasResource["dojox.gfx.arc"]=true;
10
dojo.provide("dojox.gfx.arc");
11
dojo.require("dojox.gfx.matrix");
12
(function(){
13
var m=dojox.gfx.matrix,_1=function(_2){
14
var _3=Math.cos(_2),_4=Math.sin(_2),p2={x:_3+(4/3)*(1-_3),y:_4-(4/3)*_3*(1-_3)/_4};
15
return {s:{x:_3,y:-_4},c1:{x:p2.x,y:-p2.y},c2:p2,e:{x:_3,y:_4}};
16
},_5=2*Math.PI,_6=Math.PI/4,_7=Math.PI/8,_8=_6+_7,_9=_1(_7);
17
dojo.mixin(dojox.gfx.arc,{unitArcAsBezier:_1,curvePI4:_9,arcAsBezier:function(_a,rx,ry,_b,_c,_d,x,y){
18
_c=Boolean(_c);
19
_d=Boolean(_d);
20
var _e=m._degToRad(_b),_f=rx*rx,ry2=ry*ry,pa=m.multiplyPoint(m.rotate(-_e),{x:(_a.x-x)/2,y:(_a.y-y)/2}),_10=pa.x*pa.x,_11=pa.y*pa.y,c1=Math.sqrt((_f*ry2-_f*_11-ry2*_10)/(_f*_11+ry2*_10));
21
if(isNaN(c1)){
22
c1=0;
23
}
24
var ca={x:c1*rx*pa.y/ry,y:-c1*ry*pa.x/rx};
25
if(_c==_d){
26
ca={x:-ca.x,y:-ca.y};
27
}
28
var c=m.multiplyPoint([m.translate((_a.x+x)/2,(_a.y+y)/2),m.rotate(_e)],ca);
29
var _12=m.normalize([m.translate(c.x,c.y),m.rotate(_e),m.scale(rx,ry)]);
30
var _13=m.invert(_12),sp=m.multiplyPoint(_13,_a),ep=m.multiplyPoint(_13,x,y),_14=Math.atan2(sp.y,sp.x),_15=Math.atan2(ep.y,ep.x),_16=_14-_15;
31
if(_d){
32
_16=-_16;
33
}
34
if(_16<0){
35
_16+=_5;
36
}else{
37
if(_16>_5){
38
_16-=_5;
39
}
40
}
41
var _17=_7,_18=_9,_19=_d?_17:-_17,_1a=[];
42
for(var _1b=_16;_1b>0;_1b-=_6){
43
if(_1b<_8){
44
_17=_1b/2;
45
_18=_1(_17);
46
_19=_d?_17:-_17;
47
_1b=0;
48
}
49
var c1,c2,e,M=m.normalize([_12,m.rotate(_14+_19)]);
50
if(_d){
51
c1=m.multiplyPoint(M,_18.c1);
52
c2=m.multiplyPoint(M,_18.c2);
53
e=m.multiplyPoint(M,_18.e);
54
}else{
55
c1=m.multiplyPoint(M,_18.c2);
56
c2=m.multiplyPoint(M,_18.c1);
57
e=m.multiplyPoint(M,_18.s);
58
}
59
_1a.push([c1.x,c1.y,c2.x,c2.y,e.x,e.y]);
60
_14+=2*_19;
61
}
62
return _1a;
63
}});
64
})();
65
}