Line.prototype=new Extra_Graphics();Line.prototype.constructor=Line;function Line(b,a){this._p1=b;this._p2=a;this._optimized_drawing=false}Line.prototype.draw=function(d){try{var f=_MAP_WRAPPER.convert_to_pixel(this._p1._x,this._p1._y,true);var c=_MAP_WRAPPER.convert_to_pixel(this._p2._x,this._p2._y,true);d.setStroke(this._stroke);d.setColor(this._color);d.setPrintable(this._printable);var a=this.clip(f[0],f[1],c[0],c[1]);if(a!=null){if(this._optimized_drawing){d.drawRect(parseInt(a[0])-5*0.5,parseInt(a[1])-5*0.5,5,5);d.drawRect(parseInt(a[2])-5*0.5,parseInt(a[3])-5*0.5,5,5)}else{d.drawLine(parseInt(a[0]),parseInt(a[1]),parseInt(a[2]),parseInt(a[3]))}}}catch(b){throw"Line.draw(): "+b}};Line.prototype.clip=function(b,h,a,g){try{var d=this.code(b,h);var c=this.code(a,g);var j=0;var i=0;while(d|c){if(d&c){return null}j=a-b;i=g-h;if(d){if(b<0){h+=i*(0-b)/j;b=0}else{if(b>_MAP_WRAPPER._width){h+=i*(_MAP_WRAPPER._width-b)/j;b=_MAP_WRAPPER._width}else{if(h<0){b+=j*(0-h)/i;h=0}else{if(h>_MAP_WRAPPER._height){b+=j*(_MAP_WRAPPER._height-h)/i;h=_MAP_WRAPPER._height}}}}d=this.code(b,h)}else{if(a<0){g+=i*(0-a)/j;a=0}else{if(a>_MAP_WRAPPER._width){g+=i*(_MAP_WRAPPER._width-a)/j;a=_MAP_WRAPPER._width}else{if(g<0){a+=j*(0-g)/i;g=0}else{if(g>_MAP_WRAPPER._height){a+=j*(_MAP_WRAPPER._height-g)/i;g=_MAP_WRAPPER._height}}}}c=this.code(a,g)}}return new Array(b,h,a,g)}catch(f){throw"Line.clip(): "+f}};Line.prototype.code=function(a,b){return(a<0)<<3|(a>_MAP_WRAPPER._width)<<2|(b<0)<<1|(b>_MAP_WRAPPER._height)};Line.prototype.to_post_request=function(){var a=new Array();a[0]=this._p1._x+"_"+this._p2._x;a[1]=this._p1._y+"_"+this._p2._y;return a};Line.prototype.compute_direction_vector=function(){return new Point(this._p2._x-this._p1._x,this._p2._y-this._p1._y)};Line.prototype.distance_from_point=function(r,n,g){try{var h=this._p1._x;var s=this._p1._y;var f=this._p2._x;var q=this._p2._y;function d(a,e,b,c){return Math.sqrt((a-=b)*a+(e-=c)*e)}if(g&&!(g=function(a,v,c,o,b,e){if(!(b-c)){return{x:c,y:v}}else{if(!(e-o)){return{x:a,y:o}}}var u,t=-1/((e-o)/(b-c));return{x:u=(b*(a*t-v+o)+c*(a*-t+v-e))/(t*(b-c)+o-e),y:t*u-t*a+v}}(r,n,h,s,f,q),g.x>=Math.min(h,f)&&g.x<=Math.max(h,f)&&g.y>=Math.min(s,q)&&g.y<=Math.max(s,q))){var j=d(r,n,h,s),i=d(r,n,f,q);return j>i?i:j}else{var p=s-q,m=f-h,l=h*q-s*f;return Math.abs(p*r+m*n+l)/Math.sqrt(p*p+m*m)}}catch(k){throw"Line.distance_from_point() "+k}};Line.prototype.intersect_point_line=function(j){var b=this._p2._y-this._p1._y;var i=this._p1._x-this._p2._x;var d=this._p2._x*this._p1._y-this._p1._x*this._p2._y;var a=j._p2._y-j._p1._y;var g=j._p1._x-j._p2._x;var c=j._p2._x*j._p1._y-j._p1._x*j._p2._y;var e=b*g-a*i;if(e==0){alert("Lines are parralel");return false}var h=(i*c-g*d)/e;var f=(a*d-b*c)/e;return new Point(h,f)};Line.prototype.move=function(b,a){this._p1.move(b,a);this._p2.move(b,a)};Line.prototype.equals=function(a){return((this._p1.equals(a._p1)&&this._p2.equals(a._p2))||(this._p1.equals(a._p2)&&this._p2.equals(a._p1)))};Line.prototype.clone=function(){return new Line(this._p1.clone(),this._p2.clone())};Line.prototype.invert_points=function(){var a=this._p1;this._p1=this._p2;this._p2=a};Line.prototype.to_string=function(){return"Line: "+this._p1._x+" "+this._p1._y+", "+this._p2._x+" "+this._p2._y};Line.prototype.geo_side=function(a,b){return(this._p2._x-this._p1._x)*(b-this._p1._y)-(this._p2._y-this._p1._y)*(a-this._p1._x)};
