diff --git a/dist/rough.js b/dist/rough.js index 4d62d1a..465adf5 100644 --- a/dist/rough.js +++ b/dist/rough.js @@ -956,7 +956,6 @@ class RoughRenderer { ops = ops.concat(o1, o2); } else { let ro = o.maxRandomnessOffset || 0; - console.log('largeArcFlag', largeArcFlag); for (let i = 0; i < 1; i++) { let arcConverter = new RoughArcConverter( [path.x, path.y], diff --git a/dist/rough.min.js b/dist/rough.min.js index f31f536..693b79b 100644 --- a/dist/rough.min.js +++ b/dist/rough.min.js @@ -1 +1 @@ -var RoughCanvas=function(){"use strict";function a(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var b=Math.tan,c=Math.cos,d=Math.sin,e=Math.PI,f=Math.sqrt,g=Math.max,h=Math.min,i=Math.abs,j=Number.MAX_VALUE;class k{constructor(b,c,d,e){this.RoughSegmentRelationConst=a(),this.px1=b,this.py1=c,this.px2=d,this.py2=e,this.xi=j,this.yi=j,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=j,f=j,k=0,l=0,m=this.a,n=this.b,b=this.c;return(1e-5=h(d.py1,d.py2)&&this.py1<=g(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=h(d.py1,d.py2)&&this.py2<=g(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+l,-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==j?(this.xi=d.px1,this.yi=e*this.xi+k,-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(m)?-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):e==f?k==l?this.px1>=h(d.px1,d.px2)&&this.px1<=g(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=h(d.px1,d.px2)&&this.px2<=g(d.px1,d.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(l-k)/(e-f),this.yi=e*this.xi+k,-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,g=d-b;return f(e*e+g*g)}}class l{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 k(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=f(1-p/(this._rx*this._rx*this._ry*this._ry));this._rx=a,this._ry=a,m=0}else m=(j==k?-1:1)*f(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*e),this._numSegs=Math.ceil(i(s/(e/2))),this._delta=s/this._numSegs,this._T=8/3*d(this._delta/4)*d(this._delta/4)/d(this._delta/2),this._from=a}getNextSegment(){var a,b,e;if(this._segIndex==this._numSegs)return null;let f=c(this._theta),g=d(this._theta),h=this._theta+this._delta,i=c(h),j=d(h);return e=[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*g-this._sinPhi*this._ry*f),this._from[1]+this._T*(-this._sinPhi*this._rx*g+this._cosPhi*this._ry*f)],b=[e[0]+this._T*(this._cosPhi*this._rx*j+this._sinPhi*this._ry*i),e[1]+this._T*(this._sinPhi*this._rx*j-this._cosPhi*this._ry*i)],this._theta=h,this._from=[e[0],e[1]],this._segIndex++,{cp1:a,cp2:b,to:e}}calculateVectorAngle(a,b,c,d){var f=Math.atan2;let g=f(b,a),h=f(d,c);return h>=g?h-g:2*e-(g-h)}}class o{line(a,b,c,d,e){let f=this._line(a,b,c,d,e,!0,!1),g=this._line(a,b,c,d,e,!0,!0);return{type:"path",ops:f.concat(g)}}linearPath(a,b,c){const d=(a||[]).length;if(2s;)s+=2*e,t+=2*e;t-s>2*e&&(s=0,t=2*e);let u=2*e/n.curveStepCount,v=h(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 l&&(m?(y=y.concat(this._line(o,p,o+q*c(s),p+r*d(s),n,!0,!1)),y=y.concat(this._line(o,p,o+q*c(s),p+r*d(s),n,!0,!0)),y=y.concat(this._line(o,p,o+q*c(t),p+r*d(t),n,!0,!1)),y=y.concat(this._line(o,p,o+q*c(t),p+r*d(t),n,!0,!0))):(y.push({op:"lineTo",data:[o,p]}),y.push({op:"lineTo",data:[o+q*c(s),p+r*d(s)]}))),{type:"path",ops:y}}hachureFillArc(a,b,f,g,h,j,k){let l=a,m=b,n=i(f/2),o=i(g/2);n+=this._getOffset(.01*-n,.01*n,k),o+=this._getOffset(.01*-o,.01*o,k);let p=h,q=j;for(;0>p;)p+=2*e,q+=2*e;q-p>2*e&&(p=0,q=2*e);let r=(q-p)/k.curveStepCount,s=[],t=[];for(let e=p;e<=q;e+=r)s.push(l+n*c(e)),t.push(m+o*d(e));return s.push(l+n*c(q)),t.push(m+o*d(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*j.strokeWidth),q=g(q,.1);const r=i%180*(e/180),s=c(r),t=d(r),u=b(r),v=new l(o-1,p+1,m-1,n+1,q,t,s,u);for(let b;null!=(b=v.getNextLine());){let c=this._getIntersectingLines(b,a,f);for(let a=0;a=n&&(n=4*h.strokeWidth);let o=h.fillWeight;0>o&&(o=h.strokeWidth/2);let p=b(m%180*(e/180)),q=l/k,r=f(q*p*q*p+1),s=q*p/r,t=1/r,u=n/(k*l/f(l*t*(l*t)+k*s*(k*s))/k),v=f(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);const h=this._line(a.x,a.y,f,g,d,!0,!1),i=this._line(a.x,a.y,f,g,d,!0,!0);a.setPosition(f,g),e=e.concat(h,i)}break}case"H":case"h":{const c="h"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.x);const g=this._line(a.x,a.y,f,a.y,d,!0,!1),h=this._line(a.x,a.y,f,a.y,d,!0,!0);a.setPosition(f,a.y),e=e.concat(g,h)}break}case"V":case"v":{const c="v"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.y);const g=this._line(a.x,a.y,a.x,f,d,!0,!1),h=this._line(a.x,a.y,a.x,f,d,!0,!0);a.setPosition(a.x,f),e=e.concat(g,h)}break}case"Z":case"z":{if(a.first){const b=this._line(a.x,a.y,a.first[0],a.first[1],d,!0,!1),c=this._line(a.x,a.y,a.first[0],a.first[1],d,!0,!0);a.setPosition(a.first[0],a.first[1]),e=e.concat(b,c),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){const b=this._line(a.x,a.y,k,l,!0,!1),c=this._line(a.x,a.y,k,l,!0,!1);a.setPosition(k,l),e=e.concat(b,c)}else{d.maxRandomnessOffset||0;console.log("largeArcFlag",i);for(let b=0;1>b;b++){let b=new p([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]}_line(a,b,c,d,e,g,h){var i=Math.pow;const j=i(a-c,2)+i(b-d,2);let k=e.maxRandomnessOffset||0;100*(k*k)>j&&(k=f(j)/10);const l=k/2,m=.2+.2*Math.random();let n=e.bowing*e.maxRandomnessOffset*(d-b)/200,o=e.bowing*e.maxRandomnessOffset*c/200;n=this._getOffset(-n,n,e),o=this._getOffset(-o,o,e);let p=[];return g&&(h?p.push({op:"move",data:[a+this._getOffset(-l,l,e),b+this._getOffset(-l,l,e)]}):p.push({op:"move",data:[a+this._getOffset(-k,k,e),b+this._getOffset(-k,k,e)]})),h?p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-l,l,e),o+b+(d-b)*m+this._getOffset(-l,l,e),n+a+2*(c-a)*m+this._getOffset(-l,l,e),o+b+2*(d-b)*m+this._getOffset(-l,l,e),c+this._getOffset(-l,l,e),d+this._getOffset(-l,l,e)]}):p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-k,k,e),o+b+(d-b)*m+this._getOffset(-k,k,e),n+a+2*(c-a)*m+this._getOffset(-k,k,e),o+b+2*(d-b)*m+this._getOffset(-k,k,e),c+this._getOffset(-k,k,e),d+this._getOffset(-k,k,e)]}),p}_curve(a,c,d){const e=a.length;let f=[];if(3d&&(d=c.strokeWidth/2),a.save(),a.strokeStyle=c.fill,a.lineWidth=d,this._drawToContext(a,b),a.restore()}_fill(a,b,c){a.save(),a.fillStyle=c.fill,b.type="fillPath",this._drawToContext(a,b,c),a.restore()}_drawToContext(a,b){if("path"===b.type||"fillPath"===b.type){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()}}}}(); \ No newline at end of file +var RoughCanvas=function(){"use strict";function a(){return{LEFT:0,RIGHT:1,INTERSECTS:2,AHEAD:3,BEHIND:4,SEPARATE:5,UNDEFINED:6}}var b=Math.tan,c=Math.cos,d=Math.sin,e=Math.PI,f=Math.sqrt,g=Math.max,h=Math.min,i=Math.abs,j=Number.MAX_VALUE;class k{constructor(b,c,d,e){this.RoughSegmentRelationConst=a(),this.px1=b,this.py1=c,this.px2=d,this.py2=e,this.xi=j,this.yi=j,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=j,f=j,k=0,l=0,m=this.a,n=this.b,b=this.c;return(1e-5=h(d.py1,d.py2)&&this.py1<=g(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.py2>=h(d.py1,d.py2)&&this.py2<=g(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+l,-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==j?(this.xi=d.px1,this.yi=e*this.xi+k,-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(m)?-1e-5>(this.px1-this.xi)*(this.xi-this.px2)?this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.INTERSECTS:this.RoughSegmentRelationConst.INTERSECTS):e==f?k==l?this.px1>=h(d.px1,d.px2)&&this.px1<=g(d.py1,d.py2)?(this.xi=this.px1,this.yi=this.py1,this.RoughSegmentRelationConst.INTERSECTS):this.px2>=h(d.px1,d.px2)&&this.px2<=g(d.px1,d.px2)?(this.xi=this.px2,this.yi=this.py2,this.RoughSegmentRelationConst.INTERSECTS):this.RoughSegmentRelationConst.SEPARATE:this.RoughSegmentRelationConst.SEPARATE:(this.xi=(l-k)/(e-f),this.yi=e*this.xi+k,-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,g=d-b;return f(e*e+g*g)}}class l{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 k(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=f(1-p/(this._rx*this._rx*this._ry*this._ry));this._rx=a,this._ry=a,m=0}else m=(j==k?-1:1)*f(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*e),this._numSegs=Math.ceil(i(s/(e/2))),this._delta=s/this._numSegs,this._T=8/3*d(this._delta/4)*d(this._delta/4)/d(this._delta/2),this._from=a}getNextSegment(){var a,b,e;if(this._segIndex==this._numSegs)return null;let f=c(this._theta),g=d(this._theta),h=this._theta+this._delta,i=c(h),j=d(h);return e=[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*g-this._sinPhi*this._ry*f),this._from[1]+this._T*(-this._sinPhi*this._rx*g+this._cosPhi*this._ry*f)],b=[e[0]+this._T*(this._cosPhi*this._rx*j+this._sinPhi*this._ry*i),e[1]+this._T*(this._sinPhi*this._rx*j-this._cosPhi*this._ry*i)],this._theta=h,this._from=[e[0],e[1]],this._segIndex++,{cp1:a,cp2:b,to:e}}calculateVectorAngle(a,b,c,d){var f=Math.atan2;let g=f(b,a),h=f(d,c);return h>=g?h-g:2*e-(g-h)}}class o{line(a,b,c,d,e){let f=this._line(a,b,c,d,e,!0,!1),g=this._line(a,b,c,d,e,!0,!0);return{type:"path",ops:f.concat(g)}}linearPath(a,b,c){const d=(a||[]).length;if(2s;)s+=2*e,t+=2*e;t-s>2*e&&(s=0,t=2*e);let u=2*e/n.curveStepCount,v=h(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 l&&(m?(y=y.concat(this._line(o,p,o+q*c(s),p+r*d(s),n,!0,!1)),y=y.concat(this._line(o,p,o+q*c(s),p+r*d(s),n,!0,!0)),y=y.concat(this._line(o,p,o+q*c(t),p+r*d(t),n,!0,!1)),y=y.concat(this._line(o,p,o+q*c(t),p+r*d(t),n,!0,!0))):(y.push({op:"lineTo",data:[o,p]}),y.push({op:"lineTo",data:[o+q*c(s),p+r*d(s)]}))),{type:"path",ops:y}}hachureFillArc(a,b,f,g,h,j,k){let l=a,m=b,n=i(f/2),o=i(g/2);n+=this._getOffset(.01*-n,.01*n,k),o+=this._getOffset(.01*-o,.01*o,k);let p=h,q=j;for(;0>p;)p+=2*e,q+=2*e;q-p>2*e&&(p=0,q=2*e);let r=(q-p)/k.curveStepCount,s=[],t=[];for(let e=p;e<=q;e+=r)s.push(l+n*c(e)),t.push(m+o*d(e));return s.push(l+n*c(q)),t.push(m+o*d(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*j.strokeWidth),q=g(q,.1);const r=i%180*(e/180),s=c(r),t=d(r),u=b(r),v=new l(o-1,p+1,m-1,n+1,q,t,s,u);for(let b;null!=(b=v.getNextLine());){let c=this._getIntersectingLines(b,a,f);for(let a=0;a=n&&(n=4*h.strokeWidth);let o=h.fillWeight;0>o&&(o=h.strokeWidth/2);let p=b(m%180*(e/180)),q=l/k,r=f(q*p*q*p+1),s=q*p/r,t=1/r,u=n/(k*l/f(l*t*(l*t)+k*s*(k*s))/k),v=f(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);const h=this._line(a.x,a.y,f,g,d,!0,!1),i=this._line(a.x,a.y,f,g,d,!0,!0);a.setPosition(f,g),e=e.concat(h,i)}break}case"H":case"h":{const c="h"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.x);const g=this._line(a.x,a.y,f,a.y,d,!0,!1),h=this._line(a.x,a.y,f,a.y,d,!0,!0);a.setPosition(f,a.y),e=e.concat(g,h)}break}case"V":case"v":{const c="v"===b.key;if(b.data.length){let f=+b.data[0];c&&(f+=a.y);const g=this._line(a.x,a.y,a.x,f,d,!0,!1),h=this._line(a.x,a.y,a.x,f,d,!0,!0);a.setPosition(a.x,f),e=e.concat(g,h)}break}case"Z":case"z":{if(a.first){const b=this._line(a.x,a.y,a.first[0],a.first[1],d,!0,!1),c=this._line(a.x,a.y,a.first[0],a.first[1],d,!0,!0);a.setPosition(a.first[0],a.first[1]),e=e.concat(b,c),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){const b=this._line(a.x,a.y,k,l,!0,!1),c=this._line(a.x,a.y,k,l,!0,!1);a.setPosition(k,l),e=e.concat(b,c)}else{d.maxRandomnessOffset||0;for(let b=0;1>b;b++){let b=new p([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]}_line(a,b,c,d,e,g,h){var i=Math.pow;const j=i(a-c,2)+i(b-d,2);let k=e.maxRandomnessOffset||0;100*(k*k)>j&&(k=f(j)/10);const l=k/2,m=.2+.2*Math.random();let n=e.bowing*e.maxRandomnessOffset*(d-b)/200,o=e.bowing*e.maxRandomnessOffset*c/200;n=this._getOffset(-n,n,e),o=this._getOffset(-o,o,e);let p=[];return g&&(h?p.push({op:"move",data:[a+this._getOffset(-l,l,e),b+this._getOffset(-l,l,e)]}):p.push({op:"move",data:[a+this._getOffset(-k,k,e),b+this._getOffset(-k,k,e)]})),h?p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-l,l,e),o+b+(d-b)*m+this._getOffset(-l,l,e),n+a+2*(c-a)*m+this._getOffset(-l,l,e),o+b+2*(d-b)*m+this._getOffset(-l,l,e),c+this._getOffset(-l,l,e),d+this._getOffset(-l,l,e)]}):p.push({op:"bcurveTo",data:[n+a+(c-a)*m+this._getOffset(-k,k,e),o+b+(d-b)*m+this._getOffset(-k,k,e),n+a+2*(c-a)*m+this._getOffset(-k,k,e),o+b+2*(d-b)*m+this._getOffset(-k,k,e),c+this._getOffset(-k,k,e),d+this._getOffset(-k,k,e)]}),p}_curve(a,c,d){const e=a.length;let f=[];if(3d&&(d=c.strokeWidth/2),a.save(),a.strokeStyle=c.fill,a.lineWidth=d,this._drawToContext(a,b),a.restore()}_fill(a,b,c){a.save(),a.fillStyle=c.fill,b.type="fillPath",this._drawToContext(a,b,c),a.restore()}_drawToContext(a,b){if("path"===b.type||"fillPath"===b.type){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()}}}}(); \ No newline at end of file diff --git a/src/renderer.js b/src/renderer.js index d092a8c..a7b93da 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -503,7 +503,6 @@ export class RoughRenderer { } else { let final = null; let ro = o.maxRandomnessOffset || 0; - console.log('largeArcFlag', largeArcFlag); for (let i = 0; i < 1; i++) { let arcConverter = new RoughArcConverter( [path.x, path.y],