From 3eb4ddea440863ae440dda7c9b29aa0945aa518a Mon Sep 17 00:00:00 2001 From: Preet Shihn Date: Sat, 12 May 2018 14:58:29 -0700 Subject: [PATCH 1/2] fixed a bug in Arc to Curve convertor --- dist/rough.js | 4 ++-- dist/rough.min.js | 2 +- dist/rough.umd.js | 4 ++-- dist/rough.umd.min.js | 2 +- src/path.js | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/rough.js b/dist/rough.js index 3efedcb..cd318ab 100644 --- a/dist/rough.js +++ b/dist/rough.js @@ -510,8 +510,8 @@ class RoughArcConverter { var numerator = this._rx * this._rx * this._ry * this._ry - this._rx * this._rx * y1dash * y1dash - this._ry * this._ry * x1dash * x1dash; if (numerator < 0) { let s = Math.sqrt(1 - (numerator / (this._rx * this._rx * this._ry * this._ry))); - this._rx = s; - this._ry = s; + this._rx = this._rx * s; + this._ry = this._ry * s; root = 0; } else { root = (largeArcFlag == sweepFlag ? -1.0 : 1.0) * diff --git a/dist/rough.min.js b/dist/rough.min.js index 2c7a126..2c2119a 100644 --- a/dist/rough.min.js +++ b/dist/rough.min.js @@ -1 +1 @@ -var rough=function(){"use strict";function a(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var b=Math.round,c=Math.tan,d=Math.pow,e=Math.floor,f=Math.cos,g=Math.sin,h=Math.PI,j=Math.sqrt,k=Math.max,l=Math.min,i=Math.abs,m=Number.MAX_VALUE;class n{constructor(b,c,d,e){this.RoughSegmentRelationConst=a(),this.px1=b,this.py1=c,this.px2=d,this.py2=e,this.xi=m,this.yi=m,this.a=e-c,this.b=b-d,this.c=d*c-b*e,this._undefined=0==this.a&&0==this.b&&0==this.c}isUndefined(){return this._undefined}compare(d){if(this.isUndefined()||d.isUndefined())return this.RoughSegmentRelationConst.UNDEFINED;var e=m,f=m,g=0,h=0,j=this.a,n=this.b,b=this.c;return(1e-5=l(d.py1,d.py2)&&this.py1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=l(d.py1,d.py2)&&this.py2<=k(d.py1,d.py2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=this.px1,this.yi=f*this.xi+h,-1e-5>(this.py1-this.yi)*(this.yi-this.py2)||-1e-5>(d.py1-this.yi)*(this.yi-d.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(d.a)?-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):f==m?(this.xi=d.px1,this.yi=e*this.xi+g,-1e-5>(d.py1-this.yi)*(this.yi-d.py2)||-1e-5>(this.py1-this.yi)*(this.yi-this.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(j)?-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):e==f?g==h?this.px1>=l(d.px1,d.px2)&&this.px1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=l(d.px1,d.px2)&&this.px2<=k(d.px1,d.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(h-g)/(e-f),this.yi=e*this.xi+g,-1e-5>(this.px1-this.xi)*(this.xi-this.px2)||-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS)}getLength(){return this._getLength(this.px1,this.py1,this.px2,this.py2)}_getLength(a,b,c,d){var e=c-a,f=d-b;return j(e*e+f*f)}}class p{constructor(a,b,c,d,e,f,g,h){this.top=a,this.bottom=b,this.left=c,this.right=d,this.gap=e,this.sinAngle=f,this.tanAngle=h,1e-4>i(f)?this.pos=c+e:.9999i(this.sinAngle)){if(this.posthis.right&&c>this.right;)if(this.pos+=this.hGap,b=this.pos-this.deltaX/2,c=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;let f=new n(b,d,c,e);f.compare(this.sLeft)==a().INTERSECTS&&(b=f.xi,d=f.yi),f.compare(this.sRight)==a().INTERSECTS&&(c=f.xi,e=f.yi),0p){let a=j(1-p/(this._rx*this._rx*this._ry*this._ry));this._rx=a,this._ry=a,m=0}else m=(e==k?-1:1)*j(p/(this._rx*this._rx*o*o+this._ry*this._ry*n*n));let q=m*this._rx*o/this._ry,r=-m*this._ry*n/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*q-this._sinPhi*r+(a[0]+b[0])/2,this._C[1]=this._sinPhi*q+this._cosPhi*r+(a[1]+b[1])/2,this._theta=this.calculateVectorAngle(1,0,(n-q)/this._rx,(o-r)/this._ry);let s=this.calculateVectorAngle((n-q)/this._rx,(o-r)/this._ry,(-n-q)/this._rx,(-o-r)/this._ry);!k&&0s&&(s+=2*h),this._numSegs=Math.ceil(i(s/(h/2))),this._delta=s/this._numSegs,this._T=8/3*g(this._delta/4)*g(this._delta/4)/g(this._delta/2),this._from=a}getNextSegment(){var a,b,c;if(this._segIndex==this._numSegs)return null;let d=f(this._theta),e=g(this._theta),h=this._theta+this._delta,i=f(h),j=g(h);return c=[this._cosPhi*this._rx*i-this._sinPhi*this._ry*j+this._C[0],this._sinPhi*this._rx*i+this._cosPhi*this._ry*j+this._C[1]],a=[this._from[0]+this._T*(-this._cosPhi*this._rx*e-this._sinPhi*this._ry*d),this._from[1]+this._T*(-this._sinPhi*this._rx*e+this._cosPhi*this._ry*d)],b=[c[0]+this._T*(this._cosPhi*this._rx*j+this._sinPhi*this._ry*i),c[1]+this._T*(this._sinPhi*this._rx*j-this._cosPhi*this._ry*i)],this._theta=h,this._from=[c[0],c[1]],this._segIndex++,{cp1:a,cp2:b,to:c}}calculateVectorAngle(a,b,c,d){var e=Math.atan2;let f=e(b,a),g=e(d,c);return g>=f?g-f:2*h-(f-g)}}class t{constructor(a,b){this.sets=a,this.closed=b}fit(a){let b=[];for(const c of this.sets){let d=c.length,f=e(a*d);if(5>f){if(5>=d)continue;f=5}b.push(this.reduce(c,f))}let c="";for(const d of b){for(let a,b=0;bb;){let e=-1,f=-1;for(let g=1;ge||is;)s+=2*h,t+=2*h;t-s>2*h&&(s=0,t=2*h);let u=2*h/n.curveStepCount,v=l(u/2,(t-s)/2),w=this._arc(v,o,p,q,r,s,t,1,n),x=this._arc(v,o,p,q,r,s,t,1.5,n),y=w.concat(x);return k&&(m?(y=y.concat(this._doubleLine(o,p,o+q*f(s),p+r*g(s),n)),y=y.concat(this._doubleLine(o,p,o+q*f(t),p+r*g(t),n))):(y.push({op:"lineTo",data:[o,p]}),y.push({op:"lineTo",data:[o+q*f(s),p+r*g(s)]}))),{type:"path",ops:y}}hachureFillArc(a,b,c,d,e,j,k){let l=a,m=b,n=i(c/2),o=i(d/2);n+=this._getOffset(.01*-n,.01*n,k),o+=this._getOffset(.01*-o,.01*o,k);let p=e,q=j;for(;0>p;)p+=2*h,q+=2*h;q-p>2*h&&(p=0,q=2*h);let r=(q-p)/k.curveStepCount,s=[],t=[];for(let h=p;h<=q;h+=r)s.push(l+n*f(h)),t.push(m+o*g(h));return s.push(l+n*f(q)),t.push(m+o*g(q)),s.push(l),t.push(m),this.hachureFillShape(s,t,k)}solidFillShape(a,b,c){let d=[];if(a&&b&&a.length&&b.length&&a.length===b.length){let f=c.maxRandomnessOffset||0;const g=a.length;if(2q&&(q=4*d.strokeWidth),q=k(q,.1);const r=i%180*(h/180),s=f(r),t=g(r),u=c(r),v=new p(n-1,o+1,j-1,m+1,q,t,s,u);for(let c;null!=(c=v.getNextLine());){let f=this._getIntersectingLines(c,a,b);for(let a=0;a=n&&(n=4*f.strokeWidth);let o=f.fillWeight;0>o&&(o=f.strokeWidth/2);let p=c(m%180*(h/180)),q=l/k,r=j(q*p*q*p+1),s=q*p/r,t=1/r,u=n/(k*l/j(l*t*(l*t)+k*s*(k*s))/k),v=j(k*k-(a-k+u)*(a-k+u));for(var w=a-k+u;wf;f++)0===f?k.push({op:"move",data:[h.x,h.y]}):k.push({op:"move",data:[h.x+this._getOffset(-l[0],l[0],j),h.y+this._getOffset(-l[0],l[0],j)]}),m=[e+this._getOffset(-l[f],l[f],j),g+this._getOffset(-l[f],l[f],j)],k.push({op:"bcurveTo",data:[a+this._getOffset(-l[f],l[f],j),b+this._getOffset(-l[f],l[f],j),c+this._getOffset(-l[f],l[f],j),d+this._getOffset(-l[f],l[f],j),m[0],m[1]]});return h.setPosition(m[0],m[1]),k}_processSegment(a,b,c,d){let e=[];switch(b.key){case"M":case"m":{let c="m"===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y);let h=1*(d.maxRandomnessOffset||0);f+=this._getOffset(-h,h,d),g+=this._getOffset(-h,h,d),a.setPosition(f,g),e.push({op:"move",data:[f,g]})}break}case"L":case"l":{let c="l"===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y),e=e.concat(this._doubleLine(a.x,a.y,f,g,d)),a.setPosition(f,g)}break}case"H":case"h":{const c="h"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.x),e=e.concat(this._doubleLine(a.x,a.y,f,a.y,d)),a.setPosition(f,a.y)}break}case"V":case"v":{const c="v"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.y),e=e.concat(this._doubleLine(a.x,a.y,a.x,f,d)),a.setPosition(a.x,f)}break}case"Z":case"z":{a.first&&(e=e.concat(this._doubleLine(a.x,a.y,a.first[0],a.first[1],d)),a.setPosition(a.first[0],a.first[1]),a.first=null);break}case"C":case"c":{const c="c"===b.key;if(6<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5];c&&(f+=a.x,h+=a.x,j+=a.x,g+=a.y,i+=a.y,k+=a.y);let l=this._bezierTo(f,g,h,i,j,k,a,d);e=e.concat(l),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case"S":case"s":{const f="s"===b.key;if(4<=b.data.length){let h=+b.data[0],i=+b.data[1],j=+b.data[2],k=+b.data[3];f&&(h+=a.x,j+=a.x,i+=a.y,k+=a.y);let l=h,m=i,n=c?c.key:"";var g=null;("c"==n||"C"==n||"s"==n||"S"==n)&&(g=a.bezierReflectionPoint),g&&(l=g[0],m=g[1]);let o=this._bezierTo(l,m,h,i,j,k,a,d);e=e.concat(o),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case"Q":case"q":{const c="q"===b.key;if(4<=b.data.length){let g=+b.data[0],h=+b.data[1],i=+b.data[2],j=+b.data[3];c&&(g+=a.x,i+=a.x,h+=a.y,j+=a.y);let k=1*(1+.2*d.roughness),l=1.5*(1+.22*d.roughness);e.push({op:"move",data:[a.x+this._getOffset(-k,k,d),a.y+this._getOffset(-k,k,d)]});let m=[i+this._getOffset(-k,k,d),j+this._getOffset(-k,k,d)];e.push({op:"qcurveTo",data:[g+this._getOffset(-k,k,d),h+this._getOffset(-k,k,d),m[0],m[1]]}),e.push({op:"move",data:[a.x+this._getOffset(-l,l,d),a.y+this._getOffset(-l,l,d)]}),m=[i+this._getOffset(-l,l,d),j+this._getOffset(-l,l,d)],e.push({op:"qcurveTo",data:[g+this._getOffset(-l,l,d),h+this._getOffset(-l,l,d),m[0],m[1]]}),a.setPosition(m[0],m[1]),a.quadReflectionPoint=[i+(i-g),j+(j-h)]}break}case"T":case"t":{const h="t"===b.key;if(2<=b.data.length){let i=+b.data[0],j=+b.data[1];h&&(i+=a.x,j+=a.y);let k=i,l=j,m=c?c.key:"";var g=null;("q"==m||"Q"==m||"t"==m||"T"==m)&&(g=a.quadReflectionPoint),g&&(k=g[0],l=g[1]);let n=1*(1+.2*d.roughness),o=1.5*(1+.22*d.roughness);e.push({op:"move",data:[a.x+this._getOffset(-n,n,d),a.y+this._getOffset(-n,n,d)]});let p=[i+this._getOffset(-n,n,d),j+this._getOffset(-n,n,d)];e.push({op:"qcurveTo",data:[k+this._getOffset(-n,n,d),l+this._getOffset(-n,n,d),p[0],p[1]]}),e.push({op:"move",data:[a.x+this._getOffset(-o,o,d),a.y+this._getOffset(-o,o,d)]}),p=[i+this._getOffset(-o,o,d),j+this._getOffset(-o,o,d)],e.push({op:"qcurveTo",data:[k+this._getOffset(-o,o,d),l+this._getOffset(-o,o,d),p[0],p[1]]}),a.setPosition(p[0],p[1]),a.quadReflectionPoint=[i+(i-k),j+(j-l)]}break}case"A":case"a":{const c="a"===b.key;if(7<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5],l=+b.data[6];if(c&&(k+=a.x,l+=a.y),k==a.x&&l==a.y)break;if(0==f||0==g)e=e.concat(this._doubleLine(a.x,a.y,k,l,d)),a.setPosition(k,l);else{d.maxRandomnessOffset||0;for(let b=0;1>b;b++){let b=new s([a.x,a.y],[k,l],[f,g],h,!!i,!!j),c=b.getNextSegment();for(;c;){let f=this._bezierTo(c.cp1[0],c.cp1[1],c.cp2[0],c.cp2[1],c.to[0],c.to[1],a,d);e=e.concat(f),c=b.getNextSegment()}}}}break}default:}return e}_getOffset(a,b,c){return c.roughness*(Math.random()*(b-a)+a)}_affine(a,b,c,d,e,f,g){return[-c*f-d*e+c+f*a+e*b,g*(c*e-d*f)+d+-g*e*a+g*f*b]}_doubleLine(a,b,c,d,e){const f=this._line(a,b,c,d,e,!0,!1),g=this._line(a,b,c,d,e,!0,!0);return f.concat(g)}_line(a,b,c,e,f,g,h){const i=d(a-c,2)+d(b-e,2);let k=f.maxRandomnessOffset||0;100*(k*k)>i&&(k=j(i)/10);const l=k/2,m=.2+.2*Math.random();let n=f.bowing*f.maxRandomnessOffset*(e-b)/200,o=f.bowing*f.maxRandomnessOffset*(a-c)/200;n=this._getOffset(-n,n,f),o=this._getOffset(-o,o,f);let p=[];return g&&(h?p.push({op:"move",data:[a+this._getOffset(-l,l,f),b+this._getOffset(-l,l,f)]}):p.push({op:"move",data:[a+this._getOffset(-k,k,f),b+this._getOffset(-k,k,f)]})),h?p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-l,l,f),o+b+(e-b)*m+this._getOffset(-l,l,f),n+a+2*(c-a)*m+this._getOffset(-l,l,f),o+b+2*(e-b)*m+this._getOffset(-l,l,f),c+this._getOffset(-l,l,f),e+this._getOffset(-l,l,f)]}):p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-k,k,f),o+b+(e-b)*m+this._getOffset(-k,k,f),n+a+2*(c-a)*m+this._getOffset(-k,k,f),o+b+2*(e-b)*m+this._getOffset(-k,k,f),c+this._getOffset(-k,k,f),e+this._getOffset(-k,k,f)]}),p}_curve(a,c,d){const e=a.length;let f=[];if(3c&&(c=b.strokeWidth/2),{d:this.opsToPath(a),stroke:b.fill,strokeWidth:c,fill:"none"}}opsToPath(a){let b="";for(let c of a.ops){const a=c.data;switch(c.op){case"move":b+=`M${a[0]} ${a[1]} `;break;case"bcurveTo":b+=`C${a[0]} ${a[1]}, ${a[2]} ${a[3]}, ${a[4]} ${a[5]} `;break;case"qcurveTo":b+=`Q${a[0]} ${a[1]}, ${a[2]} ${a[3]} `;break;case"lineTo":b+=`L${a[0]} ${a[1]} `;}}return b.trim()}_computePathSize(a){let b=[0,0];if(self.document)try{const c="http://www.w3.org/2000/svg";let d=self.document.createElementNS(c,"svg");d.setAttribute("width","0"),d.setAttribute("height","0");let e=self.document.createElementNS(c,"path");e.setAttribute("d",a),d.appendChild(e),self.document.body.appendChild(d);let f=e.getBBox();f&&(b[0]=f.width||0,b[1]=f.height||0),self.document.body.removeChild(d)}catch(a){}const c=this._canvasSize();return b[0]*b[1]||(b=c),b[0]=l(b[0],c[0]),b[1]=l(b[1],c[1]),b}_canvasSize(){const a=(a)=>a&&"object"==typeof a&&a.baseVal&&a.baseVal.value?a.baseVal.value:a||100;return this.canvas?[a(this.canvas.width),a(this.canvas.height)]:[100,100]}}class w extends v{async line(a,b,c,d,e){const f=this._options(e);return this._drawable("line",[await this.lib.line(a,b,c,d,f)],f)}async rectangle(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill){const e=[a,a+c,a+c,a],h=[b,b,b+d,b+d];"solid"===f.fillStyle?g.push((await this.lib.solidFillShape(e,h,f))):g.push((await this.lib.hachureFillShape(e,h,f)))}return g.push((await this.lib.rectangle(a,b,c,d,f))),this._drawable("rectangle",g,f)}async ellipse(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill)if("solid"===f.fillStyle){const e=await this.lib.ellipse(a,b,c,d,f);e.type="fillPath",g.push(e)}else g.push((await this.lib.hachureFillEllipse(a,b,c,d,f)));return g.push((await this.lib.ellipse(a,b,c,d,f))),this._drawable("ellipse",g,f)}async circle(a,b,c,d){let e=await this.ellipse(a,b,c,c,d);return e.shape="circle",e}async linearPath(a,b){const c=this._options(b);return this._drawable("linearPath",[await this.lib.linearPath(a,!1,c)],c)}async polygon(a,b){const c=this._options(b),d=[];if(c.fill){let b=[],e=[];for(let c of a)b.push(c[0]),e.push(c[1]);"solid"===c.fillStyle?d.push((await this.lib.solidFillShape(b,e,c))):d.push((await this.lib.hachureFillShape(b,e,c)))}return d.push((await this.lib.linearPath(a,!0,c))),this._drawable("polygon",d,c)}async arc(a,b,c,d,e,f,g,h){const i=this._options(h),j=[];if(g&&i.fill)if("solid"===i.fillStyle){let g=await this.lib.arc(a,b,c,d,e,f,!0,!1,i);g.type="fillPath",j.push(g)}else j.push((await this.lib.hachureFillArc(a,b,c,d,e,f,i)));return j.push((await this.lib.arc(a,b,c,d,e,f,g,!0,i))),this._drawable("arc",j,i)}async curve(a,b){const c=this._options(b);return this._drawable("curve",[await this.lib.curve(a,c)],c)}async path(a,b){const c=this._options(b),e=[];if(!a)return this._drawable("path",e,c);if(c.fill)if("solid"===c.fillStyle){e.push({type:"path2Dfill",path:a})}else{const b=this._computePathSize(a);let d=[0,b[0],b[0],0],f=[0,0,b[1],b[1]],g=await this.lib.hachureFillShape(d,f,c);g.type="path2Dpattern",g.size=b,g.path=a,e.push(g)}return e.push((await this.lib.svgPath(a,c))),this._drawable("path",e,c)}}class x{constructor(a,b){this.canvas=a,this.ctx=this.canvas.getContext("2d"),this._init(b)}_init(a){this.gen=new v(a,this.canvas)}get generator(){return this.gen}static createRenderer(){return new u}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g),g}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f),f}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c),c}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c),c}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c),c}path(a,b){let c=this.gen.path(a,b);return this.draw(c),c}draw(a){let b=a.sets||[],c=a.options||this.gen.defaultOptions,d=this.ctx;for(let e of b)switch(e.type){case"path":d.save(),d.strokeStyle=c.stroke,d.lineWidth=c.strokeWidth,this._drawToContext(d,e),d.restore();break;case"fillPath":d.save(),d.fillStyle=c.fill,this._drawToContext(d,e,c),d.restore();break;case"fillSketch":this._fillSketch(d,e,c);break;case"path2Dfill":{this.ctx.save(),this.ctx.fillStyle=c.fill;let a=new Path2D(e.path);this.ctx.fill(a),this.ctx.restore();break}case"path2Dpattern":{let a=e.size;const b=document.createElement("canvas"),d=b.getContext("2d");let f=this._computeBBox(e.path);f&&(f.width||f.height)?(b.width=this.canvas.width,b.height=this.canvas.height,d.translate(f.x||0,f.y||0)):(b.width=a[0],b.height=a[1]),this._fillSketch(d,e,c),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(b,"repeat");let g=new Path2D(e.path);this.ctx.fill(g),this.ctx.restore();break}}}_computeBBox(a){if(self.document)try{const b="http://www.w3.org/2000/svg";let c=self.document.createElementNS(b,"svg");c.setAttribute("width","0"),c.setAttribute("height","0");let d=self.document.createElementNS(b,"path");d.setAttribute("d",a),c.appendChild(d),self.document.body.appendChild(c);let e=d.getBBox();return self.document.body.removeChild(c),e}catch(a){}return null}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2),a.save(),a.strokeStyle=c.fill,a.lineWidth=d,this._drawToContext(a,b),a.restore()}_drawToContext(a,b){a.beginPath();for(let c of b.ops){const b=c.data;switch(c.op){case"move":a.moveTo(b[0],b[1]);break;case"bcurveTo":a.bezierCurveTo(b[0],b[1],b[2],b[3],b[4],b[5]);break;case"qcurveTo":a.quadraticCurveTo(b[0],b[1],b[2],b[3]);break;case"lineTo":a.lineTo(b[0],b[1]);}}"fillPath"===b.type?a.fill():a.stroke()}}class y extends x{_init(a){this.gen=new w(a,this.canvas)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g),g}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f),f}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c),c}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c),c}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c),c}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c),c}}class z{constructor(a,b){this.svg=a,this._init(b)}_init(a){this.gen=new v(a,this.svg)}get generator(){return this.gen}get defs(){if(!this._defs){let a=this.svg.ownerDocument||document,b=a.createElementNS("http://www.w3.org/2000/svg","defs");this.svg.firstChild?this.svg.insertBefore(b,this.svg.firstChild):this.svg.appendChild(b),this._defs=b}return this._defs}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g)}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g)}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g)}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f)}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c)}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c)}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c)}path(a,b){let c=this.gen.path(a,b);return this.draw(c)}draw(a){let c=a.sets||[],d=a.options||this.gen.defaultOptions,f=this.svg.ownerDocument||document,h=f.createElementNS("http://www.w3.org/2000/svg","g");for(let g of c){let a=null;switch(g.type){case"path":{a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",this._opsToPath(g)),a.style.stroke=d.stroke,a.style.strokeWidth=d.strokeWidth,a.style.fill="none";break}case"fillPath":{a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",this._opsToPath(g)),a.style.stroke="none",a.style.strokeWidth=0,a.style.fill=d.fill;break}case"fillSketch":{a=this._fillSketch(f,g,d);break}case"path2Dfill":{a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",g.path),a.style.stroke="none",a.style.strokeWidth=0,a.style.fill=d.fill;break}case"path2Dpattern":{const c=g.size,h=f.createElementNS("http://www.w3.org/2000/svg","pattern"),i=`rough-${e(Math.random()*(Number.MAX_SAFE_INTEGER||999999))}`;h.setAttribute("id",i),h.setAttribute("x",0),h.setAttribute("y",0),h.setAttribute("width",1),h.setAttribute("height",1),h.setAttribute("height",1),h.setAttribute("viewBox",`0 0 ${b(c[0])} ${b(c[1])}`),h.setAttribute("patternUnits","objectBoundingBox");const j=this._fillSketch(f,g,d);h.appendChild(j),this.defs.appendChild(h),a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",g.path),a.style.stroke="none",a.style.strokeWidth=0,a.style.fill=`url(#${i})`;break}}a&&h.appendChild(a)}return h}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2);let e=a.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d",this._opsToPath(b)),e.style.stroke=c.fill,e.style.strokeWidth=d,e.style.fill="none",e}_opsToPath(a){return this.gen.opsToPath(a)}}class A extends z{_init(a){this.gen=new w(a,this.svg)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g)}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g)}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g)}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f)}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c)}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c)}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c)}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c)}}var B={canvas(a,b){return b&&b.async?new y(a,b):new x(a,b)},svg(a,b){return b&&b.async?new A(a,b):new z(a,b)},createRenderer(){return x.createRenderer()},generator(a,b){return a&&a.async?new w(a,b):new v(a,b)}};return B}(); \ No newline at end of file +var rough=function(){"use strict";function a(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var b=Math.round,c=Math.tan,d=Math.pow,e=Math.floor,f=Math.cos,g=Math.sin,h=Math.PI,j=Math.sqrt,k=Math.max,l=Math.min,i=Math.abs,m=Number.MAX_VALUE;class n{constructor(b,c,d,e){this.RoughSegmentRelationConst=a(),this.px1=b,this.py1=c,this.px2=d,this.py2=e,this.xi=m,this.yi=m,this.a=e-c,this.b=b-d,this.c=d*c-b*e,this._undefined=0==this.a&&0==this.b&&0==this.c}isUndefined(){return this._undefined}compare(d){if(this.isUndefined()||d.isUndefined())return this.RoughSegmentRelationConst.UNDEFINED;var e=m,f=m,g=0,h=0,j=this.a,n=this.b,b=this.c;return(1e-5=l(d.py1,d.py2)&&this.py1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=l(d.py1,d.py2)&&this.py2<=k(d.py1,d.py2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=this.px1,this.yi=f*this.xi+h,-1e-5>(this.py1-this.yi)*(this.yi-this.py2)||-1e-5>(d.py1-this.yi)*(this.yi-d.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(d.a)?-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):f==m?(this.xi=d.px1,this.yi=e*this.xi+g,-1e-5>(d.py1-this.yi)*(this.yi-d.py2)||-1e-5>(this.py1-this.yi)*(this.yi-this.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(j)?-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):e==f?g==h?this.px1>=l(d.px1,d.px2)&&this.px1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=l(d.px1,d.px2)&&this.px2<=k(d.px1,d.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(h-g)/(e-f),this.yi=e*this.xi+g,-1e-5>(this.px1-this.xi)*(this.xi-this.px2)||-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS)}getLength(){return this._getLength(this.px1,this.py1,this.px2,this.py2)}_getLength(a,b,c,d){var e=c-a,f=d-b;return j(e*e+f*f)}}class p{constructor(a,b,c,d,e,f,g,h){this.top=a,this.bottom=b,this.left=c,this.right=d,this.gap=e,this.sinAngle=f,this.tanAngle=h,1e-4>i(f)?this.pos=c+e:.9999i(this.sinAngle)){if(this.posthis.right&&c>this.right;)if(this.pos+=this.hGap,b=this.pos-this.deltaX/2,c=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;let f=new n(b,d,c,e);f.compare(this.sLeft)==a().INTERSECTS&&(b=f.xi,d=f.yi),f.compare(this.sRight)==a().INTERSECTS&&(c=f.xi,e=f.yi),0p){let a=j(1-p/(this._rx*this._rx*this._ry*this._ry));this._rx*=a,this._ry*=a,m=0}else m=(e==k?-1:1)*j(p/(this._rx*this._rx*o*o+this._ry*this._ry*n*n));let q=m*this._rx*o/this._ry,r=-m*this._ry*n/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*q-this._sinPhi*r+(a[0]+b[0])/2,this._C[1]=this._sinPhi*q+this._cosPhi*r+(a[1]+b[1])/2,this._theta=this.calculateVectorAngle(1,0,(n-q)/this._rx,(o-r)/this._ry);let s=this.calculateVectorAngle((n-q)/this._rx,(o-r)/this._ry,(-n-q)/this._rx,(-o-r)/this._ry);!k&&0s&&(s+=2*h),this._numSegs=Math.ceil(i(s/(h/2))),this._delta=s/this._numSegs,this._T=8/3*g(this._delta/4)*g(this._delta/4)/g(this._delta/2),this._from=a}getNextSegment(){var a,b,c;if(this._segIndex==this._numSegs)return null;let d=f(this._theta),e=g(this._theta),h=this._theta+this._delta,i=f(h),j=g(h);return c=[this._cosPhi*this._rx*i-this._sinPhi*this._ry*j+this._C[0],this._sinPhi*this._rx*i+this._cosPhi*this._ry*j+this._C[1]],a=[this._from[0]+this._T*(-this._cosPhi*this._rx*e-this._sinPhi*this._ry*d),this._from[1]+this._T*(-this._sinPhi*this._rx*e+this._cosPhi*this._ry*d)],b=[c[0]+this._T*(this._cosPhi*this._rx*j+this._sinPhi*this._ry*i),c[1]+this._T*(this._sinPhi*this._rx*j-this._cosPhi*this._ry*i)],this._theta=h,this._from=[c[0],c[1]],this._segIndex++,{cp1:a,cp2:b,to:c}}calculateVectorAngle(a,b,c,d){var e=Math.atan2;let f=e(b,a),g=e(d,c);return g>=f?g-f:2*h-(f-g)}}class t{constructor(a,b){this.sets=a,this.closed=b}fit(a){let b=[];for(const c of this.sets){let d=c.length,f=e(a*d);if(5>f){if(5>=d)continue;f=5}b.push(this.reduce(c,f))}let c="";for(const d of b){for(let a,b=0;bb;){let e=-1,f=-1;for(let g=1;ge||is;)s+=2*h,t+=2*h;t-s>2*h&&(s=0,t=2*h);let u=2*h/n.curveStepCount,v=l(u/2,(t-s)/2),w=this._arc(v,o,p,q,r,s,t,1,n),x=this._arc(v,o,p,q,r,s,t,1.5,n),y=w.concat(x);return k&&(m?(y=y.concat(this._doubleLine(o,p,o+q*f(s),p+r*g(s),n)),y=y.concat(this._doubleLine(o,p,o+q*f(t),p+r*g(t),n))):(y.push({op:"lineTo",data:[o,p]}),y.push({op:"lineTo",data:[o+q*f(s),p+r*g(s)]}))),{type:"path",ops:y}}hachureFillArc(a,b,c,d,e,j,k){let l=a,m=b,n=i(c/2),o=i(d/2);n+=this._getOffset(.01*-n,.01*n,k),o+=this._getOffset(.01*-o,.01*o,k);let p=e,q=j;for(;0>p;)p+=2*h,q+=2*h;q-p>2*h&&(p=0,q=2*h);let r=(q-p)/k.curveStepCount,s=[],t=[];for(let h=p;h<=q;h+=r)s.push(l+n*f(h)),t.push(m+o*g(h));return s.push(l+n*f(q)),t.push(m+o*g(q)),s.push(l),t.push(m),this.hachureFillShape(s,t,k)}solidFillShape(a,b,c){let d=[];if(a&&b&&a.length&&b.length&&a.length===b.length){let f=c.maxRandomnessOffset||0;const g=a.length;if(2q&&(q=4*d.strokeWidth),q=k(q,.1);const r=i%180*(h/180),s=f(r),t=g(r),u=c(r),v=new p(n-1,o+1,j-1,m+1,q,t,s,u);for(let c;null!=(c=v.getNextLine());){let f=this._getIntersectingLines(c,a,b);for(let a=0;a=n&&(n=4*f.strokeWidth);let o=f.fillWeight;0>o&&(o=f.strokeWidth/2);let p=c(m%180*(h/180)),q=l/k,r=j(q*p*q*p+1),s=q*p/r,t=1/r,u=n/(k*l/j(l*t*(l*t)+k*s*(k*s))/k),v=j(k*k-(a-k+u)*(a-k+u));for(var w=a-k+u;wf;f++)0===f?k.push({op:"move",data:[h.x,h.y]}):k.push({op:"move",data:[h.x+this._getOffset(-l[0],l[0],j),h.y+this._getOffset(-l[0],l[0],j)]}),m=[e+this._getOffset(-l[f],l[f],j),g+this._getOffset(-l[f],l[f],j)],k.push({op:"bcurveTo",data:[a+this._getOffset(-l[f],l[f],j),b+this._getOffset(-l[f],l[f],j),c+this._getOffset(-l[f],l[f],j),d+this._getOffset(-l[f],l[f],j),m[0],m[1]]});return h.setPosition(m[0],m[1]),k}_processSegment(a,b,c,d){let e=[];switch(b.key){case"M":case"m":{let c="m"===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y);let h=1*(d.maxRandomnessOffset||0);f+=this._getOffset(-h,h,d),g+=this._getOffset(-h,h,d),a.setPosition(f,g),e.push({op:"move",data:[f,g]})}break}case"L":case"l":{let c="l"===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y),e=e.concat(this._doubleLine(a.x,a.y,f,g,d)),a.setPosition(f,g)}break}case"H":case"h":{const c="h"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.x),e=e.concat(this._doubleLine(a.x,a.y,f,a.y,d)),a.setPosition(f,a.y)}break}case"V":case"v":{const c="v"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.y),e=e.concat(this._doubleLine(a.x,a.y,a.x,f,d)),a.setPosition(a.x,f)}break}case"Z":case"z":{a.first&&(e=e.concat(this._doubleLine(a.x,a.y,a.first[0],a.first[1],d)),a.setPosition(a.first[0],a.first[1]),a.first=null);break}case"C":case"c":{const c="c"===b.key;if(6<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5];c&&(f+=a.x,h+=a.x,j+=a.x,g+=a.y,i+=a.y,k+=a.y);let l=this._bezierTo(f,g,h,i,j,k,a,d);e=e.concat(l),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case"S":case"s":{const f="s"===b.key;if(4<=b.data.length){let h=+b.data[0],i=+b.data[1],j=+b.data[2],k=+b.data[3];f&&(h+=a.x,j+=a.x,i+=a.y,k+=a.y);let l=h,m=i,n=c?c.key:"";var g=null;("c"==n||"C"==n||"s"==n||"S"==n)&&(g=a.bezierReflectionPoint),g&&(l=g[0],m=g[1]);let o=this._bezierTo(l,m,h,i,j,k,a,d);e=e.concat(o),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case"Q":case"q":{const c="q"===b.key;if(4<=b.data.length){let g=+b.data[0],h=+b.data[1],i=+b.data[2],j=+b.data[3];c&&(g+=a.x,i+=a.x,h+=a.y,j+=a.y);let k=1*(1+.2*d.roughness),l=1.5*(1+.22*d.roughness);e.push({op:"move",data:[a.x+this._getOffset(-k,k,d),a.y+this._getOffset(-k,k,d)]});let m=[i+this._getOffset(-k,k,d),j+this._getOffset(-k,k,d)];e.push({op:"qcurveTo",data:[g+this._getOffset(-k,k,d),h+this._getOffset(-k,k,d),m[0],m[1]]}),e.push({op:"move",data:[a.x+this._getOffset(-l,l,d),a.y+this._getOffset(-l,l,d)]}),m=[i+this._getOffset(-l,l,d),j+this._getOffset(-l,l,d)],e.push({op:"qcurveTo",data:[g+this._getOffset(-l,l,d),h+this._getOffset(-l,l,d),m[0],m[1]]}),a.setPosition(m[0],m[1]),a.quadReflectionPoint=[i+(i-g),j+(j-h)]}break}case"T":case"t":{const h="t"===b.key;if(2<=b.data.length){let i=+b.data[0],j=+b.data[1];h&&(i+=a.x,j+=a.y);let k=i,l=j,m=c?c.key:"";var g=null;("q"==m||"Q"==m||"t"==m||"T"==m)&&(g=a.quadReflectionPoint),g&&(k=g[0],l=g[1]);let n=1*(1+.2*d.roughness),o=1.5*(1+.22*d.roughness);e.push({op:"move",data:[a.x+this._getOffset(-n,n,d),a.y+this._getOffset(-n,n,d)]});let p=[i+this._getOffset(-n,n,d),j+this._getOffset(-n,n,d)];e.push({op:"qcurveTo",data:[k+this._getOffset(-n,n,d),l+this._getOffset(-n,n,d),p[0],p[1]]}),e.push({op:"move",data:[a.x+this._getOffset(-o,o,d),a.y+this._getOffset(-o,o,d)]}),p=[i+this._getOffset(-o,o,d),j+this._getOffset(-o,o,d)],e.push({op:"qcurveTo",data:[k+this._getOffset(-o,o,d),l+this._getOffset(-o,o,d),p[0],p[1]]}),a.setPosition(p[0],p[1]),a.quadReflectionPoint=[i+(i-k),j+(j-l)]}break}case"A":case"a":{const c="a"===b.key;if(7<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5],l=+b.data[6];if(c&&(k+=a.x,l+=a.y),k==a.x&&l==a.y)break;if(0==f||0==g)e=e.concat(this._doubleLine(a.x,a.y,k,l,d)),a.setPosition(k,l);else{d.maxRandomnessOffset||0;for(let b=0;1>b;b++){let b=new s([a.x,a.y],[k,l],[f,g],h,!!i,!!j),c=b.getNextSegment();for(;c;){let f=this._bezierTo(c.cp1[0],c.cp1[1],c.cp2[0],c.cp2[1],c.to[0],c.to[1],a,d);e=e.concat(f),c=b.getNextSegment()}}}}break}default:}return e}_getOffset(a,b,c){return c.roughness*(Math.random()*(b-a)+a)}_affine(a,b,c,d,e,f,g){return[-c*f-d*e+c+f*a+e*b,g*(c*e-d*f)+d+-g*e*a+g*f*b]}_doubleLine(a,b,c,d,e){const f=this._line(a,b,c,d,e,!0,!1),g=this._line(a,b,c,d,e,!0,!0);return f.concat(g)}_line(a,b,c,e,f,g,h){const i=d(a-c,2)+d(b-e,2);let k=f.maxRandomnessOffset||0;100*(k*k)>i&&(k=j(i)/10);const l=k/2,m=.2+.2*Math.random();let n=f.bowing*f.maxRandomnessOffset*(e-b)/200,o=f.bowing*f.maxRandomnessOffset*(a-c)/200;n=this._getOffset(-n,n,f),o=this._getOffset(-o,o,f);let p=[];return g&&(h?p.push({op:"move",data:[a+this._getOffset(-l,l,f),b+this._getOffset(-l,l,f)]}):p.push({op:"move",data:[a+this._getOffset(-k,k,f),b+this._getOffset(-k,k,f)]})),h?p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-l,l,f),o+b+(e-b)*m+this._getOffset(-l,l,f),n+a+2*(c-a)*m+this._getOffset(-l,l,f),o+b+2*(e-b)*m+this._getOffset(-l,l,f),c+this._getOffset(-l,l,f),e+this._getOffset(-l,l,f)]}):p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-k,k,f),o+b+(e-b)*m+this._getOffset(-k,k,f),n+a+2*(c-a)*m+this._getOffset(-k,k,f),o+b+2*(e-b)*m+this._getOffset(-k,k,f),c+this._getOffset(-k,k,f),e+this._getOffset(-k,k,f)]}),p}_curve(a,c,d){const e=a.length;let f=[];if(3c&&(c=b.strokeWidth/2),{d:this.opsToPath(a),stroke:b.fill,strokeWidth:c,fill:"none"}}opsToPath(a){let b="";for(let c of a.ops){const a=c.data;switch(c.op){case"move":b+=`M${a[0]} ${a[1]} `;break;case"bcurveTo":b+=`C${a[0]} ${a[1]}, ${a[2]} ${a[3]}, ${a[4]} ${a[5]} `;break;case"qcurveTo":b+=`Q${a[0]} ${a[1]}, ${a[2]} ${a[3]} `;break;case"lineTo":b+=`L${a[0]} ${a[1]} `;}}return b.trim()}_computePathSize(a){let b=[0,0];if(self.document)try{const c="http://www.w3.org/2000/svg";let d=self.document.createElementNS(c,"svg");d.setAttribute("width","0"),d.setAttribute("height","0");let e=self.document.createElementNS(c,"path");e.setAttribute("d",a),d.appendChild(e),self.document.body.appendChild(d);let f=e.getBBox();f&&(b[0]=f.width||0,b[1]=f.height||0),self.document.body.removeChild(d)}catch(a){}const c=this._canvasSize();return b[0]*b[1]||(b=c),b[0]=l(b[0],c[0]),b[1]=l(b[1],c[1]),b}_canvasSize(){const a=(a)=>a&&"object"==typeof a&&a.baseVal&&a.baseVal.value?a.baseVal.value:a||100;return this.canvas?[a(this.canvas.width),a(this.canvas.height)]:[100,100]}}class w extends v{async line(a,b,c,d,e){const f=this._options(e);return this._drawable("line",[await this.lib.line(a,b,c,d,f)],f)}async rectangle(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill){const e=[a,a+c,a+c,a],h=[b,b,b+d,b+d];"solid"===f.fillStyle?g.push((await this.lib.solidFillShape(e,h,f))):g.push((await this.lib.hachureFillShape(e,h,f)))}return g.push((await this.lib.rectangle(a,b,c,d,f))),this._drawable("rectangle",g,f)}async ellipse(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill)if("solid"===f.fillStyle){const e=await this.lib.ellipse(a,b,c,d,f);e.type="fillPath",g.push(e)}else g.push((await this.lib.hachureFillEllipse(a,b,c,d,f)));return g.push((await this.lib.ellipse(a,b,c,d,f))),this._drawable("ellipse",g,f)}async circle(a,b,c,d){let e=await this.ellipse(a,b,c,c,d);return e.shape="circle",e}async linearPath(a,b){const c=this._options(b);return this._drawable("linearPath",[await this.lib.linearPath(a,!1,c)],c)}async polygon(a,b){const c=this._options(b),d=[];if(c.fill){let b=[],e=[];for(let c of a)b.push(c[0]),e.push(c[1]);"solid"===c.fillStyle?d.push((await this.lib.solidFillShape(b,e,c))):d.push((await this.lib.hachureFillShape(b,e,c)))}return d.push((await this.lib.linearPath(a,!0,c))),this._drawable("polygon",d,c)}async arc(a,b,c,d,e,f,g,h){const i=this._options(h),j=[];if(g&&i.fill)if("solid"===i.fillStyle){let g=await this.lib.arc(a,b,c,d,e,f,!0,!1,i);g.type="fillPath",j.push(g)}else j.push((await this.lib.hachureFillArc(a,b,c,d,e,f,i)));return j.push((await this.lib.arc(a,b,c,d,e,f,g,!0,i))),this._drawable("arc",j,i)}async curve(a,b){const c=this._options(b);return this._drawable("curve",[await this.lib.curve(a,c)],c)}async path(a,b){const c=this._options(b),e=[];if(!a)return this._drawable("path",e,c);if(c.fill)if("solid"===c.fillStyle){e.push({type:"path2Dfill",path:a})}else{const b=this._computePathSize(a);let d=[0,b[0],b[0],0],f=[0,0,b[1],b[1]],g=await this.lib.hachureFillShape(d,f,c);g.type="path2Dpattern",g.size=b,g.path=a,e.push(g)}return e.push((await this.lib.svgPath(a,c))),this._drawable("path",e,c)}}class x{constructor(a,b){this.canvas=a,this.ctx=this.canvas.getContext("2d"),this._init(b)}_init(a){this.gen=new v(a,this.canvas)}get generator(){return this.gen}static createRenderer(){return new u}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g),g}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f),f}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c),c}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c),c}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c),c}path(a,b){let c=this.gen.path(a,b);return this.draw(c),c}draw(a){let b=a.sets||[],c=a.options||this.gen.defaultOptions,d=this.ctx;for(let e of b)switch(e.type){case"path":d.save(),d.strokeStyle=c.stroke,d.lineWidth=c.strokeWidth,this._drawToContext(d,e),d.restore();break;case"fillPath":d.save(),d.fillStyle=c.fill,this._drawToContext(d,e,c),d.restore();break;case"fillSketch":this._fillSketch(d,e,c);break;case"path2Dfill":{this.ctx.save(),this.ctx.fillStyle=c.fill;let a=new Path2D(e.path);this.ctx.fill(a),this.ctx.restore();break}case"path2Dpattern":{let a=e.size;const b=document.createElement("canvas"),d=b.getContext("2d");let f=this._computeBBox(e.path);f&&(f.width||f.height)?(b.width=this.canvas.width,b.height=this.canvas.height,d.translate(f.x||0,f.y||0)):(b.width=a[0],b.height=a[1]),this._fillSketch(d,e,c),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(b,"repeat");let g=new Path2D(e.path);this.ctx.fill(g),this.ctx.restore();break}}}_computeBBox(a){if(self.document)try{const b="http://www.w3.org/2000/svg";let c=self.document.createElementNS(b,"svg");c.setAttribute("width","0"),c.setAttribute("height","0");let d=self.document.createElementNS(b,"path");d.setAttribute("d",a),c.appendChild(d),self.document.body.appendChild(c);let e=d.getBBox();return self.document.body.removeChild(c),e}catch(a){}return null}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2),a.save(),a.strokeStyle=c.fill,a.lineWidth=d,this._drawToContext(a,b),a.restore()}_drawToContext(a,b){a.beginPath();for(let c of b.ops){const b=c.data;switch(c.op){case"move":a.moveTo(b[0],b[1]);break;case"bcurveTo":a.bezierCurveTo(b[0],b[1],b[2],b[3],b[4],b[5]);break;case"qcurveTo":a.quadraticCurveTo(b[0],b[1],b[2],b[3]);break;case"lineTo":a.lineTo(b[0],b[1]);}}"fillPath"===b.type?a.fill():a.stroke()}}class y extends x{_init(a){this.gen=new w(a,this.canvas)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g),g}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f),f}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c),c}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c),c}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c),c}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c),c}}class z{constructor(a,b){this.svg=a,this._init(b)}_init(a){this.gen=new v(a,this.svg)}get generator(){return this.gen}get defs(){if(!this._defs){let a=this.svg.ownerDocument||document,b=a.createElementNS("http://www.w3.org/2000/svg","defs");this.svg.firstChild?this.svg.insertBefore(b,this.svg.firstChild):this.svg.appendChild(b),this._defs=b}return this._defs}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g)}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g)}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g)}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f)}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c)}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c)}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c)}path(a,b){let c=this.gen.path(a,b);return this.draw(c)}draw(a){let c=a.sets||[],d=a.options||this.gen.defaultOptions,f=this.svg.ownerDocument||document,h=f.createElementNS("http://www.w3.org/2000/svg","g");for(let g of c){let a=null;switch(g.type){case"path":{a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",this._opsToPath(g)),a.style.stroke=d.stroke,a.style.strokeWidth=d.strokeWidth,a.style.fill="none";break}case"fillPath":{a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",this._opsToPath(g)),a.style.stroke="none",a.style.strokeWidth=0,a.style.fill=d.fill;break}case"fillSketch":{a=this._fillSketch(f,g,d);break}case"path2Dfill":{a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",g.path),a.style.stroke="none",a.style.strokeWidth=0,a.style.fill=d.fill;break}case"path2Dpattern":{const c=g.size,h=f.createElementNS("http://www.w3.org/2000/svg","pattern"),i=`rough-${e(Math.random()*(Number.MAX_SAFE_INTEGER||999999))}`;h.setAttribute("id",i),h.setAttribute("x",0),h.setAttribute("y",0),h.setAttribute("width",1),h.setAttribute("height",1),h.setAttribute("height",1),h.setAttribute("viewBox",`0 0 ${b(c[0])} ${b(c[1])}`),h.setAttribute("patternUnits","objectBoundingBox");const j=this._fillSketch(f,g,d);h.appendChild(j),this.defs.appendChild(h),a=f.createElementNS("http://www.w3.org/2000/svg","path"),a.setAttribute("d",g.path),a.style.stroke="none",a.style.strokeWidth=0,a.style.fill=`url(#${i})`;break}}a&&h.appendChild(a)}return h}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2);let e=a.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d",this._opsToPath(b)),e.style.stroke=c.fill,e.style.strokeWidth=d,e.style.fill="none",e}_opsToPath(a){return this.gen.opsToPath(a)}}class A extends z{_init(a){this.gen=new w(a,this.svg)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g)}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g)}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g)}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f)}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c)}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c)}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c)}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c)}}var B={canvas(a,b){return b&&b.async?new y(a,b):new x(a,b)},svg(a,b){return b&&b.async?new A(a,b):new z(a,b)},createRenderer(){return x.createRenderer()},generator(a,b){return a&&a.async?new w(a,b):new v(a,b)}};return B}(); \ No newline at end of file diff --git a/dist/rough.umd.js b/dist/rough.umd.js index 40030b8..748ae73 100644 --- a/dist/rough.umd.js +++ b/dist/rough.umd.js @@ -513,8 +513,8 @@ class RoughArcConverter { var numerator = this._rx * this._rx * this._ry * this._ry - this._rx * this._rx * y1dash * y1dash - this._ry * this._ry * x1dash * x1dash; if (numerator < 0) { let s = Math.sqrt(1 - (numerator / (this._rx * this._rx * this._ry * this._ry))); - this._rx = s; - this._ry = s; + this._rx = this._rx * s; + this._ry = this._ry * s; root = 0; } else { root = (largeArcFlag == sweepFlag ? -1.0 : 1.0) * diff --git a/dist/rough.umd.min.js b/dist/rough.umd.min.js index 67af803..84efa54 100644 --- a/dist/rough.umd.min.js +++ b/dist/rough.umd.min.js @@ -1 +1 @@ -(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define(b):a.rough=b()})(this,function(){'use strict';function a(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var b=Math.round,c=Math.tan,d=Math.pow,e=Math.floor,f=Math.cos,g=Math.sin,h=Math.PI,j=Math.sqrt,k=Math.max,l=Math.min,i=Math.abs,m=Number.MAX_VALUE;class n{constructor(b,c,d,e){this.RoughSegmentRelationConst=a(),this.px1=b,this.py1=c,this.px2=d,this.py2=e,this.xi=m,this.yi=m,this.a=e-c,this.b=b-d,this.c=d*c-b*e,this._undefined=0==this.a&&0==this.b&&0==this.c}isUndefined(){return this._undefined}compare(d){if(this.isUndefined()||d.isUndefined())return this.RoughSegmentRelationConst.UNDEFINED;var e=m,f=m,g=0,h=0,j=this.a,n=this.b,b=this.c;return(1e-5=l(d.py1,d.py2)&&this.py1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=l(d.py1,d.py2)&&this.py2<=k(d.py1,d.py2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=this.px1,this.yi=f*this.xi+h,-1e-5>(this.py1-this.yi)*(this.yi-this.py2)||-1e-5>(d.py1-this.yi)*(this.yi-d.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(d.a)?-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):f==m?(this.xi=d.px1,this.yi=e*this.xi+g,-1e-5>(d.py1-this.yi)*(this.yi-d.py2)||-1e-5>(this.py1-this.yi)*(this.yi-this.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(j)?-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):e==f?g==h?this.px1>=l(d.px1,d.px2)&&this.px1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=l(d.px1,d.px2)&&this.px2<=k(d.px1,d.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(h-g)/(e-f),this.yi=e*this.xi+g,-1e-5>(this.px1-this.xi)*(this.xi-this.px2)||-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS)}getLength(){return this._getLength(this.px1,this.py1,this.px2,this.py2)}_getLength(a,b,c,d){var e=c-a,f=d-b;return j(e*e+f*f)}}class p{constructor(a,b,c,d,e,f,g,h){this.top=a,this.bottom=b,this.left=c,this.right=d,this.gap=e,this.sinAngle=f,this.tanAngle=h,1e-4>i(f)?this.pos=c+e:.9999i(this.sinAngle)){if(this.posthis.right&&c>this.right;)if(this.pos+=this.hGap,b=this.pos-this.deltaX/2,c=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;let f=new n(b,d,c,e);f.compare(this.sLeft)==a().INTERSECTS&&(b=f.xi,d=f.yi),f.compare(this.sRight)==a().INTERSECTS&&(c=f.xi,e=f.yi),0p){let a=j(1-p/(this._rx*this._rx*this._ry*this._ry));this._rx=a,this._ry=a,m=0}else m=(e==k?-1:1)*j(p/(this._rx*this._rx*o*o+this._ry*this._ry*n*n));let q=m*this._rx*o/this._ry,r=-m*this._ry*n/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*q-this._sinPhi*r+(a[0]+b[0])/2,this._C[1]=this._sinPhi*q+this._cosPhi*r+(a[1]+b[1])/2,this._theta=this.calculateVectorAngle(1,0,(n-q)/this._rx,(o-r)/this._ry);let s=this.calculateVectorAngle((n-q)/this._rx,(o-r)/this._ry,(-n-q)/this._rx,(-o-r)/this._ry);!k&&0s&&(s+=2*h),this._numSegs=Math.ceil(i(s/(h/2))),this._delta=s/this._numSegs,this._T=8/3*g(this._delta/4)*g(this._delta/4)/g(this._delta/2),this._from=a}getNextSegment(){var a,b,c;if(this._segIndex==this._numSegs)return null;let d=f(this._theta),e=g(this._theta),h=this._theta+this._delta,i=f(h),j=g(h);return c=[this._cosPhi*this._rx*i-this._sinPhi*this._ry*j+this._C[0],this._sinPhi*this._rx*i+this._cosPhi*this._ry*j+this._C[1]],a=[this._from[0]+this._T*(-this._cosPhi*this._rx*e-this._sinPhi*this._ry*d),this._from[1]+this._T*(-this._sinPhi*this._rx*e+this._cosPhi*this._ry*d)],b=[c[0]+this._T*(this._cosPhi*this._rx*j+this._sinPhi*this._ry*i),c[1]+this._T*(this._sinPhi*this._rx*j-this._cosPhi*this._ry*i)],this._theta=h,this._from=[c[0],c[1]],this._segIndex++,{cp1:a,cp2:b,to:c}}calculateVectorAngle(a,b,c,d){var e=Math.atan2;let f=e(b,a),g=e(d,c);return g>=f?g-f:2*h-(f-g)}}class t{constructor(a,b){this.sets=a,this.closed=b}fit(a){let b=[];for(const c of this.sets){let d=c.length,f=e(a*d);if(5>f){if(5>=d)continue;f=5}b.push(this.reduce(c,f))}let c='';for(const d of b){for(let a,b=0;bb;){let e=-1,f=-1;for(let g=1;ge||is;)s+=2*h,t+=2*h;t-s>2*h&&(s=0,t=2*h);let u=2*h/n.curveStepCount,v=l(u/2,(t-s)/2),w=this._arc(v,o,p,q,r,s,t,1,n),x=this._arc(v,o,p,q,r,s,t,1.5,n),y=w.concat(x);return k&&(m?(y=y.concat(this._doubleLine(o,p,o+q*f(s),p+r*g(s),n)),y=y.concat(this._doubleLine(o,p,o+q*f(t),p+r*g(t),n))):(y.push({op:'lineTo',data:[o,p]}),y.push({op:'lineTo',data:[o+q*f(s),p+r*g(s)]}))),{type:'path',ops:y}}hachureFillArc(a,b,c,d,e,j,k){let l=a,m=b,n=i(c/2),o=i(d/2);n+=this._getOffset(.01*-n,.01*n,k),o+=this._getOffset(.01*-o,.01*o,k);let p=e,q=j;for(;0>p;)p+=2*h,q+=2*h;q-p>2*h&&(p=0,q=2*h);let r=(q-p)/k.curveStepCount,s=[],t=[];for(let h=p;h<=q;h+=r)s.push(l+n*f(h)),t.push(m+o*g(h));return s.push(l+n*f(q)),t.push(m+o*g(q)),s.push(l),t.push(m),this.hachureFillShape(s,t,k)}solidFillShape(a,b,c){let d=[];if(a&&b&&a.length&&b.length&&a.length===b.length){let f=c.maxRandomnessOffset||0;const g=a.length;if(2q&&(q=4*d.strokeWidth),q=k(q,.1);const r=i%180*(h/180),s=f(r),t=g(r),u=c(r),v=new p(n-1,o+1,j-1,m+1,q,t,s,u);for(let c;null!=(c=v.getNextLine());){let f=this._getIntersectingLines(c,a,b);for(let a=0;a=n&&(n=4*f.strokeWidth);let o=f.fillWeight;0>o&&(o=f.strokeWidth/2);let p=c(m%180*(h/180)),q=l/k,r=j(q*p*q*p+1),s=q*p/r,t=1/r,u=n/(k*l/j(l*t*(l*t)+k*s*(k*s))/k),v=j(k*k-(a-k+u)*(a-k+u));for(var w=a-k+u;wf;f++)0===f?k.push({op:'move',data:[h.x,h.y]}):k.push({op:'move',data:[h.x+this._getOffset(-l[0],l[0],j),h.y+this._getOffset(-l[0],l[0],j)]}),m=[e+this._getOffset(-l[f],l[f],j),g+this._getOffset(-l[f],l[f],j)],k.push({op:'bcurveTo',data:[a+this._getOffset(-l[f],l[f],j),b+this._getOffset(-l[f],l[f],j),c+this._getOffset(-l[f],l[f],j),d+this._getOffset(-l[f],l[f],j),m[0],m[1]]});return h.setPosition(m[0],m[1]),k}_processSegment(a,b,c,d){let e=[];switch(b.key){case'M':case'm':{let c='m'===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y);let h=1*(d.maxRandomnessOffset||0);f+=this._getOffset(-h,h,d),g+=this._getOffset(-h,h,d),a.setPosition(f,g),e.push({op:'move',data:[f,g]})}break}case'L':case'l':{let c='l'===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y),e=e.concat(this._doubleLine(a.x,a.y,f,g,d)),a.setPosition(f,g)}break}case'H':case'h':{const c='h'===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.x),e=e.concat(this._doubleLine(a.x,a.y,f,a.y,d)),a.setPosition(f,a.y)}break}case'V':case'v':{const c='v'===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.y),e=e.concat(this._doubleLine(a.x,a.y,a.x,f,d)),a.setPosition(a.x,f)}break}case'Z':case'z':{a.first&&(e=e.concat(this._doubleLine(a.x,a.y,a.first[0],a.first[1],d)),a.setPosition(a.first[0],a.first[1]),a.first=null);break}case'C':case'c':{const c='c'===b.key;if(6<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5];c&&(f+=a.x,h+=a.x,j+=a.x,g+=a.y,i+=a.y,k+=a.y);let l=this._bezierTo(f,g,h,i,j,k,a,d);e=e.concat(l),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case'S':case's':{const f='s'===b.key;if(4<=b.data.length){let h=+b.data[0],i=+b.data[1],j=+b.data[2],k=+b.data[3];f&&(h+=a.x,j+=a.x,i+=a.y,k+=a.y);let l=h,m=i,n=c?c.key:'';var g=null;('c'==n||'C'==n||'s'==n||'S'==n)&&(g=a.bezierReflectionPoint),g&&(l=g[0],m=g[1]);let o=this._bezierTo(l,m,h,i,j,k,a,d);e=e.concat(o),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case'Q':case'q':{const c='q'===b.key;if(4<=b.data.length){let g=+b.data[0],h=+b.data[1],i=+b.data[2],j=+b.data[3];c&&(g+=a.x,i+=a.x,h+=a.y,j+=a.y);let k=1*(1+.2*d.roughness),l=1.5*(1+.22*d.roughness);e.push({op:'move',data:[a.x+this._getOffset(-k,k,d),a.y+this._getOffset(-k,k,d)]});let m=[i+this._getOffset(-k,k,d),j+this._getOffset(-k,k,d)];e.push({op:'qcurveTo',data:[g+this._getOffset(-k,k,d),h+this._getOffset(-k,k,d),m[0],m[1]]}),e.push({op:'move',data:[a.x+this._getOffset(-l,l,d),a.y+this._getOffset(-l,l,d)]}),m=[i+this._getOffset(-l,l,d),j+this._getOffset(-l,l,d)],e.push({op:'qcurveTo',data:[g+this._getOffset(-l,l,d),h+this._getOffset(-l,l,d),m[0],m[1]]}),a.setPosition(m[0],m[1]),a.quadReflectionPoint=[i+(i-g),j+(j-h)]}break}case'T':case't':{const h='t'===b.key;if(2<=b.data.length){let i=+b.data[0],j=+b.data[1];h&&(i+=a.x,j+=a.y);let k=i,l=j,m=c?c.key:'';var g=null;('q'==m||'Q'==m||'t'==m||'T'==m)&&(g=a.quadReflectionPoint),g&&(k=g[0],l=g[1]);let n=1*(1+.2*d.roughness),o=1.5*(1+.22*d.roughness);e.push({op:'move',data:[a.x+this._getOffset(-n,n,d),a.y+this._getOffset(-n,n,d)]});let p=[i+this._getOffset(-n,n,d),j+this._getOffset(-n,n,d)];e.push({op:'qcurveTo',data:[k+this._getOffset(-n,n,d),l+this._getOffset(-n,n,d),p[0],p[1]]}),e.push({op:'move',data:[a.x+this._getOffset(-o,o,d),a.y+this._getOffset(-o,o,d)]}),p=[i+this._getOffset(-o,o,d),j+this._getOffset(-o,o,d)],e.push({op:'qcurveTo',data:[k+this._getOffset(-o,o,d),l+this._getOffset(-o,o,d),p[0],p[1]]}),a.setPosition(p[0],p[1]),a.quadReflectionPoint=[i+(i-k),j+(j-l)]}break}case'A':case'a':{const c='a'===b.key;if(7<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5],l=+b.data[6];if(c&&(k+=a.x,l+=a.y),k==a.x&&l==a.y)break;if(0==f||0==g)e=e.concat(this._doubleLine(a.x,a.y,k,l,d)),a.setPosition(k,l);else{d.maxRandomnessOffset||0;for(let b=0;1>b;b++){let b=new s([a.x,a.y],[k,l],[f,g],h,!!i,!!j),c=b.getNextSegment();for(;c;){let f=this._bezierTo(c.cp1[0],c.cp1[1],c.cp2[0],c.cp2[1],c.to[0],c.to[1],a,d);e=e.concat(f),c=b.getNextSegment()}}}}break}default:}return e}_getOffset(a,b,c){return c.roughness*(Math.random()*(b-a)+a)}_affine(a,b,c,d,e,f,g){return[-c*f-d*e+c+f*a+e*b,g*(c*e-d*f)+d+-g*e*a+g*f*b]}_doubleLine(a,b,c,d,e){const f=this._line(a,b,c,d,e,!0,!1),g=this._line(a,b,c,d,e,!0,!0);return f.concat(g)}_line(a,b,c,e,f,g,h){const i=d(a-c,2)+d(b-e,2);let k=f.maxRandomnessOffset||0;100*(k*k)>i&&(k=j(i)/10);const l=k/2,m=.2+.2*Math.random();let n=f.bowing*f.maxRandomnessOffset*(e-b)/200,o=f.bowing*f.maxRandomnessOffset*(a-c)/200;n=this._getOffset(-n,n,f),o=this._getOffset(-o,o,f);let p=[];return g&&(h?p.push({op:'move',data:[a+this._getOffset(-l,l,f),b+this._getOffset(-l,l,f)]}):p.push({op:'move',data:[a+this._getOffset(-k,k,f),b+this._getOffset(-k,k,f)]})),h?p.push({op:'bcurveTo',data:[n+a+(c-a)*m+this._getOffset(-l,l,f),o+b+(e-b)*m+this._getOffset(-l,l,f),n+a+2*(c-a)*m+this._getOffset(-l,l,f),o+b+2*(e-b)*m+this._getOffset(-l,l,f),c+this._getOffset(-l,l,f),e+this._getOffset(-l,l,f)]}):p.push({op:'bcurveTo',data:[n+a+(c-a)*m+this._getOffset(-k,k,f),o+b+(e-b)*m+this._getOffset(-k,k,f),n+a+2*(c-a)*m+this._getOffset(-k,k,f),o+b+2*(e-b)*m+this._getOffset(-k,k,f),c+this._getOffset(-k,k,f),e+this._getOffset(-k,k,f)]}),p}_curve(a,c,d){const e=a.length;let f=[];if(3c&&(c=b.strokeWidth/2),{d:this.opsToPath(a),stroke:b.fill,strokeWidth:c,fill:'none'}}opsToPath(a){let b='';for(let c of a.ops){const a=c.data;switch(c.op){case'move':b+=`M${a[0]} ${a[1]} `;break;case'bcurveTo':b+=`C${a[0]} ${a[1]}, ${a[2]} ${a[3]}, ${a[4]} ${a[5]} `;break;case'qcurveTo':b+=`Q${a[0]} ${a[1]}, ${a[2]} ${a[3]} `;break;case'lineTo':b+=`L${a[0]} ${a[1]} `;}}return b.trim()}_computePathSize(a){let b=[0,0];if(self.document)try{const c='http://www.w3.org/2000/svg';let d=self.document.createElementNS(c,'svg');d.setAttribute('width','0'),d.setAttribute('height','0');let e=self.document.createElementNS(c,'path');e.setAttribute('d',a),d.appendChild(e),self.document.body.appendChild(d);let f=e.getBBox();f&&(b[0]=f.width||0,b[1]=f.height||0),self.document.body.removeChild(d)}catch(a){}const c=this._canvasSize();return b[0]*b[1]||(b=c),b[0]=l(b[0],c[0]),b[1]=l(b[1],c[1]),b}_canvasSize(){const a=(a)=>a&&'object'==typeof a&&a.baseVal&&a.baseVal.value?a.baseVal.value:a||100;return this.canvas?[a(this.canvas.width),a(this.canvas.height)]:[100,100]}}class w extends v{async line(a,b,c,d,e){const f=this._options(e);return this._drawable('line',[await this.lib.line(a,b,c,d,f)],f)}async rectangle(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill){const e=[a,a+c,a+c,a],h=[b,b,b+d,b+d];'solid'===f.fillStyle?g.push((await this.lib.solidFillShape(e,h,f))):g.push((await this.lib.hachureFillShape(e,h,f)))}return g.push((await this.lib.rectangle(a,b,c,d,f))),this._drawable('rectangle',g,f)}async ellipse(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill)if('solid'===f.fillStyle){const e=await this.lib.ellipse(a,b,c,d,f);e.type='fillPath',g.push(e)}else g.push((await this.lib.hachureFillEllipse(a,b,c,d,f)));return g.push((await this.lib.ellipse(a,b,c,d,f))),this._drawable('ellipse',g,f)}async circle(a,b,c,d){let e=await this.ellipse(a,b,c,c,d);return e.shape='circle',e}async linearPath(a,b){const c=this._options(b);return this._drawable('linearPath',[await this.lib.linearPath(a,!1,c)],c)}async polygon(a,b){const c=this._options(b),d=[];if(c.fill){let b=[],e=[];for(let c of a)b.push(c[0]),e.push(c[1]);'solid'===c.fillStyle?d.push((await this.lib.solidFillShape(b,e,c))):d.push((await this.lib.hachureFillShape(b,e,c)))}return d.push((await this.lib.linearPath(a,!0,c))),this._drawable('polygon',d,c)}async arc(a,b,c,d,e,f,g,h){const i=this._options(h),j=[];if(g&&i.fill)if('solid'===i.fillStyle){let g=await this.lib.arc(a,b,c,d,e,f,!0,!1,i);g.type='fillPath',j.push(g)}else j.push((await this.lib.hachureFillArc(a,b,c,d,e,f,i)));return j.push((await this.lib.arc(a,b,c,d,e,f,g,!0,i))),this._drawable('arc',j,i)}async curve(a,b){const c=this._options(b);return this._drawable('curve',[await this.lib.curve(a,c)],c)}async path(a,b){const c=this._options(b),e=[];if(!a)return this._drawable('path',e,c);if(c.fill)if('solid'===c.fillStyle){e.push({type:'path2Dfill',path:a})}else{const b=this._computePathSize(a);let d=[0,b[0],b[0],0],f=[0,0,b[1],b[1]],g=await this.lib.hachureFillShape(d,f,c);g.type='path2Dpattern',g.size=b,g.path=a,e.push(g)}return e.push((await this.lib.svgPath(a,c))),this._drawable('path',e,c)}}class x{constructor(a,b){this.canvas=a,this.ctx=this.canvas.getContext('2d'),this._init(b)}_init(a){this.gen=new v(a,this.canvas)}get generator(){return this.gen}static createRenderer(){return new u}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g),g}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f),f}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c),c}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c),c}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c),c}path(a,b){let c=this.gen.path(a,b);return this.draw(c),c}draw(a){let b=a.sets||[],c=a.options||this.gen.defaultOptions,d=this.ctx;for(let e of b)switch(e.type){case'path':d.save(),d.strokeStyle=c.stroke,d.lineWidth=c.strokeWidth,this._drawToContext(d,e),d.restore();break;case'fillPath':d.save(),d.fillStyle=c.fill,this._drawToContext(d,e,c),d.restore();break;case'fillSketch':this._fillSketch(d,e,c);break;case'path2Dfill':{this.ctx.save(),this.ctx.fillStyle=c.fill;let a=new Path2D(e.path);this.ctx.fill(a),this.ctx.restore();break}case'path2Dpattern':{let a=e.size;const b=document.createElement('canvas'),d=b.getContext('2d');let f=this._computeBBox(e.path);f&&(f.width||f.height)?(b.width=this.canvas.width,b.height=this.canvas.height,d.translate(f.x||0,f.y||0)):(b.width=a[0],b.height=a[1]),this._fillSketch(d,e,c),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(b,'repeat');let g=new Path2D(e.path);this.ctx.fill(g),this.ctx.restore();break}}}_computeBBox(a){if(self.document)try{const b='http://www.w3.org/2000/svg';let c=self.document.createElementNS(b,'svg');c.setAttribute('width','0'),c.setAttribute('height','0');let d=self.document.createElementNS(b,'path');d.setAttribute('d',a),c.appendChild(d),self.document.body.appendChild(c);let e=d.getBBox();return self.document.body.removeChild(c),e}catch(a){}return null}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2),a.save(),a.strokeStyle=c.fill,a.lineWidth=d,this._drawToContext(a,b),a.restore()}_drawToContext(a,b){a.beginPath();for(let c of b.ops){const b=c.data;switch(c.op){case'move':a.moveTo(b[0],b[1]);break;case'bcurveTo':a.bezierCurveTo(b[0],b[1],b[2],b[3],b[4],b[5]);break;case'qcurveTo':a.quadraticCurveTo(b[0],b[1],b[2],b[3]);break;case'lineTo':a.lineTo(b[0],b[1]);}}'fillPath'===b.type?a.fill():a.stroke()}}class y extends x{_init(a){this.gen=new w(a,this.canvas)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g),g}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f),f}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c),c}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c),c}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c),c}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c),c}}class z{constructor(a,b){this.svg=a,this._init(b)}_init(a){this.gen=new v(a,this.svg)}get generator(){return this.gen}get defs(){if(!this._defs){let a=this.svg.ownerDocument||document,b=a.createElementNS('http://www.w3.org/2000/svg','defs');this.svg.firstChild?this.svg.insertBefore(b,this.svg.firstChild):this.svg.appendChild(b),this._defs=b}return this._defs}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g)}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g)}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g)}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f)}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c)}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c)}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c)}path(a,b){let c=this.gen.path(a,b);return this.draw(c)}draw(a){let c=a.sets||[],d=a.options||this.gen.defaultOptions,f=this.svg.ownerDocument||document,h=f.createElementNS('http://www.w3.org/2000/svg','g');for(let g of c){let a=null;switch(g.type){case'path':{a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',this._opsToPath(g)),a.style.stroke=d.stroke,a.style.strokeWidth=d.strokeWidth,a.style.fill='none';break}case'fillPath':{a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',this._opsToPath(g)),a.style.stroke='none',a.style.strokeWidth=0,a.style.fill=d.fill;break}case'fillSketch':{a=this._fillSketch(f,g,d);break}case'path2Dfill':{a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',g.path),a.style.stroke='none',a.style.strokeWidth=0,a.style.fill=d.fill;break}case'path2Dpattern':{const c=g.size,h=f.createElementNS('http://www.w3.org/2000/svg','pattern'),i=`rough-${e(Math.random()*(Number.MAX_SAFE_INTEGER||999999))}`;h.setAttribute('id',i),h.setAttribute('x',0),h.setAttribute('y',0),h.setAttribute('width',1),h.setAttribute('height',1),h.setAttribute('height',1),h.setAttribute('viewBox',`0 0 ${b(c[0])} ${b(c[1])}`),h.setAttribute('patternUnits','objectBoundingBox');const j=this._fillSketch(f,g,d);h.appendChild(j),this.defs.appendChild(h),a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',g.path),a.style.stroke='none',a.style.strokeWidth=0,a.style.fill=`url(#${i})`;break}}a&&h.appendChild(a)}return h}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2);let e=a.createElementNS('http://www.w3.org/2000/svg','path');return e.setAttribute('d',this._opsToPath(b)),e.style.stroke=c.fill,e.style.strokeWidth=d,e.style.fill='none',e}_opsToPath(a){return this.gen.opsToPath(a)}}class A extends z{_init(a){this.gen=new w(a,this.svg)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g)}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g)}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g)}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f)}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c)}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c)}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c)}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c)}}var B={canvas(a,b){return b&&b.async?new y(a,b):new x(a,b)},svg(a,b){return b&&b.async?new A(a,b):new z(a,b)},createRenderer(){return x.createRenderer()},generator(a,b){return a&&a.async?new w(a,b):new v(a,b)}};return B}); \ No newline at end of file +(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define(b):a.rough=b()})(this,function(){'use strict';function a(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var b=Math.round,c=Math.tan,d=Math.pow,e=Math.floor,f=Math.cos,g=Math.sin,h=Math.PI,j=Math.sqrt,k=Math.max,l=Math.min,i=Math.abs,m=Number.MAX_VALUE;class n{constructor(b,c,d,e){this.RoughSegmentRelationConst=a(),this.px1=b,this.py1=c,this.px2=d,this.py2=e,this.xi=m,this.yi=m,this.a=e-c,this.b=b-d,this.c=d*c-b*e,this._undefined=0==this.a&&0==this.b&&0==this.c}isUndefined(){return this._undefined}compare(d){if(this.isUndefined()||d.isUndefined())return this.RoughSegmentRelationConst.UNDEFINED;var e=m,f=m,g=0,h=0,j=this.a,n=this.b,b=this.c;return(1e-5=l(d.py1,d.py2)&&this.py1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=l(d.py1,d.py2)&&this.py2<=k(d.py1,d.py2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=this.px1,this.yi=f*this.xi+h,-1e-5>(this.py1-this.yi)*(this.yi-this.py2)||-1e-5>(d.py1-this.yi)*(this.yi-d.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(d.a)?-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):f==m?(this.xi=d.px1,this.yi=e*this.xi+g,-1e-5>(d.py1-this.yi)*(this.yi-d.py2)||-1e-5>(this.py1-this.yi)*(this.yi-this.py2)?this.RoughSegmentRelationConst.SEPARATE:1e-5>i(j)?-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):e==f?g==h?this.px1>=l(d.px1,d.px2)&&this.px1<=k(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=l(d.px1,d.px2)&&this.px2<=k(d.px1,d.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(h-g)/(e-f),this.yi=e*this.xi+g,-1e-5>(this.px1-this.xi)*(this.xi-this.px2)||-1e-5>(d.px1-this.xi)*(this.xi-d.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS)}getLength(){return this._getLength(this.px1,this.py1,this.px2,this.py2)}_getLength(a,b,c,d){var e=c-a,f=d-b;return j(e*e+f*f)}}class p{constructor(a,b,c,d,e,f,g,h){this.top=a,this.bottom=b,this.left=c,this.right=d,this.gap=e,this.sinAngle=f,this.tanAngle=h,1e-4>i(f)?this.pos=c+e:.9999i(this.sinAngle)){if(this.posthis.right&&c>this.right;)if(this.pos+=this.hGap,b=this.pos-this.deltaX/2,c=this.pos+this.deltaX/2,this.pos>this.right+this.deltaX)return null;let f=new n(b,d,c,e);f.compare(this.sLeft)==a().INTERSECTS&&(b=f.xi,d=f.yi),f.compare(this.sRight)==a().INTERSECTS&&(c=f.xi,e=f.yi),0p){let a=j(1-p/(this._rx*this._rx*this._ry*this._ry));this._rx*=a,this._ry*=a,m=0}else m=(e==k?-1:1)*j(p/(this._rx*this._rx*o*o+this._ry*this._ry*n*n));let q=m*this._rx*o/this._ry,r=-m*this._ry*n/this._rx;this._C=[0,0],this._C[0]=this._cosPhi*q-this._sinPhi*r+(a[0]+b[0])/2,this._C[1]=this._sinPhi*q+this._cosPhi*r+(a[1]+b[1])/2,this._theta=this.calculateVectorAngle(1,0,(n-q)/this._rx,(o-r)/this._ry);let s=this.calculateVectorAngle((n-q)/this._rx,(o-r)/this._ry,(-n-q)/this._rx,(-o-r)/this._ry);!k&&0s&&(s+=2*h),this._numSegs=Math.ceil(i(s/(h/2))),this._delta=s/this._numSegs,this._T=8/3*g(this._delta/4)*g(this._delta/4)/g(this._delta/2),this._from=a}getNextSegment(){var a,b,c;if(this._segIndex==this._numSegs)return null;let d=f(this._theta),e=g(this._theta),h=this._theta+this._delta,i=f(h),j=g(h);return c=[this._cosPhi*this._rx*i-this._sinPhi*this._ry*j+this._C[0],this._sinPhi*this._rx*i+this._cosPhi*this._ry*j+this._C[1]],a=[this._from[0]+this._T*(-this._cosPhi*this._rx*e-this._sinPhi*this._ry*d),this._from[1]+this._T*(-this._sinPhi*this._rx*e+this._cosPhi*this._ry*d)],b=[c[0]+this._T*(this._cosPhi*this._rx*j+this._sinPhi*this._ry*i),c[1]+this._T*(this._sinPhi*this._rx*j-this._cosPhi*this._ry*i)],this._theta=h,this._from=[c[0],c[1]],this._segIndex++,{cp1:a,cp2:b,to:c}}calculateVectorAngle(a,b,c,d){var e=Math.atan2;let f=e(b,a),g=e(d,c);return g>=f?g-f:2*h-(f-g)}}class t{constructor(a,b){this.sets=a,this.closed=b}fit(a){let b=[];for(const c of this.sets){let d=c.length,f=e(a*d);if(5>f){if(5>=d)continue;f=5}b.push(this.reduce(c,f))}let c='';for(const d of b){for(let a,b=0;bb;){let e=-1,f=-1;for(let g=1;ge||is;)s+=2*h,t+=2*h;t-s>2*h&&(s=0,t=2*h);let u=2*h/n.curveStepCount,v=l(u/2,(t-s)/2),w=this._arc(v,o,p,q,r,s,t,1,n),x=this._arc(v,o,p,q,r,s,t,1.5,n),y=w.concat(x);return k&&(m?(y=y.concat(this._doubleLine(o,p,o+q*f(s),p+r*g(s),n)),y=y.concat(this._doubleLine(o,p,o+q*f(t),p+r*g(t),n))):(y.push({op:'lineTo',data:[o,p]}),y.push({op:'lineTo',data:[o+q*f(s),p+r*g(s)]}))),{type:'path',ops:y}}hachureFillArc(a,b,c,d,e,j,k){let l=a,m=b,n=i(c/2),o=i(d/2);n+=this._getOffset(.01*-n,.01*n,k),o+=this._getOffset(.01*-o,.01*o,k);let p=e,q=j;for(;0>p;)p+=2*h,q+=2*h;q-p>2*h&&(p=0,q=2*h);let r=(q-p)/k.curveStepCount,s=[],t=[];for(let h=p;h<=q;h+=r)s.push(l+n*f(h)),t.push(m+o*g(h));return s.push(l+n*f(q)),t.push(m+o*g(q)),s.push(l),t.push(m),this.hachureFillShape(s,t,k)}solidFillShape(a,b,c){let d=[];if(a&&b&&a.length&&b.length&&a.length===b.length){let f=c.maxRandomnessOffset||0;const g=a.length;if(2q&&(q=4*d.strokeWidth),q=k(q,.1);const r=i%180*(h/180),s=f(r),t=g(r),u=c(r),v=new p(n-1,o+1,j-1,m+1,q,t,s,u);for(let c;null!=(c=v.getNextLine());){let f=this._getIntersectingLines(c,a,b);for(let a=0;a=n&&(n=4*f.strokeWidth);let o=f.fillWeight;0>o&&(o=f.strokeWidth/2);let p=c(m%180*(h/180)),q=l/k,r=j(q*p*q*p+1),s=q*p/r,t=1/r,u=n/(k*l/j(l*t*(l*t)+k*s*(k*s))/k),v=j(k*k-(a-k+u)*(a-k+u));for(var w=a-k+u;wf;f++)0===f?k.push({op:'move',data:[h.x,h.y]}):k.push({op:'move',data:[h.x+this._getOffset(-l[0],l[0],j),h.y+this._getOffset(-l[0],l[0],j)]}),m=[e+this._getOffset(-l[f],l[f],j),g+this._getOffset(-l[f],l[f],j)],k.push({op:'bcurveTo',data:[a+this._getOffset(-l[f],l[f],j),b+this._getOffset(-l[f],l[f],j),c+this._getOffset(-l[f],l[f],j),d+this._getOffset(-l[f],l[f],j),m[0],m[1]]});return h.setPosition(m[0],m[1]),k}_processSegment(a,b,c,d){let e=[];switch(b.key){case'M':case'm':{let c='m'===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y);let h=1*(d.maxRandomnessOffset||0);f+=this._getOffset(-h,h,d),g+=this._getOffset(-h,h,d),a.setPosition(f,g),e.push({op:'move',data:[f,g]})}break}case'L':case'l':{let c='l'===b.key;if(2<=b.data.length){let f=+b.data[0],g=+b.data[1];c&&(f+=a.x,g+=a.y),e=e.concat(this._doubleLine(a.x,a.y,f,g,d)),a.setPosition(f,g)}break}case'H':case'h':{const c='h'===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.x),e=e.concat(this._doubleLine(a.x,a.y,f,a.y,d)),a.setPosition(f,a.y)}break}case'V':case'v':{const c='v'===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.y),e=e.concat(this._doubleLine(a.x,a.y,a.x,f,d)),a.setPosition(a.x,f)}break}case'Z':case'z':{a.first&&(e=e.concat(this._doubleLine(a.x,a.y,a.first[0],a.first[1],d)),a.setPosition(a.first[0],a.first[1]),a.first=null);break}case'C':case'c':{const c='c'===b.key;if(6<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5];c&&(f+=a.x,h+=a.x,j+=a.x,g+=a.y,i+=a.y,k+=a.y);let l=this._bezierTo(f,g,h,i,j,k,a,d);e=e.concat(l),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case'S':case's':{const f='s'===b.key;if(4<=b.data.length){let h=+b.data[0],i=+b.data[1],j=+b.data[2],k=+b.data[3];f&&(h+=a.x,j+=a.x,i+=a.y,k+=a.y);let l=h,m=i,n=c?c.key:'';var g=null;('c'==n||'C'==n||'s'==n||'S'==n)&&(g=a.bezierReflectionPoint),g&&(l=g[0],m=g[1]);let o=this._bezierTo(l,m,h,i,j,k,a,d);e=e.concat(o),a.bezierReflectionPoint=[j+(j-h),k+(k-i)]}break}case'Q':case'q':{const c='q'===b.key;if(4<=b.data.length){let g=+b.data[0],h=+b.data[1],i=+b.data[2],j=+b.data[3];c&&(g+=a.x,i+=a.x,h+=a.y,j+=a.y);let k=1*(1+.2*d.roughness),l=1.5*(1+.22*d.roughness);e.push({op:'move',data:[a.x+this._getOffset(-k,k,d),a.y+this._getOffset(-k,k,d)]});let m=[i+this._getOffset(-k,k,d),j+this._getOffset(-k,k,d)];e.push({op:'qcurveTo',data:[g+this._getOffset(-k,k,d),h+this._getOffset(-k,k,d),m[0],m[1]]}),e.push({op:'move',data:[a.x+this._getOffset(-l,l,d),a.y+this._getOffset(-l,l,d)]}),m=[i+this._getOffset(-l,l,d),j+this._getOffset(-l,l,d)],e.push({op:'qcurveTo',data:[g+this._getOffset(-l,l,d),h+this._getOffset(-l,l,d),m[0],m[1]]}),a.setPosition(m[0],m[1]),a.quadReflectionPoint=[i+(i-g),j+(j-h)]}break}case'T':case't':{const h='t'===b.key;if(2<=b.data.length){let i=+b.data[0],j=+b.data[1];h&&(i+=a.x,j+=a.y);let k=i,l=j,m=c?c.key:'';var g=null;('q'==m||'Q'==m||'t'==m||'T'==m)&&(g=a.quadReflectionPoint),g&&(k=g[0],l=g[1]);let n=1*(1+.2*d.roughness),o=1.5*(1+.22*d.roughness);e.push({op:'move',data:[a.x+this._getOffset(-n,n,d),a.y+this._getOffset(-n,n,d)]});let p=[i+this._getOffset(-n,n,d),j+this._getOffset(-n,n,d)];e.push({op:'qcurveTo',data:[k+this._getOffset(-n,n,d),l+this._getOffset(-n,n,d),p[0],p[1]]}),e.push({op:'move',data:[a.x+this._getOffset(-o,o,d),a.y+this._getOffset(-o,o,d)]}),p=[i+this._getOffset(-o,o,d),j+this._getOffset(-o,o,d)],e.push({op:'qcurveTo',data:[k+this._getOffset(-o,o,d),l+this._getOffset(-o,o,d),p[0],p[1]]}),a.setPosition(p[0],p[1]),a.quadReflectionPoint=[i+(i-k),j+(j-l)]}break}case'A':case'a':{const c='a'===b.key;if(7<=b.data.length){let f=+b.data[0],g=+b.data[1],h=+b.data[2],i=+b.data[3],j=+b.data[4],k=+b.data[5],l=+b.data[6];if(c&&(k+=a.x,l+=a.y),k==a.x&&l==a.y)break;if(0==f||0==g)e=e.concat(this._doubleLine(a.x,a.y,k,l,d)),a.setPosition(k,l);else{d.maxRandomnessOffset||0;for(let b=0;1>b;b++){let b=new s([a.x,a.y],[k,l],[f,g],h,!!i,!!j),c=b.getNextSegment();for(;c;){let f=this._bezierTo(c.cp1[0],c.cp1[1],c.cp2[0],c.cp2[1],c.to[0],c.to[1],a,d);e=e.concat(f),c=b.getNextSegment()}}}}break}default:}return e}_getOffset(a,b,c){return c.roughness*(Math.random()*(b-a)+a)}_affine(a,b,c,d,e,f,g){return[-c*f-d*e+c+f*a+e*b,g*(c*e-d*f)+d+-g*e*a+g*f*b]}_doubleLine(a,b,c,d,e){const f=this._line(a,b,c,d,e,!0,!1),g=this._line(a,b,c,d,e,!0,!0);return f.concat(g)}_line(a,b,c,e,f,g,h){const i=d(a-c,2)+d(b-e,2);let k=f.maxRandomnessOffset||0;100*(k*k)>i&&(k=j(i)/10);const l=k/2,m=.2+.2*Math.random();let n=f.bowing*f.maxRandomnessOffset*(e-b)/200,o=f.bowing*f.maxRandomnessOffset*(a-c)/200;n=this._getOffset(-n,n,f),o=this._getOffset(-o,o,f);let p=[];return g&&(h?p.push({op:'move',data:[a+this._getOffset(-l,l,f),b+this._getOffset(-l,l,f)]}):p.push({op:'move',data:[a+this._getOffset(-k,k,f),b+this._getOffset(-k,k,f)]})),h?p.push({op:'bcurveTo',data:[n+a+(c-a)*m+this._getOffset(-l,l,f),o+b+(e-b)*m+this._getOffset(-l,l,f),n+a+2*(c-a)*m+this._getOffset(-l,l,f),o+b+2*(e-b)*m+this._getOffset(-l,l,f),c+this._getOffset(-l,l,f),e+this._getOffset(-l,l,f)]}):p.push({op:'bcurveTo',data:[n+a+(c-a)*m+this._getOffset(-k,k,f),o+b+(e-b)*m+this._getOffset(-k,k,f),n+a+2*(c-a)*m+this._getOffset(-k,k,f),o+b+2*(e-b)*m+this._getOffset(-k,k,f),c+this._getOffset(-k,k,f),e+this._getOffset(-k,k,f)]}),p}_curve(a,c,d){const e=a.length;let f=[];if(3c&&(c=b.strokeWidth/2),{d:this.opsToPath(a),stroke:b.fill,strokeWidth:c,fill:'none'}}opsToPath(a){let b='';for(let c of a.ops){const a=c.data;switch(c.op){case'move':b+=`M${a[0]} ${a[1]} `;break;case'bcurveTo':b+=`C${a[0]} ${a[1]}, ${a[2]} ${a[3]}, ${a[4]} ${a[5]} `;break;case'qcurveTo':b+=`Q${a[0]} ${a[1]}, ${a[2]} ${a[3]} `;break;case'lineTo':b+=`L${a[0]} ${a[1]} `;}}return b.trim()}_computePathSize(a){let b=[0,0];if(self.document)try{const c='http://www.w3.org/2000/svg';let d=self.document.createElementNS(c,'svg');d.setAttribute('width','0'),d.setAttribute('height','0');let e=self.document.createElementNS(c,'path');e.setAttribute('d',a),d.appendChild(e),self.document.body.appendChild(d);let f=e.getBBox();f&&(b[0]=f.width||0,b[1]=f.height||0),self.document.body.removeChild(d)}catch(a){}const c=this._canvasSize();return b[0]*b[1]||(b=c),b[0]=l(b[0],c[0]),b[1]=l(b[1],c[1]),b}_canvasSize(){const a=(a)=>a&&'object'==typeof a&&a.baseVal&&a.baseVal.value?a.baseVal.value:a||100;return this.canvas?[a(this.canvas.width),a(this.canvas.height)]:[100,100]}}class w extends v{async line(a,b,c,d,e){const f=this._options(e);return this._drawable('line',[await this.lib.line(a,b,c,d,f)],f)}async rectangle(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill){const e=[a,a+c,a+c,a],h=[b,b,b+d,b+d];'solid'===f.fillStyle?g.push((await this.lib.solidFillShape(e,h,f))):g.push((await this.lib.hachureFillShape(e,h,f)))}return g.push((await this.lib.rectangle(a,b,c,d,f))),this._drawable('rectangle',g,f)}async ellipse(a,b,c,d,e){const f=this._options(e),g=[];if(f.fill)if('solid'===f.fillStyle){const e=await this.lib.ellipse(a,b,c,d,f);e.type='fillPath',g.push(e)}else g.push((await this.lib.hachureFillEllipse(a,b,c,d,f)));return g.push((await this.lib.ellipse(a,b,c,d,f))),this._drawable('ellipse',g,f)}async circle(a,b,c,d){let e=await this.ellipse(a,b,c,c,d);return e.shape='circle',e}async linearPath(a,b){const c=this._options(b);return this._drawable('linearPath',[await this.lib.linearPath(a,!1,c)],c)}async polygon(a,b){const c=this._options(b),d=[];if(c.fill){let b=[],e=[];for(let c of a)b.push(c[0]),e.push(c[1]);'solid'===c.fillStyle?d.push((await this.lib.solidFillShape(b,e,c))):d.push((await this.lib.hachureFillShape(b,e,c)))}return d.push((await this.lib.linearPath(a,!0,c))),this._drawable('polygon',d,c)}async arc(a,b,c,d,e,f,g,h){const i=this._options(h),j=[];if(g&&i.fill)if('solid'===i.fillStyle){let g=await this.lib.arc(a,b,c,d,e,f,!0,!1,i);g.type='fillPath',j.push(g)}else j.push((await this.lib.hachureFillArc(a,b,c,d,e,f,i)));return j.push((await this.lib.arc(a,b,c,d,e,f,g,!0,i))),this._drawable('arc',j,i)}async curve(a,b){const c=this._options(b);return this._drawable('curve',[await this.lib.curve(a,c)],c)}async path(a,b){const c=this._options(b),e=[];if(!a)return this._drawable('path',e,c);if(c.fill)if('solid'===c.fillStyle){e.push({type:'path2Dfill',path:a})}else{const b=this._computePathSize(a);let d=[0,b[0],b[0],0],f=[0,0,b[1],b[1]],g=await this.lib.hachureFillShape(d,f,c);g.type='path2Dpattern',g.size=b,g.path=a,e.push(g)}return e.push((await this.lib.svgPath(a,c))),this._drawable('path',e,c)}}class x{constructor(a,b){this.canvas=a,this.ctx=this.canvas.getContext('2d'),this._init(b)}_init(a){this.gen=new v(a,this.canvas)}get generator(){return this.gen}static createRenderer(){return new u}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g),g}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f),f}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c),c}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c),c}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c),c}path(a,b){let c=this.gen.path(a,b);return this.draw(c),c}draw(a){let b=a.sets||[],c=a.options||this.gen.defaultOptions,d=this.ctx;for(let e of b)switch(e.type){case'path':d.save(),d.strokeStyle=c.stroke,d.lineWidth=c.strokeWidth,this._drawToContext(d,e),d.restore();break;case'fillPath':d.save(),d.fillStyle=c.fill,this._drawToContext(d,e,c),d.restore();break;case'fillSketch':this._fillSketch(d,e,c);break;case'path2Dfill':{this.ctx.save(),this.ctx.fillStyle=c.fill;let a=new Path2D(e.path);this.ctx.fill(a),this.ctx.restore();break}case'path2Dpattern':{let a=e.size;const b=document.createElement('canvas'),d=b.getContext('2d');let f=this._computeBBox(e.path);f&&(f.width||f.height)?(b.width=this.canvas.width,b.height=this.canvas.height,d.translate(f.x||0,f.y||0)):(b.width=a[0],b.height=a[1]),this._fillSketch(d,e,c),this.ctx.save(),this.ctx.fillStyle=this.ctx.createPattern(b,'repeat');let g=new Path2D(e.path);this.ctx.fill(g),this.ctx.restore();break}}}_computeBBox(a){if(self.document)try{const b='http://www.w3.org/2000/svg';let c=self.document.createElementNS(b,'svg');c.setAttribute('width','0'),c.setAttribute('height','0');let d=self.document.createElementNS(b,'path');d.setAttribute('d',a),c.appendChild(d),self.document.body.appendChild(c);let e=d.getBBox();return self.document.body.removeChild(c),e}catch(a){}return null}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2),a.save(),a.strokeStyle=c.fill,a.lineWidth=d,this._drawToContext(a,b),a.restore()}_drawToContext(a,b){a.beginPath();for(let c of b.ops){const b=c.data;switch(c.op){case'move':a.moveTo(b[0],b[1]);break;case'bcurveTo':a.bezierCurveTo(b[0],b[1],b[2],b[3],b[4],b[5]);break;case'qcurveTo':a.quadraticCurveTo(b[0],b[1],b[2],b[3]);break;case'lineTo':a.lineTo(b[0],b[1]);}}'fillPath'===b.type?a.fill():a.stroke()}}class y extends x{_init(a){this.gen=new w(a,this.canvas)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g),g}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g),g}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g),g}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f),f}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c),c}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c),c}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j),j}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c),c}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c),c}}class z{constructor(a,b){this.svg=a,this._init(b)}_init(a){this.gen=new v(a,this.svg)}get generator(){return this.gen}get defs(){if(!this._defs){let a=this.svg.ownerDocument||document,b=a.createElementNS('http://www.w3.org/2000/svg','defs');this.svg.firstChild?this.svg.insertBefore(b,this.svg.firstChild):this.svg.appendChild(b),this._defs=b}return this._defs}line(a,b,c,e,f){let g=this.gen.line(a,b,c,e,f);return this.draw(g)}rectangle(a,b,c,e,f){let g=this.gen.rectangle(a,b,c,e,f);return this.draw(g)}ellipse(a,b,c,e,f){let g=this.gen.ellipse(a,b,c,e,f);return this.draw(g)}circle(a,b,c,e){let f=this.gen.circle(a,b,c,e);return this.draw(f)}linearPath(a,b){let c=this.gen.linearPath(a,b);return this.draw(c)}polygon(a,b){let c=this.gen.polygon(a,b);return this.draw(c)}arc(a,b,c,e,f,g,h,i){let j=this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}curve(a,b){let c=this.gen.curve(a,b);return this.draw(c)}path(a,b){let c=this.gen.path(a,b);return this.draw(c)}draw(a){let c=a.sets||[],d=a.options||this.gen.defaultOptions,f=this.svg.ownerDocument||document,h=f.createElementNS('http://www.w3.org/2000/svg','g');for(let g of c){let a=null;switch(g.type){case'path':{a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',this._opsToPath(g)),a.style.stroke=d.stroke,a.style.strokeWidth=d.strokeWidth,a.style.fill='none';break}case'fillPath':{a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',this._opsToPath(g)),a.style.stroke='none',a.style.strokeWidth=0,a.style.fill=d.fill;break}case'fillSketch':{a=this._fillSketch(f,g,d);break}case'path2Dfill':{a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',g.path),a.style.stroke='none',a.style.strokeWidth=0,a.style.fill=d.fill;break}case'path2Dpattern':{const c=g.size,h=f.createElementNS('http://www.w3.org/2000/svg','pattern'),i=`rough-${e(Math.random()*(Number.MAX_SAFE_INTEGER||999999))}`;h.setAttribute('id',i),h.setAttribute('x',0),h.setAttribute('y',0),h.setAttribute('width',1),h.setAttribute('height',1),h.setAttribute('height',1),h.setAttribute('viewBox',`0 0 ${b(c[0])} ${b(c[1])}`),h.setAttribute('patternUnits','objectBoundingBox');const j=this._fillSketch(f,g,d);h.appendChild(j),this.defs.appendChild(h),a=f.createElementNS('http://www.w3.org/2000/svg','path'),a.setAttribute('d',g.path),a.style.stroke='none',a.style.strokeWidth=0,a.style.fill=`url(#${i})`;break}}a&&h.appendChild(a)}return h}_fillSketch(a,b,c){let d=c.fillWeight;0>d&&(d=c.strokeWidth/2);let e=a.createElementNS('http://www.w3.org/2000/svg','path');return e.setAttribute('d',this._opsToPath(b)),e.style.stroke=c.fill,e.style.strokeWidth=d,e.style.fill='none',e}_opsToPath(a){return this.gen.opsToPath(a)}}class A extends z{_init(a){this.gen=new w(a,this.svg)}async line(a,b,c,e,f){let g=await this.gen.line(a,b,c,e,f);return this.draw(g)}async rectangle(a,b,c,e,f){let g=await this.gen.rectangle(a,b,c,e,f);return this.draw(g)}async ellipse(a,b,c,e,f){let g=await this.gen.ellipse(a,b,c,e,f);return this.draw(g)}async circle(a,b,c,e){let f=await this.gen.circle(a,b,c,e);return this.draw(f)}async linearPath(a,b){let c=await this.gen.linearPath(a,b);return this.draw(c)}async polygon(a,b){let c=await this.gen.polygon(a,b);return this.draw(c)}async arc(a,b,c,e,f,g,h,i){let j=await this.gen.arc(a,b,c,e,f,g,h,i);return this.draw(j)}async curve(a,b){let c=await this.gen.curve(a,b);return this.draw(c)}async path(a,b){let c=await this.gen.path(a,b);return this.draw(c)}}var B={canvas(a,b){return b&&b.async?new y(a,b):new x(a,b)},svg(a,b){return b&&b.async?new A(a,b):new z(a,b)},createRenderer(){return x.createRenderer()},generator(a,b){return a&&a.async?new w(a,b):new v(a,b)}};return B}); \ No newline at end of file diff --git a/src/path.js b/src/path.js index 4fe6435..21b9a30 100644 --- a/src/path.js +++ b/src/path.js @@ -304,8 +304,8 @@ export class RoughArcConverter { var numerator = this._rx * this._rx * this._ry * this._ry - this._rx * this._rx * y1dash * y1dash - this._ry * this._ry * x1dash * x1dash; if (numerator < 0) { let s = Math.sqrt(1 - (numerator / (this._rx * this._rx * this._ry * this._ry))); - this._rx = s; - this._ry = s; + this._rx = this._rx * s; + this._ry = this._ry * s; root = 0; } else { root = (largeArcFlag == sweepFlag ? -1.0 : 1.0) * From 4ba3eb35b9ff3fb4e3595fa24c5faab490f5204f Mon Sep 17 00:00:00 2001 From: Preet Shihn Date: Sat, 12 May 2018 14:59:27 -0700 Subject: [PATCH 2/2] bumped version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 31c80a9..4a4f268 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "roughjs", - "version": "2.1.2", + "version": "2.1.3", "description": "Create graphics using HTML Canvas or SVG with a hand-drawn, sketchy, appearance.", "main": "dist/rough.umd.js", "jsnext:main": "src/index.js", @@ -34,4 +34,4 @@ "babel-minify": "^0.3.0", "rollup": "^0.56.5" } -} +} \ No newline at end of file