1 line
31 KiB
JavaScript
1 line
31 KiB
JavaScript
|
(function(){var t=function(){"use strict";function t(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var e=Math.tan,s=Math.pow,i=Math.cos,h=Math.sin,a=Math.PI,n=Math.sqrt,l=Math.max,r=Math.min,o=Math.abs,c=Number.MAX_VALUE;class p{constructor(e,s,i,h){this.RoughSegmentRelationConst=t(),this.px1=e,this.py1=s,this.px2=i,this.py2=h,this.xi=c,this.yi=c,this.a=h-s,this.b=e-i,this.c=i*s-e*h,this._undefined=0==this.a&&0==this.b&&0==this.c}isUndefined(){return this._undefined}compare(t){if(this.isUndefined()||t.isUndefined())return this.RoughSegmentRelationConst.UNDEFINED;var e=c,s=c,i=0,h=0,a=this.a,n=this.b,p=this.c;return 1e-5<o(n)&&(e=-a/n,i=-p/n),1e-5<o(t.b)&&(s=-t.a/t.b,h=-t.c/t.b),e==c?s==c?-p/a==-t.c/t.a?this.py1>=r(t.py1,t.py2)&&this.py1<=l(t.py1,t.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=r(t.py1,t.py2)&&this.py2<=l(t.py1,t.py2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=this.px1,this.yi=s*this.xi+h,-1e-5>(this.py1-this.yi)*(this.yi-this.py2)||-1e-5>(t.py1-this.yi)*(this.yi-t.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>o(t.a)&&-1e-5>(t.px1-this.xi)*(this.xi-t.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS):s==c?(this.xi=t.px1,this.yi=e*this.xi+i,-1e-5>(t.py1-this.yi)*(this.yi-t.py2)||-1e-5>(this.py1-this.yi)*(this.yi-this.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>o(a)&&-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS):e==s?i==h?this.px1>=r(t.px1,t.px2)&&this.px1<=l(t.py1,t.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=r(t.px1,t.px2)&&this.px2<=l(t.px1,t.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(h-i)/(e-s),this.yi=e*this.xi+i,-1e-5>(this.px1-this.xi)*(this.xi-this.px2)||-1e-5>(t.px1-this.xi)*(this.xi-t.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS)}getLength(){return this._getLength(this.px1,this.py1,this.px2,this.py2)}_getLength(t,e,s,i){var h=s-t,a=i-e;return n(h*h+a*a)}}class f{constructor(t,e,s,i,h,a,n,l){this.top=t,this.bottom=e,this.left=s,this.right=i,this.gap=h,this.sinAngle=a,this.tanAngle=l,1e-4>o(a)?this.pos=s+h:.9999<o(a)?this.pos=t+h:(this.deltaX=(e-t)*o(l),this.pos=s-o(this.deltaX),this.hGap=o(h/n),this.sLeft=new p(s,e,s,t),this.sRight=new p(i,e,i,t))}getNextLine(){if(1e-4>o(this.sinAngle)){if(this.pos<this.right){let t=[this.pos,this.top,this.pos,this.bottom];return this.pos+=this.gap,t}}else if(.9999<o(this.sinAngle)){if(this.pos<this.bottom){let t=[this.left,this.pos,this.right,this.pos];return this.pos+=this.gap,t}}else{let e=this.pos-this.deltaX/2,s=this.pos+this.deltaX/2,i=this.bottom,h=this.top;if(this.pos<this.right+this.deltaX){for(;e<this.left&&s<this.left||e>this.right&&s>this.right;)if(this.pos+=this.hGap,e=this.pos-this.deltaX/2,s=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;let a=new p(e,i,s,h);a.compare(this.sLeft)==t().INTERSECTS&&(e=a.xi,i=a.yi),a.compare(this.sRight)==t().INTERSECTS&&(s=a.xi,h=a.yi),0<this.tanAngle&&(e=this.right-(e-this.left),s=this.right-(s-this.left));let n=[e,i,s,h];return this.pos+=this.hGap,n}}return null}}class u{constructor(t,e){this.type=t,this.text=e}isType(t){return this.type===t}}class g{constructor(t){this.PARAMS={A:["rx","ry","x-axis-rotation","large-arc-flag","sweep-flag","x","y"],a:["rx","ry","x-axis-rotation","large-arc-flag","sweep-flag","x","y"],C:["x1","y1","x2","y2","x","y"],c:["x1","y1","x2","y2","x","y"],H:["x"],h:["x"],L:["x","y"],l:["x","y"],M:["x","y"],m:["x","y"],Q:["x1","y1","x","y"],q:["x1","y1","x","y"],S:["x2","y2","x","y"],s:["x2","y2","x","y"],T:["x","y"],t:["x","y"],V:["y"],v:["y"],Z:[],z:[]},this.COMMAND=0,this.NUMBER=1,this.EOD=2,this.segments=[],this.d=t||"",this.parse
|