Arc.prototype=new Extra_Graphics();Arc.prototype.constructor=Arc;function Arc(c,b,a){this._p1=c;this._p2=b;this._p3=a;this._center=null;this._optimized_drawing=false;this._draw_middle_point=true}Arc.prototype.draw=function(c){try{if(this._optimized_drawing){this._p1._color=this._color;this._p2._color=this._color;this._p3._color=this._color;this._p1.draw(c);this._p2.draw(c);this._p3.draw(c)}else{var a=this.linearize();if(a==null){return}a._optimized_drawing=this.optimized_drawing;a._color=this._color;a.draw(c);if(this._draw_middle_point){this._p2._color=this._color;this._p2.draw(c)}}}catch(b){throw"Arc.draw(): "+b}};Arc.prototype.linearize=function(){try{var g=_MAP_WRAPPER.convert_point_to_pixel(this._p1,true);var d=_MAP_WRAPPER.convert_point_to_pixel(this._p2,true);var c=_MAP_WRAPPER.convert_point_to_pixel(this._p3,true);this._radius=this.circle(g,d,c);if(isNaN(this._radius)||this._radius==0){return null}var b=new Point(1,0);b._x=b._x*this._radius;b._y=b._y*this._radius;b._x=b._x+this._center._x;b._y=b._y+this._center._y;var a=new Array(b._x-this._center._x,this._center._y-b._y);var q=new Array(g._x-this._center._x,this._center._y-g._y);var o=new Array(d._x-this._center._x,this._center._y-d._y);var n=new Array(c._x-this._center._x,this._center._y-c._y);var i=parseInt(_MAP_WRAPPER.rad_to_deg(_GENERIC_GIS_UTILS.vectors_angle(a,q)));var l=parseInt(_MAP_WRAPPER.rad_to_deg(_GENERIC_GIS_UTILS.vectors_angle(a,o)));var j=parseInt(_MAP_WRAPPER.rad_to_deg(_GENERIC_GIS_UTILS.vectors_angle(a,n)));if(q[1]<0){i=360-i}if(o[1]<0){l=360-l}if(n[1]<0){j=360-j}if((i==l)||(l==j)||isNaN(i)||isNaN(l)||isNaN(j)){return null}var m=l;var f=false;if(this.clockwise(g,d,c)==0){return null}else{if(this.clockwise(g,d,c)<0){f=true}}var h=new Line_Path();h._color=this._color;h.add_list_of_graphics(this.linearize_circle(f,i,m,g,d));m=j;h.add_list_of_graphics(this.linearize_circle(f,l,m,d,c));return h}catch(k){throw"Arc.linearize(): "+k}};Arc.prototype.linearize_circle=function(b,d,h,n,a){try{var j=0;var c=true;var i=new Array();while(true){if(b){d++}else{d--}j=(d+3600)%360;if(j==h%360){break}var m=null;var g=_MAP_WRAPPER.deg_to_rad(j);var l=new Point(Math.cos(g),Math.sin(g));l._x=l._x*this._radius;l._y=l._y*this._radius;l._x=l._x+this._center._x;l._y=this._center._y-l._y;if(c){m=new Line(_MAP_WRAPPER.convert_point_to_geo(n.clone()),_MAP_WRAPPER.convert_point_to_geo(l));m._optimized_drawing=this._optimized_drawing;m._color=this._color;i.push(m);c=false}if(!b&&j>=0){g=_MAP_WRAPPER.deg_to_rad(j-1)}else{g=_MAP_WRAPPER.deg_to_rad(j+1)}var k=new Point(Math.cos(g),Math.sin(g));k._x=k._x*this._radius;k._y=k._y*this._radius;k._x=k._x+this._center._x;k._y=+this._center._y-k._y;m=new Line(_MAP_WRAPPER.convert_point_to_geo(l),_MAP_WRAPPER.convert_point_to_geo(k));m._optimized_drawing=this._optimized_drawing;m._color=this._color;i.push(m)}return i}catch(f){throw"Arc.linearize_circle: "+f}};Arc.prototype.circle=function(l,k,j){try{var b,g,f,d,c;var i=new Array();i[0]=new Array();i[1]=new Array();i[2]=new Array();i[0][0]=l._x;i[0][1]=l._y;i[0][2]=1;i[1][0]=k._x;i[1][1]=k._y;i[1][2]=1;i[2][0]=j._x;i[2][1]=j._y;i[2][2]=1;g=this.det(i,3);i[0][0]=Math.pow(l._x,2)+Math.pow(l._y,2);i[0][1]=l._y;i[0][2]=1;i[1][0]=Math.pow(k._x,2)+Math.pow(k._y,2);i[1][1]=k._y;i[1][2]=1;i[2][0]=Math.pow(j._x,2)+Math.pow(j._y,2);i[2][1]=j._y;i[2][2]=1;f=this.det(i,3);i[0][0]=Math.pow(l._x,2)+Math.pow(l._y,2);i[0][1]=l._x;i[0][2]=1;i[1][0]=Math.pow(k._x,2)+Math.pow(k._y,2);i[1][1]=k._x;i[1][2]=1;i[2][0]=Math.pow(j._x,2)+Math.pow(j._y,2);i[2][1]=j._x;i[2][2]=1;d=this.det(i,3);i[0][0]=Math.pow(l._x,2)+Math.pow(l._y,2);i[0][1]=l._x;i[0][2]=l._y;i[1][0]=Math.pow(k._x,2)+Math.pow(k._y,2);i[1][1]=k._x;i[1][2]=k._y;i[2][0]=Math.pow(j._x,2)+Math.pow(j._y,2);i[2][1]=j._x;i[2][2]=j._y;c=this.det(i,3);if(g==0){b=0}else{this._center=new Point(0.5*f/g,-0.5*d/g);b=Math.sqrt(Math.pow(this._center._x,2)+Math.pow(this._center._y,2)+c/g)}return b}catch(h){throw"Arc.circle(): "+h}};Arc.prototype.det=function(l,b){try{var g,f,p,o;var k=0;var c=new Array();c[0]=new Array();c[1]=new Array();c[2]=new Array();if(b==2){k=l[0][0]*l[1][1]-l[1][0]*l[0][1]}else{k=0}for(p=0;p<b;p++){for(g=1;g<b;g++){o=0;for(f=0;f<b;f++){if(f==p){continue}c[g-1][o]=l[g][f];o++}}k=k+Math.pow((-1),(0+p))*l[0][p]*this.det(c,b-1)}return k}catch(h){throw"Arc.det() :"+h}};Arc.prototype.to_post_request=function(){var a=new Array();a[0]=this._p1._x+"_"+this._p2._x+"_"+this._p3._x;a[1]=this._p1._y+"_"+this._p2._y+"_"+this._p3._y;return a};Arc.prototype.distance_from_point=function(b,f,c){try{var a=new Point(b,f);if(this._p1.distance(a)<=this._p2.distance(a)){if(this._p1.distance(a)<this._p3.distance(a)){return this._p1.distance(a)}else{return this._p3.distance(a)}}else{if(this._p2.distance(a)<=this._p3.distance(a)){return this._p2.distance(a)}else{return this._p3.distance(a)}}}catch(d){throw"Arc.distance_from_point() "+d}};Arc.prototype.equals=function(a){if(!(a instanceof Arc)){return false}return this._p2.equals(a._p2)&&((this._p1.equals(a._p1)&&this._p3.equals(a._p3))||(this._p1.equals(a._p3)&&this._p3.equals(a._p1)))};Arc.prototype.move=function(a,b){this._p1.move(a,b);this._p2.move(a,b);this._p3.move(a,b)};Arc.prototype.to_string=function(){return"Arc: "+this._p1._x+" "+this._p1._y+", "+this._p2._x+" "+this._p2._y+", "+this._p3._x+" "+this._p3._y};Arc.prototype.invert_points=function(){var a=this._p1;this._p1=this._p3;this._p3=a};Arc.prototype.clockwise=function(a,c,b){return(a._x-b._x)*(c._y-b._y)-(a._y-b._y)*(c._x-b._x)};Arc.prototype.clone=function(){return new Arc(this._p1.clone(),this._p2.clone(),this._p3.clone())};Arc.prototype.compute_direction_vector=function(){var a=this.linearize();if(a==null){return null}else{return a.get_last_object().compute_direction_vector()}};
