diff --git a/article.js b/article.js index 1c5b3a12..e8692f13 100644 --- a/article.js +++ b/article.js @@ -59,7 +59,7 @@ return{TOLERANCE:1e-6,EPSILON:o,MACHINE_EPSILON:s,CURVETIME_EPSILON:4e-7,GEOMETR var e=["point: "+this._point];return this._handleIn.isZero()||e.push("handleIn: "+this._handleIn),this._handleOut.isZero()||e.push("handleOut: "+this._handleOut),"{ "+e.join(", ")+" }"},transform:function(e){this._transformCoordinates(e,new Array(6),!0),this._changed()},_transformCoordinates:function(e,t,n){var r=this._point,i=n&&this._handleIn.isZero()?null:this._handleIn,a=n&&this._handleOut.isZero()?null:this._handleOut,o=r._x,s=r._y,l=2;return t[0]=o,t[1]=s,i&&(t[l++]=i._x+o,t[l++]=i._y+s),a&&(t[l++]=a._x+o,t[l++]=a._y+s),e&&(e._transformCoordinates(t,t,l/2),o=t[0],s=t[1],n?(r._x=o,r._y=s,l=2,i&&(i._x=t[l++]-o,i._y=t[l++]-s),a&&(a._x=t[l++]-o,a._y=t[l++]-s)):(i||(t[l++]=o,t[l++]=s),a||(t[l++]=o,t[l++]=s))),t}}),M=f.extend({initialize:function(e,t,n){var r,i,a;if(e)if((r=e[0])!==o)i=e[1];else{var s=e;(r=s.x)===o&&(s=f.read(arguments),r=s.x),i=s.y,a=s.selected}else r=i=0;this._x=r,this._y=i,this._owner=t,t[n]=this,a&&this.setSelected(!0)},set:function(e,t){return this._x=e,this._y=t,this._owner._changed(this),this},_serialize:function(e){var t=e.formatter,n=t.number(this._x),r=t.number(this._y);return this.isSelected()?{x:n,y:r,selected:!0}:[n,r]},getX:function(){return this._x},setX:function(e){this._x=e,this._owner._changed(this)},getY:function(){return this._y},setY:function(e){this._y=e,this._owner._changed(this)},isZero:function(){return d.isZero(this._x)&&d.isZero(this._y)},setSelected:function(e){this._owner.setSelected(e,this)},isSelected:function(){return this._owner.isSelected(this)}}),I=s.extend({_class:"Curve",initialize:function(e,t,n,r,i,a,o,s){var l,u,c,h,d,p,f=arguments.length;3===f?(this._path=e,l=t,u=n):0===f?(l=new T,u=new T):1===f?"segment1"in e?(l=new T(e.segment1),u=new T(e.segment2)):"point1"in e?(c=e.point1,d=e.handle1,p=e.handle2,h=e.point2):Array.isArray(e)&&(c=[e[0],e[1]],h=[e[6],e[7]],d=[e[2]-e[0],e[3]-e[1]],p=[e[4]-e[6],e[5]-e[7]]):2===f?(l=new T(e),u=new T(t)):4===f?(c=e,d=t,p=n,h=r):8===f&&(c=[e,t],h=[o,s],d=[n-e,r-t],p=[i-o,a-s]),this._segment1=l||new T(c,null,d),this._segment2=u||new T(h,p,null)},_serialize:function(e){return s.serialize(this.hasHandles()?[this.getPoint1(),this.getHandle1(),this.getHandle2(),this.getPoint2()]:[this.getPoint1(),this.getPoint2()],e,!0)},_changed:function(){this._length=this._bounds=o},clone:function(){return new I(this._segment1,this._segment2)},toString:function(){var e=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||e.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||e.push("handle2: "+this._segment2._handleIn),e.push("point2: "+this._segment2._point),"{ "+e.join(", ")+" }"},remove:function(){var e=!1;if(this._path){var t=this._segment2,n=t._handleOut;e=t.remove(),e&&this._segment1._handleOut.set(n.x,n.y)}return e},getPoint1:function(){return this._segment1._point},setPoint1:function(){var e=f.read(arguments);this._segment1._point.set(e.x,e.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(){var e=f.read(arguments);this._segment2._point.set(e.x,e.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(){var e=f.read(arguments);this._segment1._handleOut.set(e.x,e.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(){var e=f.read(arguments);this._segment2._handleIn.set(e.x,e.y)},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var e=this._path&&this._path._curves;return e&&(e[this._segment1._index+1]||this._path._closed&&e[0])||null},getPrevious:function(){var e=this._path&&this._path._curves;return e&&(e[this._segment1._index-1]||this._path._closed&&e[e.length-1])||null},isFirst:function(){return 0===this._segment1._index},isLast:function(){var e=this._path;return e&&this._segment1._index===e._curves.length-1||!1},isSelected:function(){return this.getPoint1().isSelected()&&this.getHandle2().isSelected()&&this.getHandle2().isSelected()&&this.getPoint2().isSelected()},setSelected:function(e){this.getPoint1().setSelected(e),this.getHandle1().setSelected(e),this.getHandle2().setSelected(e),this.getPoint2().setSelected(e)},getValues:function(e){return I.getValues(this._segment1,this._segment2,e)},getPoints:function(){for(var e=this.getValues(),t=[],n=0;8>n;n+=2)t.push(new f(e[n],e[n+1]));return t},getLength:function(){return null==this._length&&(this._length=I.getLength(this.getValues(),0,1)),this._length},getArea:function(){return I.getArea(this.getValues())},getLine:function(){return new _(this._segment1._point,this._segment2._point)},getPart:function(e,t){return new I(I.getPart(this.getValues(),e,t))},getPartLength:function(e,t){return I.getLength(this.getValues(),e,t)},getIntersections:function(e){return I._getIntersections(this.getValues(),e&&e!==this?e.getValues():null,this,e,[],{})},_getParameter:function(e,t){return t?e:e&&e.curve===this?e.parameter:e===o&&t===o?.5:this.getParameterAt(e,0)},divide:function(e,t,n){var r=this._getParameter(e,t),i=4e-7,a=1-i,o=null;if(r>=i&&a>=r){var s=I.subdivide(this.getValues(),r),l=s[0],u=s[1],c=n||this.hasHandles(),h=this._segment1,d=this._segment2,p=this._path;c&&(h._handleOut.set(l[2]-l[0],l[3]-l[1]),d._handleIn.set(u[4]-u[6],u[5]-u[7]));var m=l[6],g=l[7],v=new T(new f(m,g),c&&new f(l[4]-m,l[5]-g),c&&new f(u[2]-m,u[3]-g));p?(p.insert(h._index+1,v),o=this.getNext()):(this._segment2=v,o=new I(v,d))}return o},split:function(e,t){return this._path?this._path.split(this._segment1._index,this._getParameter(e,t)):null},reversed:function(){return new I(this._segment2.reversed(),this._segment1.reversed())},clearHandles:function(){this._segment1._handleOut.set(0,0),this._segment2._handleIn.set(0,0)},statics:{getValues:function(e,t,n){var r=e._point,i=e._handleOut,a=t._handleIn,o=t._point,s=[r._x,r._y,r._x+i._x,r._y+i._y,o._x+a._x,o._y+a._y,o._x,o._y];return n&&n._transformCoordinates(s,s,4),s},subdivide:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],l=e[5],u=e[6],c=e[7];t===o&&(t=.5);var h=1-t,d=h*n+t*i,p=h*r+t*a,f=h*i+t*s,m=h*a+t*l,g=h*s+t*u,v=h*l+t*c,y=h*d+t*f,w=h*p+t*m,b=h*f+t*g,_=h*m+t*v,x=h*y+t*b,E=h*w+t*_;return[[n,r,d,p,y,w,x,E],[x,E,b,_,g,v,u,c]]},solveCubic:function(e,t,n,r,i,a){var o=e[t],s=e[t+2],l=e[t+4],u=e[t+6],c=3*(s-o),h=3*(l-s)-c,p=u-o-c-h;return d.solveCubic(p,h,c,o-n,r,i,a)},getParameterOf:function(e,t){var n=new f(e[0],e[1]),r=new f(e[6],e[7]),i=1e-12,a=t.isClose(n,i)?0:t.isClose(r,i)?1:null;if(null!==a)return a;for(var o=[t.x,t.y],s=[],l=2e-7,u=0;2>u;u++)for(var c=I.solveCubic(e,u,o[u],s,0,1),h=0;c>h;h++)if(a=s[h],t.isClose(I.getPoint(e,a),l))return a;return t.isClose(n,l)?0:t.isClose(r,l)?1:null},getNearestParameter:function(e,t){function n(n){if(n>=0&&1>=n){var r=t.getDistance(I.getPoint(e,n),!0);if(d>r)return d=r,p=n,!0}}if(I.isStraight(e)){var r=e[0],i=e[1],a=e[6],o=e[7],s=a-r,l=o-i,u=s*s+l*l;if(0===u)return 0;var c=((t.x-r)*s+(t.y-i)*l)/u;return 1e-12>c?0:c>.999999999999?1:I.getParameterOf(e,new f(r+c*s,i+c*l))}for(var h=100,d=1/0,p=0,m=0;h>=m;m++)n(m/h);for(var g=1/(2*h);g>4e-7;)n(p-g)||n(p+g)||(g/=2);return p},getPart:function(e,t,n){var r=t>n;if(r){var i=t;t=n,n=i}return t>0&&(e=I.subdivide(e,t)[1]),1>n&&(e=I.subdivide(e,(n-t)/(1-t))[0]),r?[e[6],e[7],e[4],e[5],e[2],e[3],e[0],e[1]]:e},hasHandles:function(e){var t=d.isZero;return!(t(e[0]-e[2])&&t(e[1]-e[3])&&t(e[4]-e[6])&&t(e[5]-e[7]))},isFlatEnough:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],l=e[6],u=e[7],c=3*i-2*n-l,h=3*a-2*r-u,d=3*o-2*l-n,p=3*s-2*u-r;return Math.max(c*c,d*d)+Math.max(h*h,p*p)<10*t*t},getArea:function(e){var t=e[0],n=e[1],r=e[6],i=e[7],a=(e[2]+t)/2,o=(e[3]+n)/2,s=(e[4]+e[6])/2,l=(e[5]+e[7])/2;return 6*((t-a)*(o+n)+(a-s)*(l+o)+(s-r)*(i+l))/10},getBounds:function(e){for(var t=e.slice(0,2),n=t.slice(),r=[0,0],i=0;2>i;i++)I._addBounds(e[i],e[i+2],e[i+4],e[i+6],i,0,t,n,r);return new y(t[0],t[1],n[0]-t[0],n[1]-t[1])},_addBounds:function(e,t,n,r,i,a,o,s,l){function u(e,t){var n=e-t,r=e+t;ns[i]&&(s[i]=r)}var c=3*(t-n)-e+r,h=2*(e+n)-4*t,p=t-e,f=d.solveQuadratic(c,h,p,l),m=4e-7,g=1-m;u(r,0);for(var v=0;f>v;v++){var y=l[v],w=1-y;y>m&&g>y&&u(w*w*w*e+3*w*w*y*t+3*w*y*y*n+y*y*y*r,a)}}}},s.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(e){this[e]=function(){this._bounds||(this._bounds={});var t=this._bounds[e];if(!t){var n=this._path;t=this._bounds[e]=L[e]([this._segment1,this._segment2],!1,n&&n.getStyle())}return t.clone()}},{}),s.each({isStraight:function(e,t,n){if(t.isZero()&&n.isZero())return!0;if(e.isZero())return!1;if(t.isCollinear(e)&&n.isCollinear(e)){var r=e.dot(e),i=e.dot(t)/r,a=e.dot(n)/r;return i>=0&&1>=i&&0>=a&&a>=-1}return!1},isLinear:function(e,t,n){var r=e.divide(3);return t.equals(r)&&n.negate().equals(r)}},function(e,t){this[t]=function(){var t=this._segment1,n=this._segment2;return e(n._point.subtract(t._point),t._handleOut,n._handleIn)},this.statics[t]=function(t){var n=t[0],r=t[1],i=t[6],a=t[7];return e(new f(i-n,a-r),new f(t[2]-n,t[3]-r),new f(t[4]-i,t[5]-a))}},{statics:{},hasHandles:function(){return!this._segment1._handleOut.isZero()||!this._segment2._handleIn.isZero()},isCollinear:function(e){return e&&this.isStraight()&&e.isStraight()&&this.getLine().isCollinear(e.getLine())},isHorizontal:function(){return this.isStraight()&&Math.abs(this.getTangentAt(.5,!0).y)<1e-7},isVertical:function(){return this.isStraight()&&Math.abs(this.getTangentAt(.5,!0).x)<1e-7}}),{beans:!1,getParameterAt:function(e,t){return I.getParameterAt(this.getValues(),e,t)},getParameterOf:function(){return I.getParameterOf(this.getValues(),f.read(arguments))},getLocationAt:function(e,t){var n=t?e:this.getParameterAt(e);return null!=n&&n>=0&&1>=n?new R(this,n):null},getLocationOf:function(){return this.getLocationAt(this.getParameterOf(f.read(arguments)),!0)},getOffsetOf:function(){var e=this.getLocationOf.apply(this,arguments);return e?e.getOffset():null},getNearestLocation:function(){var e=f.read(arguments),t=this.getValues(),n=I.getNearestParameter(t,e),r=I.getPoint(t,n);return new R(this,n,r,null,e.getDistance(r))},getNearestPoint:function(){return this.getNearestLocation.apply(this,arguments).getPoint()}},new function(){var e=["getPoint","getTangent","getNormal","getWeightedTangent","getWeightedNormal","getCurvature"];return s.each(e,function(e){this[e+"At"]=function(t,n){var r=this.getValues();return I[e](r,n?t:I.getParameterAt(r,t,0))}},{statics:{evaluateMethods:e}})},new function(){function e(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],l=e[7],u=9*(r-a)+3*(s-t),c=6*(t+a)-12*r,h=3*(r-t),d=9*(i-o)+3*(l-n),p=6*(n+o)-12*i,f=3*(i-n);return function(e){var t=(u*e+c)*e+h,n=(d*e+p)*e+f;return Math.sqrt(t*t+n*n)}}function t(e,t){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(t-e))))}function n(e,t,n,r){if(null==t||0>t||t>1)return null;var i,a,o=e[0],s=e[1],l=e[2],u=e[3],c=e[4],h=e[5],d=e[6],p=e[7],m=4e-7,g=1-m;if(0===n&&(m>t||t>g)){var v=m>t;i=v?o:d,a=v?s:p}else{var y=3*(l-o),w=3*(c-l)-y,b=d-o-y-w,_=3*(u-s),x=3*(h-u)-_,E=p-s-_-x;if(0===n)i=((b*t+w)*t+y)*t+o,a=((E*t+x)*t+_)*t+s;else{if(m>t?(i=y,a=_):t>g?(i=3*(d-c),a=3*(p-h)):(i=(3*b*t+2*w)*t+y,a=(3*E*t+2*x)*t+_),r){0===i&&0===a&&(m>t||t>g)&&(i=c-l,a=h-u);var C=Math.sqrt(i*i+a*a);C&&(i/=C,a/=C)}if(3===n){var N=6*b*t+2*w,k=6*E*t+2*x,S=Math.pow(i*i+a*a,1.5);i=0!==S?(i*k-a*N)/S:0,a=0}}}return 2===n?new f(a,-i):new f(i,a)}return{statics:{getLength:function(n,r,i){if(r===o&&(r=0),i===o&&(i=1),0===r&&1===i&&I.isStraight(n)){var a=n[6]-n[0],s=n[7]-n[1];return Math.sqrt(a*a+s*s)}var l=e(n);return d.integrate(l,r,i,t(r,i))},getParameterAt:function(n,r,i){function a(e){return m+=d.integrate(h,i,e,t(i,e)),i=e,m-r}if(i===o&&(i=0>r?1:0),0===r)return i;var s=Math.abs,l=r>0,u=l?i:0,c=l?1:i,h=e(n),p=d.integrate(h,u,c,t(u,c));if(s(r-p)<1e-12)return l?c:u;if(s(r)>p)return null;var f=r/p,m=0;return d.findRoot(a,h,i+f,u,c,32,1e-12)},getPoint:function(e,t){return n(e,t,0,!1)},getTangent:function(e,t){return n(e,t,1,!0)},getWeightedTangent:function(e,t){return n(e,t,1,!1)},getNormal:function(e,t){return n(e,t,2,!0)},getWeightedNormal:function(e,t){return n(e,t,2,!1)},getCurvature:function(e,t){return n(e,t,3,!1).x}}}},new function(){function e(e,t,n,r,i,a,o,s,l,u,c){var h=t.startConnected,d=t.endConnected,p=4e-7,f=1-p;if(null==i&&(i=I.getParameterOf(n,a)),null!==i&&i>=(h?p:0)&&(d?f:1)>=i&&(null==l&&(l=I.getParameterOf(o,u)),null!==l&&l>=(d?p:0)&&(h?f:1)>=l)){var m=t.renormalize;if(m){var g=m(i,l);i=g[0],l=g[1]}var v=new R(r,i,a||I.getPoint(n,i),c),y=new R(s,l,u||I.getPoint(o,l),c),w=v.getPath()===y.getPath()&&v.getIndex()>y.getIndex(),b=w?y:v,_=t.include;v._intersection=y,y._intersection=v,(!_||_(b))&&R.insert(e,b,!0)}}function t(i,a,o,s,l,u,c,h,d,p,f,m,g){if(!(++g>=24)){var v,y,w=a[0],b=a[1],x=a[6],E=a[7],C=_.getSignedDistance,N=C(w,b,x,E,a[2],a[3]),k=C(w,b,x,E,a[4],a[5]),S=N*k>0?.75:4/9,P=S*Math.min(0,N,k),O=S*Math.max(0,N,k),D=C(w,b,x,E,i[0],i[1]),T=C(w,b,x,E,i[2],i[3]),M=C(w,b,x,E,i[4],i[5]),R=C(w,b,x,E,i[6],i[7]),A=n(D,T,M,R),L=A[0],z=A[1];if(null!=(v=r(L,z,P,O))&&null!=(y=r(L.reverse(),z.reverse(),P,O))){i=I.getPart(i,v,y);var V=y-v,B=c+(h-c)*v,j=c+(h-c)*y;if(f>.5&&V>.5)if(j-B>p-d){var F=I.subdivide(i,.5),q=B+(j-B)/2;t(a,F[0],s,o,l,u,d,p,B,q,V,!m,g),t(a,F[1],s,o,l,u,d,p,q,j,V,!m,g)}else{var F=I.subdivide(a,.5),q=d+(p-d)/2;t(F[0],i,s,o,l,u,d,q,B,j,V,!m,g),t(F[1],i,s,o,l,u,q,p,B,j,V,!m,g)}else if(Math.max(p-d,j-B)<1e-7){var U=B+(j-B)/2,W=d+(p-d)/2;i=o.getValues(),a=s.getValues(),e(l,u,m?a:i,m?s:o,m?W:U,null,m?i:a,m?o:s,m?U:W,null)}else V>1e-12&&t(a,i,s,o,l,u,d,p,B,j,V,!m,g)}}}function n(e,t,n,r){var i,a=[0,e],o=[1/3,t],s=[2/3,n],l=[1,r],u=t-(2*e+r)/3,c=n-(e+2*r)/3;if(0>u*c)i=[[a,o,l],[a,s,l]];else{var h=u/c;i=[h>=2?[a,o,l]:.5>=h?[a,s,l]:[a,o,s,l],[a,l]]}return 0>(u||c)?i.reverse():i}function r(e,t,n,r){return e[0][1]r?i(t,!1,r):e[0][0]}function i(e,t,n){for(var r=e[0][0],i=e[0][1],a=1,o=e.length;o>a;a++){var s=e[a][0],l=e[a][1];if(t?l>=n:n>=l)return l===n?s:r+(n-i)*(s-r)/(l-i);r=s,i=l}return null}function a(t,n,r,i,a,o){for(var s=I.isStraight(t),l=s?n:t,u=s?t:n,c=u[0],h=u[1],p=u[6],f=u[7],m=p-c,g=f-h,v=Math.atan2(-g,m),y=Math.sin(v),w=Math.cos(v),b=[],_=0;8>_;_+=2){var x=l[_]-c,E=l[_+1]-h;b.push(x*w-E*y,x*y+E*w)}for(var C=[],N=I.solveCubic(b,1,0,C,0,1),_=0;N>_;_++){var k=C[_],S=I.getPoint(l,k),P=I.getParameterOf(u,S);if(null!==P){var O=I.getPoint(u,P),D=s?P:k,T=s?k:P;(!o.endConnected||T>d.CURVETIME_EPSILON)&&e(a,o,t,r,D,s?O:S,n,i,T,s?S:O)}}}function o(t,n,r,i,a,o){var s=_.intersect(t[0],t[1],t[6],t[7],n[0],n[1],n[6],n[7]);s&&e(a,o,t,r,null,s,n,i,null,s)}return{statics:{_getIntersections:function(n,r,i,s,l,u){if(!r)return I._getSelfIntersection(n,i,l,u);var c=n[0],h=n[1],d=n[6],p=n[7],m=r[0],g=r[1],v=r[6],y=r[7],w=(3*n[2]+c)/4,b=(3*n[3]+h)/4,_=(3*n[4]+d)/4,x=(3*n[5]+p)/4,E=(3*r[2]+m)/4,C=(3*r[3]+g)/4,N=(3*r[4]+v)/4,k=(3*r[5]+y)/4,S=Math.min,P=Math.max;if(!(P(c,w,_,d)>=S(m,E,N,v)&&S(c,w,_,d)<=P(m,E,N,v)&&P(h,b,x,p)>=S(g,C,k,y)&&S(h,b,x,p)<=P(g,C,k,y)))return l;if(!u.startConnected&&!u.endConnected){var O=I.getOverlaps(n,r);if(O){for(var D=0;2>D;D++){var T=O[D];e(l,u,n,i,T[0],null,r,s,T[1],null,!0)}return l}}var M=I.isStraight(n),R=I.isStraight(r),A=M&&R,L=1e-12,z=l.length;if((A?o:M||R?a:t)(n,r,i,s,l,u,0,1,0,1,0,!1,0),A&&l.length>z)return l;var V=new f(c,h),B=new f(d,p),j=new f(m,g),F=new f(v,y);return V.isClose(j,L)&&e(l,u,n,i,0,V,r,s,0,j),!u.startConnected&&V.isClose(F,L)&&e(l,u,n,i,0,V,r,s,1,F),!u.endConnected&&B.isClose(j,L)&&e(l,u,n,i,1,B,r,s,0,j),B.isClose(F,L)&&e(l,u,n,i,1,B,r,s,1,F),l},_getSelfIntersection:function(e,t,n,r){var i=e[0],a=e[1],o=e[2],s=e[3],l=e[4],u=e[5],c=e[6],h=e[7],p=new _(i,a,c,h,!1),m=p.getSide(new f(o,s),!0),g=p.getSide(new f(l,u),!0);if(m===g){var v=(i-l)*(s-h)+(o-c)*(u-a);if(v*m>0)return n}var y=c-3*l+3*o-i,w=l-2*o+i,b=o-i,x=h-3*u+3*s-a,E=u-2*s+a,C=s-a,N=x*b-y*C,k=x*w-y*E,S=E*b-w*C;if(0>N*N-4*k*S){var P,O=[],D=d.solveCubic(y*y+x*x,3*(y*w+x*E),2*(w*w+E*E)+y*b+x*C,w*b+E*C,O,0,1);if(D>0){for(var T=0,M=0;D>T;T++){var R=Math.abs(t.getCurvatureAt(O[T],!0));R>M&&(M=R,P=O[T])}var A=I.subdivide(e,P);r.endConnected=!0,r.renormalize=function(e,t){return[e*P,t*(1-P)+P]},I._getIntersections(A[0],A[1],t,t,n,r)}}return n},getOverlaps:function(e,t){function n(e){var t=e[6]-e[0],n=e[7]-e[1];return t*t+n*n}var r=Math.abs,i=4e-7,a=2e-7,o=I.isStraight(e),s=I.isStraight(t),l=o&&s;if(l){var u=n(e)a||d.getDistance(new f(h[6],h[7]))>a)return null}else if(o^s)return null;for(var p=[e,t],m=[],g=0,v=0;2>g&&m.length<2;g+=0===v?0:1,v=1^v){var y=I.getParameterOf(p[1^g],new f(p[g][0===v?0:6],p[g][0===v?1:7]));if(null!=y){var w=0===g?[v,y]:[y,v];(0===m.length||r(w[0]-m[0][0])>i&&r(w[1]-m[0][1])>i)&&m.push(w)}if(1===g&&0===m.length)break}if(2!==m.length)m=null;else if(!l){var b=I.getPart(e,m[0][0],m[1][0]),x=I.getPart(t,m[0][1],m[1][1]);(r(x[2]-b[2])>a||r(x[3]-b[3])>a||r(x[4]-b[4])>a||r(x[5]-b[5])>a)&&(m=null)}return m}}}}),R=s.extend({_class:"CurveLocation",beans:!0,initialize:function be(e,t,n,r,i){if(t>.9999996){var a=e.getNext();a&&(t=0,e=a)}this._id=p.get(be),this._setCurve(e),this._parameter=t,this._point=n||e.getPointAt(t,!0),this._overlap=r,this._distance=i,this._intersection=this._next=this._prev=null},_setCurve:function(e){var t=e._path;this._version=t?t._version:0,this._curve=e,this._segment=null,this._segment1=e._segment1,this._segment2=e._segment2},_setSegment:function(e){this._setCurve(e.getCurve()),this._segment=e,this._parameter=e===this._segment1?0:1,this._point=e._point.clone()},getSegment:function(){var e=this.getCurve(),t=this._segment;if(!t){var n=this.getParameter();0===n?t=e._segment1:1===n?t=e._segment2:null!=n&&(t=e.getPartLength(0,n)i;i++)e+=r[i].getLength();this._offset=e+=this.getCurveOffset()}return e},getCurveOffset:function(){var e=this.getCurve(),t=this.getParameter();return null!=t&&e&&e.getPartLength(0,t)},getIntersection:function(){return this._intersection},getDistance:function(){return this._distance},divide:function(){var e=this.getCurve(),t=null;return e&&(t=e.divide(this.getParameter(),!0),t&&this._setSegment(t._segment1)),t},split:function(){var e=this.getCurve();return e?e.split(this.getParameter(),!0):null},equals:function(e,t){var n=this===e,r=2e-7;if(!n&&e instanceof R&&this.getPath()===e.getPath()&&this.getPoint().isClose(e.getPoint(),r)){var i=this.getCurve(),a=e.getCurve(),o=Math.abs,s=o((i.isLast()&&a.isFirst()?-1:i.getIndex())+this.getParameter()-((a.isLast()&&i.isFirst()?-1:a.getIndex())+e.getParameter()));n=(4e-7>s||(s=o(this.getOffset()-e.getOffset()))t?e>t&&n>e:e>t&&c>=e||e>=-c&&n>e}var t=this._intersection;if(!t)return!1;var n=this.getParameter(),r=t.getParameter(),i=4e-7,a=1-i;if(n>=i&&a>=n||r>=i&&a>=r)return!this.isTouching();var o=this.getCurve(),s=o.getPrevious(),l=t.getCurve(),u=l.getPrevious(),c=Math.PI;if(!s||!u)return!1;var h=s.getTangentAt(a,!0).negate().getAngleInRadians(),d=o.getTangentAt(i,!0).getAngleInRadians(),p=u.getTangentAt(a,!0).negate().getAngleInRadians(),f=l.getTangentAt(i,!0).getAngleInRadians();return e(p,h,d)^e(f,h,d)&&e(p,d,h)^e(f,d,h)},isOverlap:function(){return!!this._overlap}},s.each(I.evaluateMethods,function(e){var t=e+"At";this[e]=function(){var e=this.getParameter(),n=this.getCurve();return null!=e&&n&&n[t](e,!0)}},{preserve:!0}),new function(){function e(e,t,n){function r(n,r){for(var a=n+r;a>=-1&&i>=a;a+=r){var o=e[(a%i+i)%i];if(!t.getPoint().isClose(o.getPoint(),2e-7))break;if(t.equals(o))return o}return null}for(var i=e.length,a=0,o=i-1;o>=a;){var s,l=a+o>>>1,u=e[l];if(n&&(s=t.equals(u)?u:r(l,-1)||r(l,1)))return t._overlap&&(s._overlap=s._intersection._overlap=!0),s;var c=t.getPath(),h=u.getPath(),d=c===h?t.getIndex()+t.getParameter()-(u.getIndex()+u.getParameter()):c._id-h._id;0>d?o=l-1:a=l+1}return e.splice(a,0,t),t}return{statics:{insert:e,expand:function(t){for(var n=t.slice(),r=0,i=t.length;i>r;r++)e(n,t[r]._intersection,!1);return n}}}}),A=C.extend({_class:"PathItem",initialize:function(){},getIntersections:function(e,t,n,r){var i=this===e||!e,a=this._matrix.orNullIfIdentity(),o=i?a:(n||e._matrix).orNullIfIdentity();if(!i&&!this.getBounds(a).touches(e.getBounds(o)))return[];for(var s,e,l=this.getCurves(),u=i?l:e.getCurves(),c=l.length,h=i?c:u.length,d=[],p=[],f=0;h>f;f++)d[f]=u[f].getValues(o);for(var f=0;c>f;f++){var m=l[f],g=i?d[f]:m.getValues(a),v=m.getPath();v!==e&&(e=v,s=[],p.push(s)),i&&I._getSelfIntersection(g,m,s,{include:t,startConnected:1===c&&m.getPoint1().equals(m.getPoint2())});for(var y=i?f+1:0;h>y;y++){if(r&&s.length)return s;var w=u[y];I._getIntersections(g,d[y],m,w,s,{include:t,startConnected:i&&m.getPrevious()===w,endConnected:i&&m.getNext()===w})}}s=[];for(var f=0,b=p.length;b>f;f++)s.push.apply(s,p[f]);return s},getCrossings:function(e){return this.getIntersections(e,function(e){return e.isCrossing()})},_asPathItem:function(){return this},setPathData:function(e){function t(e,t){var n=+r[e];return s&&(n+=l[t]),n}function n(e){return new f(t(e,"x"),t(e+1,"y"))}var r,i,a,o=e.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi),s=!1,l=new f,u=new f;this.clear();for(var c=0,h=o&&o.length;h>c;c++){var d=o[c],p=d[0],m=p.toLowerCase();r=d.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);var v=r&&r.length;switch(s=p===m,"z"!==i||/[mz]/.test(m)||this.moveTo(l=u),m){case"m":case"l":for(var y="m"===m,w=0;v>w;w+=2)this[0===w&&y?"moveTo":"lineTo"](l=n(w));a=l,y&&(u=l);break;case"h":case"v":for(var b="h"===m?"x":"y",w=0;v>w;w++)l[b]=t(w,b),this.lineTo(l);a=l;break;case"c":for(var w=0;v>w;w+=6)this.cubicCurveTo(n(w),a=n(w+2),l=n(w+4));break;case"s":for(var w=0;v>w;w+=4)this.cubicCurveTo(/[cs]/.test(i)?l.multiply(2).subtract(a):l,a=n(w),l=n(w+2)),i=m;break;case"q":for(var w=0;v>w;w+=4)this.quadraticCurveTo(a=n(w),l=n(w+2));break;case"t":for(var w=0;v>w;w+=2)this.quadraticCurveTo(a=/[qt]/.test(i)?l.multiply(2).subtract(a):l,l=n(w)),i=m;break;case"a":for(var w=0;v>w;w+=7)this.arcTo(l=n(w+5),new g(+r[w],+r[w+1]),+r[w+2],+r[w+4],+r[w+3]);break;case"z":this.closePath(!0)}i=m}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_contains:function(e){var t=this._getWinding(e,!1,!0);return!!("evenodd"===this.getWindingRule()?1&t:t)}}),L=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(e){this._closed=!1,this._segments=[],this._version=0;var t=Array.isArray(e)?"object"==typeof e[0]?e:arguments:!e||e.size!==o||e.x===o&&e.point===o?null:arguments;t&&t.length>0?this.setSegments(t):(this._curves=o,this._selectedSegmentState=0,t||"string"!=typeof e||(this.setPathData(e),e=null)),this._initialize(!t&&e)},_equals:function(e){return this._closed===e._closed&&s.equals(this._segments,e._segments)},clone:function(e){var t=new L(C.NO_INSERT);return t.setSegments(this._segments),t._closed=this._closed,this._clockwise!==o&&(t._clockwise=this._clockwise),this._clone(t,e)},_changed:function _e(e){if(_e.base.call(this,e),8&e){var t=this._parent;if(t&&(t._currentPath=o),this._length=this._area=this._clockwise=this._monoCurves=o,16&e)this._version++;else if(this._curves)for(var n=0,r=this._curves.length;r>n;n++)this._curves[n]._changed()}else 32&e&&(this._bounds=o)},getStyle:function(){var e=this._parent;return(e instanceof z?e:this)._style},getSegments:function(){return this._segments},setSegments:function(e){var t=this.isFullySelected();this._segments.length=0,this._selectedSegmentState=0,this._curves=o,e&&e.length>0&&this._add(T.readAll(e)),t&&this.setFullySelected(!0)},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var e=this._curves,t=this._segments;if(!e){var n=this._countCurves();e=this._curves=new Array(n);for(var r=0;n>r;r++)e[r]=new I(this,t[r],t[r+1]||t[0])}return e},getFirstCurve:function(){return this.getCurves()[0]},getLastCurve:function(){var e=this.getCurves();return e[e.length-1]},isClosed:function(){return this._closed},setClosed:function(e){if(this._closed!=(e=!!e)){if(this._closed=e,this._curves){var t=this._curves.length=this._countCurves();e&&(this._curves[t-1]=new I(this,this._segments[t-1],this._segments[0]))}this._changed(25)}}},{beans:!0,getPathData:function(e,t){function n(t,n){t._transformCoordinates(e,m,!1),r=m[0],i=m[1],g?(v.push("M"+f.pair(r,i)),g=!1):(s=m[2],l=m[3],s===r&&l===i&&u===a&&c===o?n||v.push("l"+f.pair(r-a,i-o)):v.push("c"+f.pair(u-a,c-o)+" "+f.pair(s-a,l-o)+" "+f.pair(r-a,i-o))),a=r,o=i,u=m[4],c=m[5]}var r,i,a,o,s,l,u,c,d=this._segments,p=d.length,f=new h(t),m=new Array(6),g=!0,v=[];if(0===p)return"";for(var y=0;p>y;y++)n(d[y]);return this._closed&&p>0&&(n(d[0],!0),v.push("z")),v.join("")}},{isEmpty:function(){return 0===this._segments.length},_transformContent:function(e){for(var t=new Array(6),n=0,r=this._segments.length;r>n;n++)this._segments[n]._transformCoordinates(e,t,!0);return!0},_add:function(e,t){for(var n=this._segments,r=this._curves,i=e.length,a=null==t,t=a?n.length:t,o=0;i>o;o++){var s=e[o];s._path&&(s=e[o]=s.clone()),s._path=this,s._index=t+o,s._selectionState&&this._updateSelection(s,0,s._selectionState)}if(a)n.push.apply(n,e);else{n.splice.apply(n,[t,0].concat(e));for(var o=t+i,l=n.length;l>o;o++)n[o]._index=o}if(r){var u=this._countCurves(),c=t+i-1===u?t-1:t,h=c,d=Math.min(c+i,u);e._curves&&(r.splice.apply(r,[c,0].concat(e._curves)),h+=e._curves.length);for(var o=h;d>o;o++)r.splice(o,0,new I(this,null,null));this._adjustCurves(c,d)}return this._changed(25),e},_adjustCurves:function(e,t){for(var n,r=this._segments,i=this._curves,a=e;t>a;a++)n=i[a],n._path=this,n._segment1=r[a],n._segment2=r[a+1]||r[0],n._changed();(n=i[this._closed&&0===e?r.length-1:e-1])&&(n._segment2=r[e]||r[0],n._changed()),(n=i[t])&&(n._segment1=r[t],n._changed())},_countCurves:function(){var e=this._segments.length;return!this._closed&&e>0?e-1:e},add:function(e){return arguments.length>1&&"number"!=typeof e?this._add(T.readAll(arguments)):this._add([T.read(arguments)])[0]},insert:function(e,t){return arguments.length>2&&"number"!=typeof t?this._add(T.readAll(arguments,1),e):this._add([T.read(arguments,1)],e)[0]},addSegment:function(){return this._add([T.read(arguments)])[0]},insertSegment:function(e){return this._add([T.read(arguments,1)],e)[0]},addSegments:function(e){return this._add(T.readAll(e))},insertSegments:function(e,t){return this._add(T.readAll(t),e)},removeSegment:function(e){return this.removeSegments(e,e+1)[0]||null},removeSegments:function(e,t,n){e=e||0,t=s.pick(t,this._segments.length);var r=this._segments,i=this._curves,a=r.length,o=r.splice(e,t-e),l=o.length;if(!l)return o;for(var u=0;l>u;u++){var c=o[u];c._selectionState&&this._updateSelection(c,c._selectionState,0),c._index=c._path=null}for(var u=e,h=r.length;h>u;u++)r[u]._index=u;if(i){var d=e>0&&t===a+(this._closed?1:0)?e-1:e,i=i.splice(d,l);n&&(o._curves=i.slice(1)),this._adjustCurves(d,d)}return this._changed(25),o},clear:"#removeSegments",hasHandles:function(){for(var e=this._segments,t=0,n=e.length;n>t;t++)if(e[t].hasHandles())return!0;return!1},clearHandles:function(){for(var e=this._segments,t=0,n=e.length;n>t;t++)e[t].clearHandles()},getLength:function(){if(null==this._length){for(var e=this.getCurves(),t=0,n=0,r=e.length;r>n;n++)t+=e[n].getLength();this._length=t}return this._length},getArea:function(){if(null==this._area){for(var e=this._segments,t=e.length,n=t-1,r=0,i=0,a=this._closed?t:n;a>i;i++)r+=I.getArea(I.getValues(e[i],e[n>i?i+1:0]));this._area=r}return this._area},isClockwise:function(){return this._clockwise!==o?this._clockwise:this.getArea()>=0},setClockwise:function(e){this.isClockwise()!=(e=!!e)&&this.reverse(),this._clockwise=e},isFullySelected:function(){var e=this._segments.length;return this._selected&&e>0&&this._selectedSegmentState===7*e},setFullySelected:function(e){e&&this._selectSegments(!0),this.setSelected(e)},setSelected:function xe(e){e||this._selectSegments(!1),xe.base.call(this,e)},_selectSegments:function(e){var t=this._segments.length;this._selectedSegmentState=e?7*t:0;for(var n=0;t>n;n++)this._segments[n]._selectionState=e?7:0},_updateSelection:function(e,t,n){e._selectionState=n;var r=this._selectedSegmentState+=n-t;r>0&&this.setSelected(!0)},flatten:function(e){for(var t=new V(this,64,.1),n=0,r=t.length/Math.ceil(t.length/e),i=t.length+(this._closed?-r:r)/2,a=[];i>=n;)a.push(new T(t.getPointAt(n))),n+=r;this.setSegments(a)},reduce:function(){for(var e=this.getCurves(),t=e.length-1;t>=0;t--){var n=e[t];n.hasHandles()||0!==n.getLength()&&!n.isCollinear(n.getNext())||n.remove()}return this},simplify:function(e){if(this._segments.length>2){var t=new B(this,e||2.5);this.setSegments(t.fit())}},split:function(e,t){if(null===t)return null;if(1===arguments.length){var n=e;if("number"==typeof n&&(n=this.getLocationAt(n)),!n)return null;e=n.index,t=n.parameter}var r=4e-7,i=1-r;t>=i&&(e++,t--);var a=this.getCurves();if(e>=0&&e=r&&a[e++].divide(t,!0);var o,s=this.removeSegments(e,this._segments.length,!0);return this._closed?(this.setClosed(!1),o=this):(o=new L(C.NO_INSERT),o.insertAbove(this,!0),this._clone(o)),o._add(s,0),this.addSegment(s[0]),o}return null},reverse:function(){this._segments.reverse();for(var e=0,t=this._segments.length;t>e;e++){var n=this._segments[e],r=n._handleIn;n._handleIn=n._handleOut,n._handleOut=r,n._index=e}this._curves=null,this._clockwise!==o&&(this._clockwise=!this._clockwise),this._changed(9)},join:function(e){if(e){var t=e._segments,n=this.getLastSegment(),r=e.getLastSegment();if(!r)return this;n&&n._point.equals(r._point)&&e.reverse();var i=e.getFirstSegment();if(n&&n._point.equals(i._point))n.setHandleOut(i._handleOut),this._add(t.slice(1));else{var a=this.getFirstSegment();a&&a._point.equals(i._point)&&e.reverse(),r=e.getLastSegment(),a&&a._point.equals(r._point)?(a.setHandleIn(r._handleIn),this._add(t.slice(0,t.length-1),0)):this._add(t.slice())}e._closed&&this._add([t[0]]),e.remove()}var o=this.getFirstSegment(),s=this.getLastSegment();return o!==s&&o._point.equals(s._point)&&(o.setHandleIn(s._handleIn),s.remove(),this.setClosed(!0)),this},toShape:function(e){function t(e,t){var n=u[e],r=n.getNext(),i=u[t],a=i.getNext();return n._handleOut.isZero()&&r._handleIn.isZero()&&i._handleOut.isZero()&&a._handleIn.isZero()&&r._point.subtract(n._point).isCollinear(a._point.subtract(i._point))}function n(e){var t=u[e],n=t.getPrevious(),r=t.getNext();return n._handleOut.isZero()&&t._handleIn.isZero()&&t._handleOut.isZero()&&r._handleIn.isZero()&&t._point.subtract(n._point).isOrthogonal(r._point.subtract(t._point)); }function r(e){var t=u[e],n=t.getNext(),r=t._handleOut,i=n._handleIn,a=.5522847498307936;if(r.isOrthogonal(i)){var o=t._point,s=n._point,l=new _(o,r,!0).intersect(new _(s,i,!0),!0);return l&&d.isZero(r.getLength()/l.subtract(o).getLength()-a)&&d.isZero(i.getLength()/l.subtract(s).getLength()-a)}return!1}function i(e,t){return u[e]._point.getDistance(u[t]._point)}if(!this._closed)return null;var a,o,s,l,u=this._segments;if(!this.hasHandles()&&4===u.length&&t(0,2)&&t(1,3)&&n(1)?(a=S.Rectangle,o=new g(i(0,3),i(0,1)),l=u[1]._point.add(u[2]._point).divide(2)):8===u.length&&r(0)&&r(2)&&r(4)&&r(6)&&t(1,5)&&t(3,7)?(a=S.Rectangle,o=new g(i(1,6),i(0,3)),s=o.subtract(new g(i(0,7),i(1,2))).divide(2),l=u[3]._point.add(u[4]._point).divide(2)):4===u.length&&r(0)&&r(1)&&r(2)&&r(3)&&(d.isZero(i(0,2)-i(1,3))?(a=S.Circle,s=i(0,2)/2):(a=S.Ellipse,s=new g(i(2,0)/2,i(3,1)/2)),l=u[1]._point),a){var c=this.getPosition(!0),h=this._clone(new a({center:c,size:o,radius:s,insert:!1}),e,!1);return h.rotate(l.subtract(c).getAngle()+90),h}return null},_hitTestSelf:function(e,t){function n(t,n){return e.subtract(t).divide(n).length<=1}function r(e,r,i){if(!t.selected||r.isSelected()){var a=e._point;if(r!==a&&(r=r.add(a)),n(r,b))return new D(i,p,{segment:e,point:r})}}function i(e,n){return(n||t.segments)&&r(e,e._point,"segment")||!n&&t.handles&&(r(e,e._handleIn,"handle-in")||r(e,e._handleOut,"handle-out"))}function a(e){c.add(e)}function o(t){if(("round"!==s||"round"!==l)&&(c=new L({internal:!0,closed:!0}),y||t._index>0&&t._index0||E?0:null;if(null!==C&&(C>0?(s=m.getStrokeJoin(),l=m.getStrokeCap(),u=C*m.getMiterLimit(),b=w.add(new f(C,C))):s=l="round"),!t.ends||t.segments||y){if(t.segments||t.handles)for(var N=0;v>N;N++)if(d=i(g[N]))return d}else if(d=i(g[0],!0)||i(g[v-1],!0))return d;if(null!==C){if(h=this.getNearestLocation(e)){var k=h.getParameter();0===k||1===k&&v>1?o(h.getSegment())||(h=null):n(h.getPoint(),b)||(h=null)}if(!h&&"miter"===s&&v>1)for(var N=0;v>N;N++){var S=g[N];if(e.getDistance(S._point)<=u&&o(S)){h=S.getLocation();break}}}return!h&&x&&this._contains(e)||h&&!_&&!E?new D("fill",this):h?new D(_?"stroke":"curve",this,{location:h,point:h.getPoint()}):null}},s.each(I.evaluateMethods,function(e){this[e+"At"]=function(t,n){var r=this.getLocationAt(t,n);return r&&r[e]()}},{beans:!1,getLocationOf:function(){for(var e=f.read(arguments),t=this.getCurves(),n=0,r=t.length;r>n;n++){var i=t[n].getLocationOf(e);if(i)return i}return null},getOffsetOf:function(){var e=this.getLocationOf.apply(this,arguments);return e?e.getOffset():null},getLocationAt:function(e,t){var n=this.getCurves(),r=0;if(t){var i=~~e,a=n[i];return a?a.getLocationAt(e-i,!0):null}for(var o=0,s=n.length;s>o;o++){var l=r,a=n[o];if(r+=a.getLength(),r>e)return a.getLocationAt(e-l)}return n.length>0&&e<=this.getLength()?new R(n[n.length-1],1):null},getNearestLocation:function(){for(var e=f.read(arguments),t=this.getCurves(),n=1/0,r=null,i=0,a=t.length;a>i;i++){var o=t[i].getNearestLocation(e);o._distances;s++){var u=t[s];u._transformCoordinates(n,o,!1);var c=u._selectionState,h=o[0],d=o[1];if(1&c&&i(2),2&c&&i(4),e.fillRect(h-a,d-a,r,r),!(4&c)){var p=e.fillStyle;e.fillStyle="#ffffff",e.fillRect(h-a+1,d-a+1,r-2,r-2),e.fillStyle=p}}}function t(e,t,n){function r(t){if(n)t._transformCoordinates(n,f,!1),i=f[0],a=f[1];else{var r=t._point;i=r._x,a=r._y}if(m)e.moveTo(i,a),m=!1;else{if(n)l=f[2],u=f[3];else{var d=t._handleIn;l=i+d._x,u=a+d._y}l===i&&u===a&&c===o&&h===s?e.lineTo(i,a):e.bezierCurveTo(c,h,l,u,i,a)}if(o=i,s=a,n)c=f[4],h=f[5];else{var d=t._handleOut;c=o+d._x,h=s+d._y}}for(var i,a,o,s,l,u,c,h,d=t._segments,p=d.length,f=new Array(6),m=!0,g=0;p>g;g++)r(d[g]);t._closed&&p>0&&r(d[0])}return{_draw:function(e,n,r){function i(e){return h[(e%d+d)%d]}var o=n.dontStart,s=n.dontFinish||n.clip,l=this.getStyle(),u=l.hasFill(),c=l.hasStroke(),h=l.getDashArray(),d=!a.support.nativeDash&&c&&h&&h.length;if(o||e.beginPath(),!o&&this._currentPath?e.currentPath=this._currentPath:(u||c&&!d||s)&&(t(e,this,r),this._closed&&e.closePath(),o||(this._currentPath=e.currentPath)),!s&&(u||c)&&(this._setStyles(e),u&&(e.fill(l.getWindingRule()),e.shadowColor="rgba(0,0,0,0)"),c)){if(d){o||e.beginPath();var p,f=new V(this,32,.25,r),m=f.length,g=-l.getDashOffset(),v=0;for(g%=m;g>0;)g-=i(v--)+i(v--);for(;m>g;)p=g+i(v++),(g>0||p>0)&&f.drawPart(e,Math.max(g,0),Math.max(p,0)),g=p+i(v++)}e.stroke()}},_drawSelected:function(n,r){n.beginPath(),t(n,this,r),n.stroke(),e(n,this._segments,r,a.settings.handleSize)}}},new function(){function e(e){var t=e.length,n=[],r=[],i=2;n[0]=e[0]/i;for(var a=1;t>a;a++)r[a]=1/i,i=(t-1>a?4:2)-r[a],n[a]=(e[a]-n[a-1])/i;for(var a=1;t>a;a++)n[t-a-1]-=r[t-a]*n[t-a];return n}return{smooth:function(){var t=this._segments,n=t.length,r=this._closed,i=n,a=0;if(!(2>=n)){r&&(a=Math.min(n,4),i+=2*Math.min(n,a));for(var o=[],s=0;n>s;s++)o[s+a]=t[s]._point;if(r)for(var s=0;a>s;s++)o[s]=t[s+n-a]._point,o[s+n+a]=t[s]._point;else i--;for(var l=[],s=1;i-1>s;s++)l[s]=4*o[s]._x+2*o[s+1]._x;l[0]=o[0]._x+2*o[1]._x,l[i-1]=3*o[i-1]._x;for(var u=e(l),s=1;i-1>s;s++)l[s]=4*o[s]._y+2*o[s+1]._y;l[0]=o[0]._y+2*o[1]._y,l[i-1]=3*o[i-1]._y;var c=e(l);if(r){for(var s=0,h=n;a>s;s++,h++){var d=s/a,p=1-d,m=s+a,g=h+a;u[h]=u[s]*d+u[h]*p,c[h]=c[s]*d+c[h]*p,u[g]=u[m]*p+u[g]*d,c[g]=c[m]*p+c[g]*d}i--}for(var v=null,s=a;i-a>=s;s++){var y=t[s-a];v&&y.setHandleIn(v.subtract(y._point)),i>s&&(y.setHandleOut(new f(u[s],c[s]).subtract(y._point)),v=i-1>s?new f(2*o[s+1]._x-u[s+1],2*o[s+1]._y-c[s+1]):new f((o[i]._x+u[i-1])/2,(o[i]._y+c[i-1])/2))}if(r&&v){var y=this._segments[0];y.setHandleIn(v.subtract(y._point))}}}}},new function(){function e(e){var t=e._segments;if(0===t.length)throw new Error("Use a moveTo() command first");return t[t.length-1]}return{moveTo:function(){var e=this._segments;1===e.length&&this.removeSegment(0),e.length||this._add([new T(f.read(arguments))])},moveBy:function(){throw new Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new T(f.read(arguments))])},cubicCurveTo:function(){var t=f.read(arguments),n=f.read(arguments),r=f.read(arguments),i=e(this);i.setHandleOut(t.subtract(i._point)),this._add([new T(r,n.subtract(r))])},quadraticCurveTo:function(){var t=f.read(arguments),n=f.read(arguments),r=e(this)._point;this.cubicCurveTo(t.add(r.subtract(t).multiply(1/3)),t.add(n.subtract(t).multiply(1/3)),n)},curveTo:function(){var t=f.read(arguments),n=f.read(arguments),r=s.pick(s.read(arguments),.5),i=1-r,a=e(this)._point,o=t.subtract(a.multiply(i*i)).subtract(n.multiply(r*r)).divide(2*r*i);if(o.isNaN())throw new Error("Cannot put a curve through points with parameter = "+r);this.quadraticCurveTo(o,n)},arcTo:function(){var t,n,r,i,a,o=e(this),l=o._point,u=f.read(arguments),c=s.peek(arguments),h=s.pick(c,!0);if("boolean"==typeof h)var d=l.add(u).divide(2),t=d.add(d.subtract(l).rotate(h?-90:90));else if(s.remain(arguments)<=2)t=u,u=f.read(arguments);else{var p=g.read(arguments);if(p.isZero())return this.lineTo(u);var m=s.read(arguments),h=!!s.read(arguments),v=!!s.read(arguments),d=l.add(u).divide(2),y=l.subtract(d).rotate(-m),w=y.x,x=y.y,E=Math.abs,C=E(p.width),N=E(p.height),k=C*C,S=N*N,P=w*w,O=x*x,D=Math.sqrt(P/k+O/S);if(D>1&&(C*=D,N*=D,k=C*C,S=N*N),D=(k*S-k*O-S*P)/(k*O+S*P),E(D)<1e-12&&(D=0),0>D)throw new Error("Cannot create an arc with the given arguments");n=new f(C*x/N,-N*w/C).multiply((v===h?-1:1)*Math.sqrt(D)).rotate(m).add(d),a=(new b).translate(n).rotate(m).scale(C,N),i=a._inverseTransform(l),r=i.getDirectedAngle(a._inverseTransform(u)),!h&&r>0?r-=360:h&&0>r&&(r+=360)}if(t){var M=new _(l.add(t).divide(2),t.subtract(l).rotate(90),!0),I=new _(t.add(u).divide(2),u.subtract(t).rotate(90),!0),R=new _(l,u),A=R.getSide(t);if(n=M.intersect(I,!0),!n){if(!A)return this.lineTo(u);throw new Error("Cannot create an arc with the given arguments")}i=l.subtract(n),r=i.getDirectedAngle(u.subtract(n));var L=R.getSide(n);0===L?r=A*Math.abs(r):A===L&&(r+=0>r?360:-360)}for(var z=Math.abs(r),V=z>=360?4:Math.ceil(z/90),B=r/V,j=B*Math.PI/360,F=4/3*Math.sin(j)/(1+Math.cos(j)),q=[],U=0;V>=U;U++){var y=u,W=null;if(V>U&&(W=i.rotate(90).multiply(F),a?(y=a._transformPoint(i),W=a._transformPoint(i.add(W)).subtract(y)):y=n.add(i)),0===U)o.setHandleOut(W);else{var G=i.rotate(-90).multiply(F);a&&(G=a._transformPoint(i.add(G)).subtract(y)),q.push(new T(y,G,W))}i=i.rotate(B)}this._add(q)},lineBy:function(){var t=f.read(arguments),n=e(this)._point;this.lineTo(n.add(t))},curveBy:function(){var t=f.read(arguments),n=f.read(arguments),r=s.read(arguments),i=e(this)._point;this.curveTo(i.add(t),i.add(n),r)},cubicCurveBy:function(){var t=f.read(arguments),n=f.read(arguments),r=f.read(arguments),i=e(this)._point;this.cubicCurveTo(i.add(t),i.add(n),i.add(r))},quadraticCurveBy:function(){var t=f.read(arguments),n=f.read(arguments),r=e(this)._point;this.quadraticCurveTo(r.add(t),r.add(n))},arcBy:function(){var t=e(this)._point,n=t.add(f.read(arguments)),r=s.pick(s.peek(arguments),!0);"boolean"==typeof r?this.arcTo(n,r):this.arcTo(n,t.add(f.read(arguments)))},closePath:function(e){this.setClosed(!0),e&&this.join()}}},{_getBounds:function(e,t){return L[e](this._segments,this._closed,this.getStyle(),t)},statics:{getBounds:function(e,t,n,r,i){function a(e){e._transformCoordinates(r,s,!1);for(var t=0;2>t;t++)I._addBounds(l[t],l[t+4],s[t+2],s[t],t,i?i[t]:0,u,c,h);var n=l;l=s,s=n}var o=e[0];if(!o)return new y;for(var s=new Array(6),l=o._transformCoordinates(r,new Array(6),!1),u=l.slice(0,2),c=u.slice(),h=new Array(2),d=1,p=e.length;p>d;d++)a(e[d]);return t&&a(o),new y(u[0],u[1],c[0]-u[0],c[1]-u[1])},getStrokeBounds:function(e,t,n,r){function i(e){h=h.include(r?r._transformPoint(e,e):e)}function a(e){h=h.unite(m.setCenter(r?r._transformPoint(e._point):e._point))}function o(e,t){var n=e._handleIn,r=e._handleOut;"round"===t||!n.isZero()&&!r.isZero()&&n.isCollinear(r)?a(e):L._addBevelJoin(e,t,u,f,i)}function s(e,t){"round"===t?a(e):L._addSquareCap(e,t,u,i)}if(!n.hasStroke())return L.getBounds(e,t,n,r);for(var l=e.length-(t?0:1),u=n.getStrokeWidth()/2,c=L._getPenPadding(u,r),h=L.getBounds(e,t,n,r,c),d=n.getStrokeJoin(),p=n.getStrokeCap(),f=u*n.getMiterLimit(),m=new y(new g(c).multiply(2)),v=1;l>v;v++)o(e[v],d);return t?o(e[0],d):l>0&&(s(e[0],p),s(e[e.length-1],p)),h},_getPenPadding:function(e,t){if(!t)return[e,e];var n=t.shiftless(),r=n.transform(new f(e,0)),i=n.transform(new f(0,e)),a=r.getAngleInRadians(),o=r.getLength(),s=i.getLength(),l=Math.sin(a),u=Math.cos(a),c=Math.tan(a),h=-Math.atan(s*c/o),d=Math.atan(s/(c*o));return[Math.abs(o*Math.cos(h)*u-s*Math.sin(h)*l),Math.abs(s*Math.sin(d)*u+o*Math.cos(d)*l)]},_addBevelJoin:function(e,t,n,r,i,a){var o=e.getCurve(),s=o.getPrevious(),l=o.getPointAt(0,!0),u=s.getNormalAt(1,!0),c=o.getNormalAt(0,!0),h=u.getDirectedAngle(c)<0?-n:n;if(u.setLength(h),c.setLength(h),a&&(i(l),i(l.add(u))),"miter"===t){var d=new _(l.add(u),new f(-u.y,u.x),!0).intersect(new _(l.add(c),new f(-c.y,c.x),!0),!0);if(d&&l.getDistance(d)<=r&&(i(d),!a))return}a||i(l.add(u)),i(l.add(c))},_addSquareCap:function(e,t,n,r,i){var a=e._point,o=e.getLocation(),s=o.getNormal().multiply(n);i&&(r(a.subtract(s)),r(a.add(s))),"square"===t&&(a=a.add(s.rotate(0===o.getParameter()?-90:90))),r(a.add(s)),r(a.subtract(s))},getHandleBounds:function(e,t,n,r,i,a){for(var o=new Array(6),s=1/0,l=-s,u=s,c=l,h=0,d=e.length;d>h;h++){var p=e[h];p._transformCoordinates(r,o,!1);for(var f=0;6>f;f+=2){var m=0===f?a:i,g=m?m[0]:0,v=m?m[1]:0,w=o[f],b=o[f+1],_=w-g,x=w+g,E=b-v,C=b+v;s>_&&(s=_),x>l&&(l=x),u>E&&(u=E),C>c&&(c=C)}}return new y(s,u,l-s,c-u)},getRoughBounds:function(e,t,n,r){var i=n.hasStroke()?n.getStrokeWidth()/2:0,a=i;return i>0&&("miter"===n.getStrokeJoin()&&(a=i*n.getMiterLimit()),"square"===n.getStrokeCap()&&(a=Math.max(a,i*Math.sqrt(2)))),L.getHandleBounds(e,t,n,r,L._getPenPadding(i,r),L._getPenPadding(a,r))}}});L.inject({statics:new function(){function e(e,t,n){var r=s.getNamed(n),i=new L(r&&r.insert===!1&&C.NO_INSERT);return i._add(e),i._closed=t,i.set(r)}function t(t,n,i){for(var a=new Array(4),o=0;4>o;o++){var s=r[o];a[o]=new T(s._point.multiply(n).add(t),s._handleIn.multiply(n),s._handleOut.multiply(n))}return e(a,!0,i)}var n=.5522847498307936,r=[new T([-1,0],[0,n],[0,-n]),new T([0,-1],[-n,0],[n,0]),new T([1,0],[0,-n],[0,n]),new T([0,1],[n,0],[-n,0])];return{Line:function(){return e([new T(f.readNamed(arguments,"from")),new T(f.readNamed(arguments,"to"))],!1,arguments)},Circle:function(){var e=f.readNamed(arguments,"center"),n=s.readNamed(arguments,"radius");return t(e,new g(n),arguments)},Rectangle:function(){var t,r=y.readNamed(arguments,"rectangle"),i=g.readNamed(arguments,"radius",0,{readNull:!0}),a=r.getBottomLeft(!0),o=r.getTopLeft(!0),s=r.getTopRight(!0),l=r.getBottomRight(!0);if(!i||i.isZero())t=[new T(a),new T(o),new T(s),new T(l)];else{i=g.min(i,r.getSize(!0).divide(2));var u=i.width,c=i.height,h=u*n,d=c*n;t=[new T(a.add(u,0),null,[-h,0]),new T(a.subtract(0,c),[0,d]),new T(o.add(0,c),null,[0,-d]),new T(o.add(u,0),[-h,0],null),new T(s.subtract(u,0),null,[h,0]),new T(s.add(0,c),[0,-d],null),new T(l.subtract(0,c),null,[0,d]),new T(l.subtract(u,0),[h,0])]}return e(t,!0,arguments)},RoundRectangle:"#Rectangle",Ellipse:function(){var e=S._readEllipse(arguments);return t(e.center,e.radius,arguments)},Oval:"#Ellipse",Arc:function(){var e=f.readNamed(arguments,"from"),t=f.readNamed(arguments,"through"),n=f.readNamed(arguments,"to"),r=s.getNamed(arguments),i=new L(r&&r.insert===!1&&C.NO_INSERT);return i.moveTo(e),i.arcTo(t,n),i.set(r)},RegularPolygon:function(){for(var t=f.readNamed(arguments,"center"),n=s.readNamed(arguments,"sides"),r=s.readNamed(arguments,"radius"),i=360/n,a=!(n%3),o=new f(0,a?-r:r),l=a?-1:.5,u=new Array(n),c=0;n>c;c++)u[c]=new T(t.add(o.rotate((c+l)*i)));return e(u,!0,arguments)},Star:function(){for(var t=f.readNamed(arguments,"center"),n=2*s.readNamed(arguments,"points"),r=s.readNamed(arguments,"radius1"),i=s.readNamed(arguments,"radius2"),a=360/n,o=new f(0,-1),l=new Array(n),u=0;n>u;u++)l[u]=new T(t.add(o.rotate(a*u).multiply(u%2?i:r)));return e(l,!0,arguments)}}}});var z=A.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(e){this._children=[],this._namedChildren={},this._initialize(e)||("string"==typeof e?this.setPathData(e):this.addChildren(Array.isArray(e)?e:arguments))},insertChildren:function Ee(e,t,n){for(var r=t.length-1;r>=0;r--){var i=t[r];i instanceof z&&(t.splice.apply(t,[r,1].concat(i.removeChildren())),i.remove())}t=Ee.base.call(this,e,t,n,L);for(var r=0,a=!n&&t&&t.length;a>r;r++){var i=t[r];i._clockwise===o&&i.setClockwise(0===i._index)}return t},reverse:function(){for(var e=this._children,t=0,n=e.length;n>t;t++)e[t].reverse()},smooth:function(){for(var e=0,t=this._children.length;t>e;e++)this._children[e].smooth()},reduce:function Ce(){for(var e=this._children,t=e.length-1;t>=0;t--){var n=e[t].reduce();n.isEmpty()&&e.splice(t,1)}if(0===e.length){var n=new L(C.NO_INSERT);return n.insertAbove(this),n.setStyle(this._style),this.remove(),n}return Ce.base.call(this)},isClockwise:function(){var e=this.getFirstChild();return e&&e.isClockwise()},setClockwise:function(e){this.isClockwise()!==!!e&&this.reverse()},getFirstSegment:function(){var e=this.getFirstChild();return e&&e.getFirstSegment()},getLastSegment:function(){var e=this.getLastChild();return e&&e.getLastSegment()},getCurves:function(){for(var e=this._children,t=[],n=0,r=e.length;r>n;n++)t.push.apply(t,e[n].getCurves());return t},getFirstCurve:function(){var e=this.getFirstChild();return e&&e.getFirstCurve()},getLastCurve:function(){var e=this.getLastChild();return e&&e.getFirstCurve()},getArea:function(){for(var e=this._children,t=0,n=0,r=e.length;r>n;n++)t+=e[n].getArea();return t}},{beans:!0,getPathData:function(e,t){for(var n=this._children,r=[],i=0,a=n.length;a>i;i++){var o=n[i],s=o._matrix;r.push(o.getPathData(e&&!s.isIdentity()?e.chain(s):e,t))}return r.join(" ")}},{_getChildHitTestOptions:function(e){return e["class"]===L||"path"===e.type?e:new s(e,{fill:!1})},_draw:function(e,t,n){var r=this._children;if(0!==r.length){if(this._currentPath)e.currentPath=this._currentPath;else{t=t.extend({dontStart:!0,dontFinish:!0}),e.beginPath();for(var i=0,a=r.length;a>i;i++)r[i].draw(e,t,n);this._currentPath=e.currentPath}if(!t.clip){this._setStyles(e);var o=this._style;o.hasFill()&&(e.fill(o.getWindingRule()),e.shadowColor="rgba(0,0,0,0)"),o.hasStroke()&&e.stroke()}}},_drawSelected:function(e,t,n){for(var r=this._children,i=0,a=r.length;a>i;i++){var o=r[i],s=o._matrix;n[o._id]||o._drawSelected(e,s.isIdentity()?t:t.chain(s))}}},new function(){function e(e,t){var n=e._children;if(t&&0===n.length)throw new Error("Use a moveTo() command first");return n[n.length-1]}var t={moveTo:function(){var t=e(this),n=t&&t.isEmpty()?t:new L(C.NO_INSERT);n!==t&&this.addChild(n),n.moveTo.apply(n,arguments)},moveBy:function(){var t=e(this,!0),n=t&&t.getLastSegment(),r=f.read(arguments);this.moveTo(n?r.add(n._point):r)},closePath:function(t){e(this,!0).closePath(t)}};return s.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","cubicCurveBy","quadraticCurveBy","curveBy","arcBy"],function(n){t[n]=function(){var t=e(this,!0);t[n].apply(t,arguments)}}),t});A.inject(new function(){function e(e,t){var n=e.clone(!1).reduce().transform(null,!0,!0);return t?n.resolveCrossings().reorient():n}function t(e,t,n,r,i){var a=new e(C.NO_INSERT);return a.addChildren(t,!0),i&&(a=a.reduce()),a.insertAbove(r&&n.isSibling(r)&&n.getIndex()t;t++){var r=e[t];p.push.apply(p,r._segments),f.push.apply(f,r._getMonoCurves())}}if(!n._children&&!n._closed)return r(n,i,o);var c=e(n,!0),h=i&&n!==i&&e(i,!0);h&&/^(subtract|exclude)$/.test(o)^h.isClockwise()!==c.isClockwise()&&h.reverse();var d=R.expand(c.getIntersections(h,function(e){return h&&e.isOverlap()||e.isCrossing()}));a(d);var p=[],f=[];u(c._children||[c]),h&&u(h._children||[h]);for(var m=0,g=d.length;g>m;m++)s(d[m]._segment,c,h,f,o);for(var m=0,g=p.length;g>m;m++){var v=p[m];null==v._winding&&s(v,c,h,f,o)}return t(z,l(p,o),n,i,!0)}function r(n,r,i){function a(e){return s.contains(e.getPointAt(e.getLength()/2))^u?(c.unshift(e),!0):void 0}if(!r||!r._children&&!r._closed||!/^(subtract|intersect)$/.test(i))return null;for(var o=e(n,!1),s=e(r,!1),l=o.getIntersections(s,function(e){return e.isOverlap()||e.isCrossing()}),u="subtract"===i,c=[],h=l.length-1;h>=0;h--){var d=l[h].split();d&&(a(d)&&d.getFirstSegment().setHandleIn(0,0),o.getLastSegment().setHandleOut(0,0))}return a(o),t(N,c,n,r)}function i(e,t){for(var n=e;n;){if(n===t)return;n=n._prev}for(;e._next&&e._next!==t;)e=e._next;if(!e._next){for(;t._prev;)t=t._prev;e._next=t,t._prev=e}}function a(e){for(var t,n,r=4e-7,a=1-r,o=!1,s=[],l=e.length-1;l>=0;l--){var u=e[l],c=u._curve,h=u._parameter,d=h;c!==t?o=!c.hasHandles():n>0&&(h/=n);var p;r>h?p=c._segment1:h>a?p=c._segment2:(p=c.divide(h,!0,!0)._segment1,o&&s.push(p)),u._setSegment(p);var f=p._intersection,m=u._intersection;if(f){i(f,m);for(var g=f;g;)i(g._intersection,f),g=g._next}else p._intersection=m;t=c,n=d}for(var l=0,v=s.length;v>l;l++)s[l].clearHandles()}function o(e,t,n,r){var i=2e-7,a=4e-7,s=1-a,l=e.x,u=e.y,c=0,h=0,p=[],m=Math.abs;if(n){for(var g=-(1/0),v=1/0,y=u-i,w=u+i,b=0,_=t.length;_>b;b++){var x=t[b].values;if(I.solveCubic(x,0,l,p,0,1)>0)for(var E=p.length-1;E>=0;E--){var C=I.getPoint(x,p[E]).y;y>C&&C>g?g=C:C>w&&v>C&&(v=C)}}g=(g+u)/2,v=(v+u)/2,g>-(1/0)&&(c=o(new f(l,g),t,!1,r)),1/0>v&&(h=o(new f(l,v),t,!1,r))}else for(var N,k,S=l-i,P=l+i,O=!1,b=0,_=t.length;_>b;b++){var D=t[b],x=D.values,T=D.winding;if(T&&(1===T&&u>=x[1]&&u<=x[7]||u>=x[7]&&u<=x[1])&&1===I.solveCubic(x,1,u,p,0,1)){var M=p[0];if(!(M>s&&O&&D.next!==t[b+1]||a>M&&k>s&&D.previous===N)){var R=I.getPoint(x,M).x,A=I.getTangent(x,M).y,L=!1;d.isZero(A)&&!I.isStraight(x)||a>M&&A*I.getTangent(D.previous.values,1).y<0||M>s&&A*I.getTangent(D.next.values,0).y<0?r&&R>=S&&P>=R&&(++c,++h,L=!0):S>=R?(c+=T,L=!0):R>=P&&(h+=T,L=!0),D.previous!==t[b-1]&&(O=a>M&&L)}N=D,k=M}}return Math.max(m(c),m(h))}function s(e,t,n,r,i){var a=2e-7,s=[],l=e,u=0,c=0;do{var h=e.getCurve(),d=h.getLength();s.push({segment:e,curve:h,length:d}),u+=d,e=e.getNext()}while(e&&!e._intersection&&e!==l);for(var p=0;3>p;p++)for(var d=u*(p+1)/4,f=0,m=s.length;m>f;f++){var g=s[f],v=g.length;if(v>=d){(a>d||a>v-d)&&(d=v/2);var h=g.curve,y=h._path,w=y._parent,b=h.getPointAt(d),_=h.isHorizontal();w instanceof z&&(y=w),c+="subtract"===i&&n&&(y===t&&n._getWinding(b,_)||y===n&&!t._getWinding(b,_))?0:o(b,r,_);break}d-=v}for(var x=Math.round(c/3),E=s.length-1;E>=0;E--)s[E].segment._winding=x}function l(e,t){function n(e,t){if(e._visited)return!1;if(!c)return!0;var n=e._winding,r=e._intersection;return r&&t&&h&&r.isOverlap()&&(n=h[n]||n),c(n)}function r(e){return e===o||e===s}function i(e,t){if(!e._next)return e;for(;e;){var i=e._segment,a=i.getNext(),o=a._intersection;if(r(a)||!i._visited&&!a._visited&&(!c||(!t||n(i))&&(!(t&&o&&o.isOverlap())&&n(a)||!t&&o&&n(o._segment))))return e;e=e._next}return null}function a(e,t){for(;e;){var n=e._segment;if(r(n))return n;e=e[t?"_next":"_prev"]}}for(var o,s,l=[],c=u[t],h={unite:{1:2},intersect:{2:1}}[t],p=0,f=e.length;f>p;p++){var m=e[p],g=null,v=!1;if(n(m,!0)){for(o=s=null;!v;){var y=m._intersection,w=g&&m._handleIn;y=y&&(i(y,!0)||i(y,!1))||y;var b=y&&y._segment;if(b&&n(b)&&(m=b),m._visited){if(v=r(m),!v&&y){var _=a(y,!0)||a(y,!1);_&&(m=_,v=!0)}break}g||(g=new L(C.NO_INSERT),o=m,s=b),g.add(new T(m._point,w,m._handleOut)),m._visited=!0,m=m.getNext(),v=r(m)}v?(g.firstSegment.setHandleIn(m._handleIn),g.setClosed(!0)):g&&(console.error("Boolean operation resulted in open path","segments =",g._segments.length,"length =",g.getLength()),g=null),g&&(g._segments.length>8||!d.isZero(g.getArea()))&&(l.push(g),g=null)}}return l}var u={unite:function(e){return 1===e||0===e},intersect:function(e){return 2===e},subtract:function(e){return 1===e},exclude:function(e){return 1===e}};return{_getWinding:function(e,t,n){return o(e,this._getMonoCurves(),t,n)},unite:function(e){return n(this,e,"unite")},intersect:function(e){return n(this,e,"intersect")},subtract:function(e){return n(this,e,"subtract")},exclude:function(e){return n(this,e,"exclude")},divide:function(e){return t(N,[this.subtract(e),this.intersect(e)],this,e,!0)},resolveCrossings:function(){var e=this.getCrossings();if(!e.length)return this;a(R.expand(e));for(var n=this._children||[this],r=[],i=0,o=n.length;o>i;i++)r.push.apply(r,n[i]._segments);return t(z,l(r),this,null,!1)}}}),L.inject({_getMonoCurves:function(){function e(e){var t=e[1],i=e[7],a={values:e,winding:t===i?0:t>i?-1:1,previous:n,next:null};n&&(n.next=a),r.push(a),n=a}function t(t){if(0!==I.getLength(t)){var n=t[1],r=t[3],i=t[5],a=t[7];if(I.isStraight(t))e(t);else{var o=3*(r-i)-n+a,s=2*(n+i)-4*r,l=r-n,u=4e-7,c=1-u,h=[],p=d.solveQuadratic(o,s,l,h,u,c);if(0===p)e(t);else{h.sort();var f=h[0],m=I.subdivide(t,f);e(m[0]),p>1&&(f=(h[1]-f)/(1-f),m=I.subdivide(m[1],f),e(m[0])),e(m[1])}}}}var n,r=this._monoCurves;if(!r){r=this._monoCurves=[];for(var i=this.getCurves(),a=this._segments,o=0,s=i.length;s>o;o++)t(i[o].getValues());if(!this._closed&&a.length>1){var l=a[a.length-1]._point,u=a[0]._point,c=l._x,h=l._y,p=u._x,f=u._y;t([c,h,c,h,p,f,p,f])}if(r.length>0){var m=r[0],g=r[r.length-1];m.previous=g,g.next=m}}return r},getInteriorPoint:function(){var e=this.getBounds(),t=e.getCenter(!0);if(!this.contains(t)){for(var n=this._getMonoCurves(),r=[],i=t.y,a=[],o=0,s=n.length;s>o;o++){var l=n[o].values;if((1===n[o].winding&&i>=l[1]&&i<=l[7]||i>=l[7]&&i<=l[1])&&I.solveCubic(l,1,i,r,0,1)>0)for(var u=r.length-1;u>=0;u--)a.push(I.getPoint(l,r[u]).x);if(a.length>1)break}t.x=(a[0]+a[1])/2}return t},reorient:function(){return this.setClockwise(!0),this}}),z.inject({_getMonoCurves:function(){for(var e=this._children,t=[],n=0,r=e.length;r>n;n++)t.push.apply(t,e[n]._getMonoCurves());return t},reorient:function(){var e=this.removeChildren().sort(function(e,t){return t.getBounds().getArea()-e.getBounds().getArea()});if(e.length>0){this.addChildren(e);for(var t=e[0].isClockwise(),n=1,r=e.length;r>n;n++){for(var i=e[n].getInteriorPoint(),a=0,o=n-1;o>=0;o--)e[o].contains(i)&&a++;e[n].setClockwise(a%2===0&&t)}}return this}});var V=s.extend({_class:"PathIterator",initialize:function(e,t,n,r){function i(e,t){var n=I.getValues(e,t,r);s.push(n),a(n,e._index,0,1)}function a(e,t,r,i){if(i-r>c&&!I.isFlatEnough(e,n||.25)){var o=I.subdivide(e,.5),s=(r+i)/2;a(o[0],t,r,s),a(o[1],t,s,i)}else{var h=e[6]-e[0],d=e[7]-e[1],p=Math.sqrt(h*h+d*d);p>1e-6&&(u+=p,l.push({offset:u,value:i,index:t}))}}for(var o,s=[],l=[],u=0,c=1/(t||32),h=e._segments,d=h[0],p=1,f=h.length;f>p;p++)o=h[p],i(d,o),d=o;e._closed&&i(o,h[0]),this.curves=s,this.parts=l,this.length=u,this.index=0},getParameterAt:function(e){for(var t,n=this.index;t=n,!(0==n||this.parts[--n].offsett;t++){var i=this.parts[t];if(i.offset>=e){this.index=t;var a=this.parts[t-1],o=a&&a.index==i.index?a.value:0,s=a?a.offset:0;return{value:o+(i.value-o)*(e-s)/(i.offset-s),index:i.index}}}var i=this.parts[this.parts.length-1];return{value:1,index:i.index}},drawPart:function(e,t,n){t=this.getParameterAt(t),n=this.getParameterAt(n);for(var r=t.index;r<=n.index;r++){var i=I.getPart(this.curves[r],r==t.index?t.value:0,r==n.index?n.value:1);r==t.index&&e.moveTo(i[0],i[1]),e.bezierCurveTo.apply(e,i.slice(2))}}},s.each(I.evaluateMethods,function(e){this[e+"At"]=function(t,n){var r=this.getParameterAt(t);return I[e](this.curves[r.index],r.value,n)}},{})),B=s.extend({initialize:function(e,t){for(var n,r=this.points=[],i=e._segments,a=0,o=i.length;o>a;a++){var s=i[a].point.clone();n&&n.equals(s)||(r.push(s),n=s)}e._closed&&(this.closed=!0,r.unshift(r[r.length-1]),r.push(r[1])),this.error=t},fit:function(){var e=this.points,t=e.length,n=this.segments=t>0?[new T(e[0])]:[];return t>1&&this.fitCubic(0,t-1,e[1].subtract(e[0]).normalize(),e[t-2].subtract(e[t-1]).normalize()),this.closed&&(n.shift(),n.pop()),n},fitCubic:function(e,t,n,r){if(t-e==1){var i=this.points[e],a=this.points[t],o=i.getDistance(a)/3;return void this.addCurve([i,i.add(n.normalize(o)),a.add(r.normalize(o)),a])}for(var s,l=this.chordLengthParameterize(e,t),u=Math.max(this.error,this.error*this.error),c=!0,h=0;4>=h;h++){var d=this.generateBezier(e,t,l,n,r),p=this.findMaxError(e,t,d,l);if(p.error=u)break;c=this.reparameterize(e,t,l,d),u=p.error}var f=this.points[s-1].subtract(this.points[s]),m=this.points[s].subtract(this.points[s+1]),g=f.add(m).divide(2).normalize();this.fitCubic(e,s,n,g),this.fitCubic(s,t,g.negate(),r)},addCurve:function(e){var t=this.segments[this.segments.length-1];t.setHandleOut(e[1].subtract(e[0])),this.segments.push(new T(e[3],e[2].subtract(e[3])))},generateBezier:function(e,t,n,r,i){for(var a=1e-12,o=this.points[e],s=this.points[t],l=[[0,0],[0,0]],u=[0,0],c=0,h=t-e+1;h>c;c++){var d=n[c],p=1-d,f=3*d*p,m=p*p*p,g=f*p,v=f*d,y=d*d*d,w=r.normalize(g),b=i.normalize(v),_=this.points[e+c].subtract(o.multiply(m+g)).subtract(s.multiply(v+y));l[0][0]+=w.dot(w),l[0][1]+=w.dot(b),l[1][0]=l[0][1],l[1][1]+=b.dot(b),u[0]+=w.dot(_),u[1]+=b.dot(_)}var x,E,C=l[0][0]*l[1][1]-l[1][0]*l[0][1];if(Math.abs(C)>a){var N=l[0][0]*u[1]-l[1][0]*u[0],k=u[0]*l[1][1]-u[1]*l[0][1];x=k/C,E=N/C}else{var S=l[0][0]+l[0][1],P=l[1][0]+l[1][1];x=E=Math.abs(S)>a?u[0]/S:Math.abs(P)>a?u[1]/P:0}var O,D,T=s.getDistance(o),M=a*T;if(M>x||M>E)x=E=T/3;else{var I=s.subtract(o);O=r.normalize(x),D=i.normalize(E),O.dot(I)-D.dot(I)>T*T&&(x=E=T/3,O=D=null)}return[o,o.add(O||r.normalize(x)),s.add(D||i.normalize(E)),s]},reparameterize:function(e,t,n,r){for(var i=e;t>=i;i++)n[i-e]=this.findRoot(r,this.points[i],n[i-e]);for(var i=1,a=n.length;a>i;i++)if(n[i]<=n[i-1])return!1;return!0},findRoot:function(e,t,n){for(var r=[],i=[],a=0;2>=a;a++)r[a]=e[a+1].subtract(e[a]).multiply(3);for(var a=0;1>=a;a++)i[a]=r[a+1].subtract(r[a]).multiply(2);var o=this.evaluate(3,e,n),s=this.evaluate(2,r,n),l=this.evaluate(1,i,n),u=o.subtract(t),c=s.dot(s)+u.dot(l);return Math.abs(c)<1e-6?n:n-u.dot(s)/c},evaluate:function(e,t,n){for(var r=t.slice(),i=1;e>=i;i++)for(var a=0;e-i>=a;a++)r[a]=r[a].multiply(1-n).add(r[a+1].multiply(n));return r[0]},chordLengthParameterize:function(e,t){for(var n=[0],r=e+1;t>=r;r++)n[r-e]=n[r-e-1]+this.points[r].getDistance(this.points[r-1]);for(var r=1,i=t-e;i>=r;r++)n[r]/=n[i];return n},findMaxError:function(e,t,n,r){for(var i=Math.floor((t-e+1)/2),a=0,o=e+1;t>o;o++){var s=this.evaluate(3,n,r[o-e]),l=s.subtract(this.points[o]),u=l.x*l.x+l.y*l.y;u>=a&&(a=u,i=o)}return{error:a,index:i}}}),j=C.extend({_class:"TextItem",_boundsSelected:!0,_applyMatrix:!1,_canApplyMatrix:!1,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(e){this._content="",this._lines=[];var t=e&&s.isPlainObject(e)&&e.x===o&&e.y===o;this._initialize(t&&e,!t&&f.read(arguments))},_equals:function(e){return this._content===e._content},_clone:function Ne(e,t,n){return e.setContent(this._content),Ne.base.call(this,e,t,n)},getContent:function(){return this._content},setContent:function(e){this._content=""+e,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(265)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),F=j.extend({_class:"PointText",initialize:function(){j.apply(this,arguments)},clone:function(e){return this._clone(new F(C.NO_INSERT),e)},getPoint:function(){var e=this._matrix.getTranslation();return new m(e.x,e.y,this,"setPoint")},setPoint:function(){var e=f.read(arguments);this.translate(e.subtract(this._matrix.getTranslation()))},_draw:function(e){if(this._content){this._setStyles(e);var t=this._style,n=this._lines,r=t.getLeading(),i=e.shadowColor;e.font=t.getFontStyle(),e.textAlign=t.getJustification();for(var a=0,o=n.length;o>a;a++){e.shadowColor=i;var s=n[a];t.hasFill()&&(e.fillText(s,0,0),e.shadowColor="rgba(0,0,0,0)"),t.hasStroke()&&e.strokeText(s,0,0),e.translate(0,r)}}},_getBounds:function(e,t){var n=this._style,r=this._lines,i=r.length,a=n.getJustification(),o=n.getLeading(),s=this.getView().getTextWidth(n.getFontStyle(),r),l=0;"left"!==a&&(l-=s/("center"===a?2:1));var u=new y(l,i?-.75*o:0,s,i*o);return t?t._transformBounds(u,u):u}}),q=s.extend(new function(){function e(e){var n,r=e.match(/^#(\w{1,2})(\w{1,2})(\w{1,2})$/);if(r){n=[0,0,0];for(var a=0;3>a;a++){var o=r[a+1];n[a]=parseInt(1==o.length?o+o:o,16)/255}}else if(r=e.match(/^rgba?\((.*)\)$/)){n=r[1].split(",");for(var a=0,s=n.length;s>a;a++){var o=+n[a];n[a]=3>a?o/255:o}}else{var l=i[e];if(!l){t||(t=ne.getContext(1,1),t.globalCompositeOperation="copy"),t.fillStyle="rgba(0,0,0,0)",t.fillStyle=e,t.fillRect(0,0,1,1);var u=t.getImageData(0,0,1,1).data;l=i[e]=[u[0]/255,u[1]/255,u[2]/255]}n=l.slice()}return n}var t,n={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},r={},i={},a=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],o={"rgb-hsb":function(e,t,n){var r=Math.max(e,t,n),i=Math.min(e,t,n),a=r-i,o=0===a?0:60*(r==e?(t-n)/a+(n>t?6:0):r==t?(n-e)/a+2:(e-t)/a+4); return[o,0===r?0:a/r,r]},"hsb-rgb":function(e,t,n){e=(e/60%6+6)%6;var r=Math.floor(e),i=e-r,r=a[r],o=[n,n*(1-t),n*(1-t*i),n*(1-t*(1-i))];return[o[r[0]],o[r[1]],o[r[2]]]},"rgb-hsl":function(e,t,n){var r=Math.max(e,t,n),i=Math.min(e,t,n),a=r-i,o=0===a,s=o?0:60*(r==e?(t-n)/a+(n>t?6:0):r==t?(n-e)/a+2:(e-t)/a+4),l=(r+i)/2,u=o?0:.5>l?a/(r+i):a/(2-r-i);return[s,u,l]},"hsl-rgb":function(e,t,n){if(e=(e/360%1+1)%1,0===t)return[n,n,n];for(var r=[e+1/3,e,e-1/3],i=.5>n?n*(1+t):n+t-n*t,a=2*n-i,o=[],s=0;3>s;s++){var l=r[s];0>l&&(l+=1),l>1&&(l-=1),o[s]=1>6*l?a+6*(i-a)*l:1>2*l?i:2>3*l?a+(i-a)*(2/3-l)*6:a}return o},"rgb-gray":function(e,t,n){return[.2989*e+.587*t+.114*n]},"gray-rgb":function(e){return[e,e,e]},"gray-hsb":function(e){return[0,0,e]},"gray-hsl":function(e){return[0,0,e]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return s.each(n,function(e,t){r[t]=[],s.each(e,function(e,i){var a=s.capitalize(e),o=/^(hue|saturation)$/.test(e),l=r[t][i]="gradient"===e?function(e){var t=this._components[0];return e=U.read(Array.isArray(e)?e:arguments,0,{readNull:!0}),t!==e&&(t&&t._removeOwner(this),e&&e._addOwner(this)),e}:"gradient"===t?function(){return f.read(arguments,0,{readNull:"highlight"===e,clone:!0})}:function(e){return null==e||isNaN(e)?0:e};this["get"+a]=function(){return this._type===t||o&&/^hs[bl]$/.test(this._type)?this._components[i]:this._convert(t)[i]},this["set"+a]=function(e){this._type===t||o&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(t),this._properties=n[t],this._type=t),this._components[i]=l.call(this,e),this._changed()}},this)},{_class:"Color",_readIndex:!0,initialize:function l(t){var i,a,o,s,u=Array.prototype.slice,c=arguments,h=0;Array.isArray(t)&&(c=t,t=c[0]);var d=null!=t&&typeof t;if("string"===d&&t in n&&(i=t,t=c[1],Array.isArray(t)?(a=t,o=c[2]):(this.__read&&(h=1),c=u.call(c,1),d=typeof t)),!a){if(s="number"===d?c:"object"===d&&null!=t.length?t:null){i||(i=s.length>=3?"rgb":"gray");var f=n[i].length;o=s[f],this.__read&&(h+=s===arguments?f+(null!=o?1:0):1),s.length>f&&(s=u.call(s,0,f))}else if("string"===d)i="rgb",a=e(t),4===a.length&&(o=a[3],a.length--);else if("object"===d)if(t.constructor===l){if(i=t._type,a=t._components.slice(),o=t._alpha,"gradient"===i)for(var m=1,g=a.length;g>m;m++){var v=a[m];v&&(a[m]=v.clone())}}else if(t.constructor===U)i="gradient",s=c;else{i="hue"in t?"lightness"in t?"hsl":"hsb":"gradient"in t||"stops"in t||"radial"in t?"gradient":"gray"in t?"gray":"rgb";var y=n[i],w=r[i];this._components=a=[];for(var m=0,g=y.length;g>m;m++){var b=t[y[m]];null==b&&0===m&&"gradient"===i&&"stops"in t&&(b={stops:t.stops,radial:t.radial}),b=w[m].call(this,b),null!=b&&(a[m]=b)}o=t.alpha}this.__read&&i&&(h=1)}if(this._type=i||"rgb",this._id=p.get(l),!a){this._components=a=[];for(var w=r[this._type],m=0,g=w.length;g>m;m++){var b=w[m].call(this,s&&s[m]);null!=b&&(a[m]=b)}}this._components=a,this._properties=n[this._type],this._alpha=o,this.__read&&(this.__read=h)},_serialize:function(e,t){var n=this.getComponents();return s.serialize(/^(gray|rgb)$/.test(this._type)?n:[this._type].concat(n),e,!0,t)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(65)},_convert:function(e){var t;return this._type===e?this._components.slice():(t=o[this._type+"-"+e])?t.apply(this,this._components):o["rgb-"+e].apply(this,o[this._type+"-rgb"].apply(this,this._components))},convert:function(e){return new q(e,this._convert(e),this._alpha)},getType:function(){return this._type},setType:function(e){this._components=this._convert(e),this._properties=n[e],this._type=e},getComponents:function(){var e=this._components.slice();return null!=this._alpha&&e.push(this._alpha),e},getAlpha:function(){return null!=this._alpha?this._alpha:1},setAlpha:function(e){this._alpha=null==e?null:Math.min(Math.max(e,0),1),this._changed()},hasAlpha:function(){return null!=this._alpha},equals:function(e){var t=s.isPlainValue(e,!0)?q.read(arguments):e;return t===this||t&&this._class===t._class&&this._type===t._type&&this._alpha===t._alpha&&s.equals(this._components,t._components)||!1},toString:function(){for(var e=this._properties,t=[],n="gradient"===this._type,r=h.instance,i=0,a=e.length;a>i;i++){var o=this._components[i];null!=o&&t.push(e[i]+": "+(n?o:r.number(o)))}return null!=this._alpha&&t.push("alpha: "+r.number(this._alpha)),"{ "+t.join(", ")+" }"},toCSS:function(e){function t(e){return Math.round(255*(0>e?0:e>1?1:e))}var n=this._convert("rgb"),r=e||null==this._alpha?1:this._alpha;return n=[t(n[0]),t(n[1]),t(n[2])],1>r&&n.push(0>r?0:r),e?"#"+((1<<24)+(n[0]<<16)+(n[1]<<8)+n[2]).toString(16).slice(1):(4==n.length?"rgba(":"rgb(")+n.join(",")+")"},toCanvasStyle:function(e){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var t,n=this._components,r=n[0],i=r._stops,a=n[1],o=n[2];if(r._radial){var s=o.getDistance(a),l=n[3];if(l){var u=l.subtract(a);u.getLength()>s&&(l=a.add(u.normalize(s-.1)))}var c=l||a;t=e.createRadialGradient(c.x,c.y,0,a.x,a.y,s)}else t=e.createLinearGradient(a.x,a.y,o.x,o.y);for(var h=0,d=i.length;d>h;h++){var p=i[h];t.addColorStop(p._rampPoint,p._color.toCanvasStyle())}return this._canvasStyle=t},transform:function(e){if("gradient"===this._type){for(var t=this._components,n=1,r=t.length;r>n;n++){var i=t[n];e._transformPoint(i,i,!0)}this._changed()}},statics:{_types:n,random:function(){var e=Math.random;return new q(e(),e(),e())}}})},new function(){var e={add:function(e,t){return e+t},subtract:function(e,t){return e-t},multiply:function(e,t){return e*t},divide:function(e,t){return e/t}};return s.each(e,function(e,t){this[t]=function(t){t=q.read(arguments);for(var n=this._type,r=this._components,i=t._convert(n),a=0,o=r.length;o>a;a++)i[a]=e(r[a],i[a]);return new q(n,i,null!=this._alpha?e(this._alpha,t.getAlpha()):null)}},{})}),U=s.extend({_class:"Gradient",initialize:function(e,t){this._id=p.get(),e&&this._set(e)&&(e=t=null),this._stops||this.setStops(e||["white","black"]),null==this._radial&&this.setRadial("string"==typeof t&&"radial"===t||t||!1)},_serialize:function(e,t){return t.add(this,function(){return s.serialize([this._stops,this._radial],e,!0,t)})},_changed:function(){for(var e=0,t=this._owners&&this._owners.length;t>e;e++)this._owners[e]._changed()},_addOwner:function(e){this._owners||(this._owners=[]),this._owners.push(e)},_removeOwner:function(e){var t=this._owners?this._owners.indexOf(e):-1;-1!=t&&(this._owners.splice(t,1),0===this._owners.length&&(this._owners=o))},clone:function(){for(var e=[],t=0,n=this._stops.length;n>t;t++)e[t]=this._stops[t].clone();return new U(e,this._radial)},getStops:function(){return this._stops},setStops:function(e){if(this.stops)for(var t=0,n=this._stops.length;n>t;t++)this._stops[t]._owner=o;if(e.length<2)throw new Error("Gradient stop list needs to contain at least two stops.");this._stops=W.readAll(e,0,{clone:!0});for(var t=0,n=this._stops.length;n>t;t++){var r=this._stops[t];r._owner=this,r._defaultRamp&&r.setRampPoint(t/(n-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(e){this._radial=e,this._changed()},equals:function(e){if(e===this)return!0;if(e&&this._class===e._class&&this._stops.length===e._stops.length){for(var t=0,n=this._stops.length;n>t;t++)if(!this._stops[t].equals(e._stops[t]))return!1;return!0}return!1}}),W=s.extend({_class:"GradientStop",initialize:function(e,t){if(e){var n,r;t===o&&Array.isArray(e)?(n=e[0],r=e[1]):e.color?(n=e.color,r=e.rampPoint):(n=e,r=t),this.setColor(n),this.setRampPoint(r)}},clone:function(){return new W(this._color.clone(),this._rampPoint)},_serialize:function(e,t){return s.serialize([this._color,this._rampPoint],e,!0,t)},_changed:function(){this._owner&&this._owner._changed(65)},getRampPoint:function(){return this._rampPoint},setRampPoint:function(e){this._defaultRamp=null==e,this._rampPoint=e||0,this._changed()},getColor:function(){return this._color},setColor:function(e){this._color=q.read(arguments),this._color===e&&(this._color=e.clone()),this._color._owner=this,this._changed()},equals:function(e){return e===this||e&&this._class===e._class&&this._color.equals(e._color)&&this._rampPoint==e._rampPoint||!1}}),G=s.extend(new function(){var e={fillColor:o,strokeColor:o,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",strokeScaling:!0,miterLimit:10,dashOffset:0,dashArray:[],windingRule:"nonzero",shadowColor:o,shadowBlur:0,shadowOffset:new f,selectedColor:o,fontFamily:"sans-serif",fontWeight:"normal",fontSize:12,font:"sans-serif",leading:null,justification:"left"},t={strokeWidth:97,strokeCap:97,strokeJoin:97,strokeScaling:105,miterLimit:97,fontFamily:9,fontWeight:9,fontSize:9,font:9,leading:9,justification:9},n={beans:!0},r={_defaults:e,_textDefaults:new s(e,{fillColor:new q}),beans:!0};return s.each(e,function(e,i){var a=/Color$/.test(i),l="shadowOffset"===i,u=s.capitalize(i),c=t[i],h="set"+u,d="get"+u;r[h]=function(e){var t=this._owner,n=t&&t._children;if(n&&n.length>0&&!(t instanceof z))for(var r=0,s=n.length;s>r;r++)n[r]._style[h](e);else{var l=this._values[i];l!==e&&(a&&(l&&(l._owner=o),e&&e.constructor===q&&(e._owner&&(e=e.clone()),e._owner=t)),this._values[i]=e,t&&t._changed(c||65))}},r[d]=function(e){var t,n=this._owner,r=n&&n._children;if(!r||0===r.length||e||n instanceof z){var t=this._values[i];if(t===o)t=this._defaults[i],t&&t.clone&&(t=t.clone());else{var u=a?q:l?f:null;!u||t&&t.constructor===u||(this._values[i]=t=u.read([t],0,{readNull:!0,clone:!0}),t&&a&&(t._owner=n))}return t}for(var c=0,h=r.length;h>c;c++){var p=r[c]._style[d]();if(0===c)t=p;else if(!s.equals(t,p))return o}return t},n[d]=function(e){return this._style[d](e)},n[h]=function(e){this._style[h](e)}}),C.inject(n),r},{_class:"Style",initialize:function(e,t,n){this._values={},this._owner=t,this._project=t&&t._project||n||a.project,t instanceof j&&(this._defaults=this._textDefaults),e&&this.set(e)},set:function(e){var t=e instanceof G,n=t?e._values:e;if(n)for(var r in n)if(r in this._defaults){var i=n[r];this[r]=i&&t&&i.clone?i.clone():i}},equals:function(e){return e===this||e&&this._class===e._class&&s.equals(this._values,e._values)||!1},hasFill:function(){return!!this.getFillColor()},hasStroke:function(){return!!this.getStrokeColor()&&this.getStrokeWidth()>0},hasShadow:function(){return!!this.getShadowColor()&&this.getShadowBlur()>0},getView:function(){return this._project.getView()},getFontStyle:function(){var e=this.getFontSize();return this.getFontWeight()+" "+e+(/[a-z]/i.test(e+"")?" ":"px ")+this.getFontFamily()},getFont:"#getFontFamily",setFont:"#setFontFamily",getLeading:function ke(){var e=ke.base.call(this),t=this.getFontSize();return/pt|em|%|px/.test(t)&&(t=this.getView().getPixelSize(t)),null!=e?e:1.2*t}}),H=new function(){function e(e,t,n,r){for(var i=["","webkit","moz","Moz","ms","o"],a=t[0].toUpperCase()+t.substring(1),o=0;6>o;o++){var s=i[o],l=s?s+a:t;if(l in e){if(!n)return e[l];e[l]=r;break}}}return{getStyles:function(e){var t=e&&9!==e.nodeType?e.ownerDocument:e,n=t&&t.defaultView;return n&&n.getComputedStyle(e,"")},getBounds:function(e,t){var n,r=e.ownerDocument,i=r.body,a=r.documentElement;try{n=e.getBoundingClientRect()}catch(o){n={left:0,top:0,width:0,height:0}}var s=n.left-(a.clientLeft||i.clientLeft||0),l=n.top-(a.clientTop||i.clientTop||0);if(!t){var u=r.defaultView;s+=u.pageXOffset||a.scrollLeft||i.scrollLeft,l+=u.pageYOffset||a.scrollTop||i.scrollTop}return new y(s,l,n.width,n.height)},getViewportBounds:function(e){var t=e.ownerDocument,n=t.defaultView,r=t.documentElement;return new y(0,0,n.innerWidth||r.clientWidth,n.innerHeight||r.clientHeight)},getOffset:function(e,t){return H.getBounds(e,t).getPoint()},getSize:function(e){return H.getBounds(e,!0).getSize()},isInvisible:function(e){return H.getSize(e).equals(new g(0,0))},isInView:function(e){return!H.isInvisible(e)&&H.getViewportBounds(e).intersects(H.getBounds(e,!0))},getPrefixed:function(t,n){return e(t,n)},setPrefixed:function(t,n,r){if("object"==typeof n)for(var i in n)e(t,i,!0,n[i]);else e(t,n,!0,r)}}},X={add:function(e,t){for(var n in t)for(var r=t[n],i=n.split(/[\s,]+/g),a=0,o=i.length;o>a;a++)e.addEventListener(i[a],r,!1)},remove:function(e,t){for(var n in t)for(var r=t[n],i=n.split(/[\s,]+/g),a=0,o=i.length;o>a;a++)e.removeEventListener(i[a],r,!1)},getPoint:function(e){var t=e.targetTouches?e.targetTouches.length?e.targetTouches[0]:e.changedTouches[0]:e;return new f(t.pageX||t.clientX+document.documentElement.scrollLeft,t.pageY||t.clientY+document.documentElement.scrollTop)},getTarget:function(e){return e.target||e.srcElement},getRelatedTarget:function(e){return e.relatedTarget||e.toElement},getOffset:function(e,t){return X.getPoint(e).subtract(H.getOffset(t||X.getTarget(e)))},stop:function(e){e.stopPropagation(),e.preventDefault()}};X.requestAnimationFrame=new function(){function e(){for(var t=i.length-1;t>=0;t--){var o=i[t],s=o[0],l=o[1];(!l||("true"==u.getAttribute(l,"keepalive")||a)&&H.isInView(l))&&(i.splice(t,1),s())}n&&(i.length?n(e):r=!1)}var t,n=H.getPrefixed(window,"requestAnimationFrame"),r=!1,i=[],a=!0;return X.add(window,{focus:function(){a=!0},blur:function(){a=!1}}),function(a,o){i.push([a,o]),n?r||(n(e),r=!0):t||(t=setInterval(e,1e3/60))}};var K=s.extend(l,{_class:"View",initialize:function Se(e,t){function n(e){return t[e]||parseInt(t.getAttribute(e),10)}function r(){var e=H.getSize(t);return e.isNaN()||e.isZero()?new g(n("width"),n("height")):e}this._project=e,this._scope=e._scope,this._element=t;var i;this._pixelRatio||(this._pixelRatio=window.devicePixelRatio||1),this._id=t.getAttribute("id"),null==this._id&&t.setAttribute("id",this._id="view-"+Se._id++),X.add(t,this._viewEvents);var a="none";if(H.setPrefixed(t.style,{userSelect:a,touchAction:a,touchCallout:a,contentZooming:a,userDrag:a,tapHighlightColor:"rgba(0,0,0,0)"}),u.hasAttribute(t,"resize")){var o=this;X.add(window,this._windowEvents={resize:function(){o.setViewSize(r())}})}if(this._setViewSize(i=r()),u.hasAttribute(t,"stats")&&"undefined"!=typeof Stats){this._stats=new Stats;var s=this._stats.domElement,l=s.style,c=H.getOffset(t);l.position="absolute",l.left=c.x+"px",l.top=c.y+"px",document.body.appendChild(s)}Se._views.push(this),Se._viewsById[this._id]=this,this._viewSize=i,(this._matrix=new b)._owner=this,this._zoom=1,Se._focused||(Se._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return this._project?(K._focused===this&&(K._focused=null),K._views.splice(K._views.indexOf(this),1),delete K._viewsById[this._id],this._project._view===this&&(this._project._view=null),X.remove(this._element,this._viewEvents),X.remove(window,this._windowEvents),this._element=this._project=null,this.off("frame"),this._animate=!1,this._frameItems={},!0):!1},_events:s.each(["onResize","onMouseDown","onMouseUp","onMouseMove"],function(e){this[e]={install:function(e){this._installEvent(e)},uninstall:function(e){this._uninstallEvent(e)}}},{onFrame:{install:function(){this.play()},uninstall:function(){this.pause()}}}),_animate:!1,_time:0,_count:0,_requestFrame:function(){var e=this;X.requestAnimationFrame(function(){e._requested=!1,e._animate&&(e._requestFrame(),e._handleFrame())},this._element),this._requested=!0},_handleFrame:function(){a=this._scope;var e=Date.now()/1e3,t=this._before?e-this._before:0;this._before=e,this._handlingFrame=!0,this.emit("frame",new s({delta:t,time:this._time+=t,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.update()},_animateItem:function(e,t){var n=this._frameItems;t?(n[e._id]={item:e,time:0,count:0},1===++this._frameItemCount&&this.on("frame",this._handleFrameItems)):(delete n[e._id],0===--this._frameItemCount&&this.off("frame",this._handleFrameItems))},_handleFrameItems:function(e){for(var t in this._frameItems){var n=this._frameItems[t];n.item.emit("frame",new s(e,{time:n.time+=e.delta,count:n.count++}))}},_update:function(){this._project._needsUpdate=!0,this._handlingFrame||(this._animate?this._handleFrame():this.update())},_changed:function(e){1&e&&(this._project._needsUpdate=!0)},_transform:function(e){this._matrix.concatenate(e),this._bounds=null,this._update()},getElement:function(){return this._element},getPixelRatio:function(){return this._pixelRatio},getResolution:function(){return 72*this._pixelRatio},getViewSize:function(){var e=this._viewSize;return new v(e.width,e.height,this,"setViewSize")},setViewSize:function(){var e=g.read(arguments),t=e.subtract(this._viewSize);t.isZero()||(this._viewSize.set(e.width,e.height),this._setViewSize(e),this._bounds=null,this.emit("resize",{size:e,delta:t}),this._update())},_setViewSize:function(e){var t=this._element;t.width=e.width,t.height=e.height},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new y(new f,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize()},getCenter:function(){return this.getBounds().getCenter()},setCenter:function(){var e=f.read(arguments);this.scrollBy(e.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(e){this._transform((new b).scale(e/this._zoom,this.getCenter())),this._zoom=e},isVisible:function(){return H.isInView(this._element)},scrollBy:function(){this._transform((new b).translate(f.read(arguments).negate()))},play:function(){this._animate=!0,this._requested||this._requestFrame()},pause:function(){this._animate=!1},draw:function(){this.update()},projectToView:function(){return this._matrix._transformPoint(f.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(f.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(e,t){return"string"==typeof t&&(t=document.getElementById(t)),new Y(e,t)}}},new function(){function e(e){var t=X.getTarget(e);return t.getAttribute&&K._viewsById[t.getAttribute("id")]}function t(e,t){return e.viewToProject(X.getOffset(t,e._element))}function n(){if(!K._focused||!K._focused.isVisible())for(var e=0,t=K._views.length;t>e;e++){var n=K._views[e];if(n&&n.isVisible()){K._focused=o=n;break}}}function r(e,t,n){e._handleEvent("mousemove",t,n);var r=e._scope.tool;return r&&r._handleEvent(c&&r.responds("mousedrag")?"mousedrag":"mousemove",t,n),e.update(),r}var i,a,o,s,l,u,c=!1,h=window.navigator;h.pointerEnabled||h.msPointerEnabled?(s="pointerdown MSPointerDown",l="pointermove MSPointerMove",u="pointerup pointercancel MSPointerUp MSPointerCancel"):(s="touchstart",l="touchmove",u="touchend touchcancel","ontouchstart"in window&&h.userAgent.match(/mobile|tablet|ip(ad|hone|od)|android|silk/i)||(s+=" mousedown",l+=" mousemove",u+=" mouseup"));var d={"selectstart dragstart":function(e){c&&e.preventDefault()}},p={mouseout:function(e){var n=K._focused,i=X.getRelatedTarget(e);!n||i&&"HTML"!==i.nodeName||r(n,t(n,e),e)},scroll:n};d[s]=function(n){var r=K._focused=e(n),a=t(r,n);c=!0,r._handleEvent("mousedown",a,n),(i=r._scope.tool)&&i._handleEvent("mousedown",a,n),r.update()},p[l]=function(s){var l=K._focused;if(!c){var u=e(s);u?(l!==u&&r(l,t(l,s),s),a=l,l=K._focused=o=u):o&&o===l&&(l=K._focused=a,n())}if(l){var h=t(l,s);(c||l.getBounds().contains(h))&&(i=r(l,h,s))}},p[u]=function(e){var n=K._focused;if(n&&c){var r=t(n,e);c=!1,n._handleEvent("mouseup",r,e),i&&i._handleEvent("mouseup",r,e),n.update()}},X.add(document,p),X.add(window,{load:n});var f={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}};return{_viewEvents:d,_handleEvent:function(){},_installEvent:function(e){var t=this._eventCounters;if(t)for(var n in f)t[n]=(t[n]||0)+(f[n][e]||0)},_uninstallEvent:function(e){var t=this._eventCounters;if(t)for(var n in f)t[n]-=f[n][e]||0},statics:{updateFocus:n}}}),Y=K.extend({_class:"CanvasView",initialize:function(e,t){if(!(t instanceof HTMLCanvasElement)){var n=g.read(arguments,1);if(n.isZero())throw new Error("Cannot create CanvasView with the provided argument: "+[].slice.call(arguments,1));t=ne.getCanvas(n)}if(this._context=t.getContext("2d"),this._eventCounters={},this._pixelRatio=1,!/^off|false$/.test(u.getAttribute(t,"hidpi"))){var r=window.devicePixelRatio||1,i=H.getPrefixed(this._context,"backingStorePixelRatio")||1;this._pixelRatio=r/i}K.call(this,e,t)},_setViewSize:function(e){var t=this._element,n=this._pixelRatio,r=e.width,i=e.height;if(t.width=r*n,t.height=i*n,1!==n){if(!u.hasAttribute(t,"resize")){var a=t.style;a.width=r+"px",a.height=i+"px"}this._context.scale(n,n)}},getPixelSize:function(e){var t,n=a.browser;if(n&&n.firefox){var r=this._element.parentNode,i=document.createElement("div");i.style.fontSize=e,r.appendChild(i),t=parseFloat(H.getStyles(i).fontSize),r.removeChild(i)}else{var o=this._context,s=o.font;o.font=e+" serif",t=parseFloat(o.font),o.font=s}return t},getTextWidth:function(e,t){var n=this._context,r=n.font,i=0;n.font=e;for(var a=0,o=t.length;o>a;a++)i=Math.max(i,n.measureText(t[a]).width);return n.font=r,i},update:function(e){var t=this._project;if(!t||!e&&!t._needsUpdate)return!1;var n=this._context,r=this._viewSize;return n.clearRect(0,0,r.width+1,r.height+1),t.draw(n,this._matrix,this._pixelRatio),t._needsUpdate=!1,!0}},new function(){function e(e,t,n,r,i,a){function o(e){return e.responds(t)&&(s||(s=new $(t,n,r,i,a?r.subtract(a):null)),e.emit(t,s)&&s.isStopped)?(n.preventDefault(),!0):void 0}for(var s,l=i;l;){if(o(l))return!0;l=l.getParent()}return o(e)?!0:!1}var t,n,r,i,a,o,s,l,u;return{_handleEvent:function(c,h,d){if(this._eventCounters[c]){var p=this._project,f=p.hitTest(h,{tolerance:0,fill:!0,stroke:!0}),m=f&&f.item,g=!1;switch(c){case"mousedown":for(g=e(this,c,d,h,m),l=a==m&&Date.now()-u<300,i=a=m,t=n=r=h,s=!g&&m;s&&!s.responds("mousedrag");)s=s._parent;break;case"mouseup":g=e(this,c,d,h,m,t),s&&(n&&!n.equals(h)&&e(this,"mousedrag",d,h,s,n),m!==s&&(r=h,e(this,"mousemove",d,h,m,r))),!g&&m&&m===i&&(u=Date.now(),e(this,l&&i.responds("doubleclick")?"doubleclick":"click",d,t,m),l=!1),i=s=null;break;case"mousemove":s&&(g=e(this,"mousedrag",d,h,s,n)),g||(m!==o&&(r=h),g=e(this,c,d,h,m,r)),n=r=h,m!==o&&(e(this,"mouseleave",d,h,o),o=m,e(this,"mouseenter",d,h,m))}return g}}}}),Q=s.extend({_class:"Event",initialize:function(e){this.event=e},isPrevented:!1,isStopped:!1,preventDefault:function(){this.isPrevented=!0,this.event.preventDefault()},stopPropagation:function(){this.isStopped=!0,this.event.stopPropagation()},stop:function(){this.stopPropagation(),this.preventDefault()},getModifiers:function(){return J.modifiers}}),Z=Q.extend({_class:"KeyEvent",initialize:function(e,t,n,r){Q.call(this,r),this.type=e?"keydown":"keyup",this.key=t,this.character=n},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),J=new function(){function e(n,i,c,h){var d,p=c?String.fromCharCode(c):"",f=r[i],m=f||p.toLowerCase(),g=n?"keydown":"keyup",v=K._focused,y=v&&v.isVisible()&&v._scope,w=y&&y.tool;if(u[m]=n,n?l[i]=c:delete l[i],f&&(d=s.camelize(f))in o){o[d]=n;var b=a.browser;if("command"===d&&b&&b.mac)if(n)t={};else{for(var _ in t)_ in l&&e(!1,_,t[_],h);t=null}}else n&&t&&(t[i]=c);w&&w.responds(g)&&(a=y,w.emit(g,new Z(n,m,p,h)),v&&v.update())}var t,n,r={8:"backspace",9:"tab",13:"enter",16:"shift",17:"control",18:"option",19:"pause",20:"caps-lock",27:"escape",32:"space",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete",91:"command",93:"command",224:"command"},i={9:!0,13:!0,32:!0},o=new s({shift:!1,control:!1,option:!1,command:!1,capsLock:!1,space:!1}),l={},u={};return X.add(document,{keydown:function(t){var a=t.which||t.keyCode;a in r||o.command?e(!0,a,a in i||o.command?a:0,t):n=a},keypress:function(t){null!=n&&(e(!0,n,t.which||t.keyCode,t),n=null)},keyup:function(t){var n=t.which||t.keyCode;n in l&&e(!1,n,l[n],t)}}),X.add(window,{blur:function(t){for(var n in l)e(!1,n,l[n],t)}}),{modifiers:o,isDown:function(e){return!!u[e]}}},$=Q.extend({_class:"MouseEvent",initialize:function(e,t,n,r,i){Q.call(this,t),this.type=e,this.point=n,this.target=r,this.delta=i},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}}),ee=Q.extend({_class:"ToolEvent",_item:null,initialize:function(e,t,n){this.tool=e,this.type=t,this.event=n},_choosePoint:function(e,t){return e?e:t?t.clone():null},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(e){this._point=e},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(e){this._lastPoint=e},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(e){this._downPoint=e},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this._middlePoint},setMiddlePoint:function(e){this._middlePoint=e},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(e){this._delta=e},getCount:function(){return/^mouse(down|up)$/.test(this.type)?this.tool._downCount:this.tool._count},setCount:function(e){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=e},getItem:function(){if(!this._item){var e=this.tool._scope.project.hitTest(this.getPoint());if(e){for(var t=e.item,n=t._parent;/^(Group|CompoundPath)$/.test(n._class);)t=n,n=n._parent;this._item=t}}return this._item},setItem:function(e){this._item=e},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),te=(c.extend({_class:"Tool",_list:"tools",_reference:"tool",_events:["onActivate","onDeactivate","onEditOptions","onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onKeyDown","onKeyUp"],initialize:function(e){c.call(this),this._firstMove=!0,this._count=0,this._downCount=0,this._set(e)},getMinDistance:function(){return this._minDistance},setMinDistance:function(e){this._minDistance=e,null!=e&&null!=this._maxDistance&&e>this._maxDistance&&(this._maxDistance=e)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(e){this._maxDistance=e,null!=this._minDistance&&null!=e&&eu)return!1;if(null!=r&&0!=r)if(u>r)t=this._point.add(l.normalize(r));else if(o)return!1}if(a&&t.equals(this._point))return!1}switch(this._lastPoint=i&&"mousemove"==e?t:this._point,this._point=t,e){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=i?0:this._count+1,!0},_fireEvent:function(e,t){var n=a.project._removeSets;if(n){"mouseup"===e&&(n.mousedrag=null);var r=n[e];if(r){for(var i in r){var o=r[i];for(var s in n){var l=n[s];l&&l!=r&&delete l[o._id]}o.remove()}n[e]=null}}return this.responds(e)&&this.emit(e,new ee(this,e,t))},_handleEvent:function(e,t,n){a=this._scope;var r=!1;switch(e){case"mousedown":this._updateEvent(e,t,null,null,!0,!1,!1),r=this._fireEvent(e,n);break;case"mousedrag":for(var i=!1,o=!1;this._updateEvent(e,t,this.minDistance,this.maxDistance,!1,i,o);)r=this._fireEvent(e,n)||r,i=!0,o=!0;break;case"mouseup":!t.equals(this._point)&&this._updateEvent("mousedrag",t,this.minDistance,this.maxDistance,!1,!1,!1)&&(r=this._fireEvent("mousedrag",n)),this._updateEvent(e,t,null,this.maxDistance,!1,!1,!1),r=this._fireEvent(e,n)||r,this._updateEvent(e,t,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(e,t,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)r=this._fireEvent(e,n)||r,this._firstMove=!1}return r&&n.preventDefault(),r}}),{request:function(e,t,n,r){r=r===o?!0:r;var i=new(window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");return i.open(e.toUpperCase(),t,r),"overrideMimeType"in i&&i.overrideMimeType("text/plain"),i.onreadystatechange=function(){if(4===i.readyState){var e=i.status;if(0!==e&&200!==e)throw new Error("Could not load "+t+" (Error "+e+")");n.call(i,i.responseText)}},i.send(null)}}),ne={canvases:[],getCanvas:function(e,t){var n,r=!0;"object"==typeof e&&(t=e.height,e=e.width),n=this.canvases.length?this.canvases.pop():document.createElement("canvas");var i=n.getContext("2d");return n.width===e&&n.height===t?r&&i.clearRect(0,0,e+1,t+1):(n.width=e,n.height=t),i.save(),n},getContext:function(e,t){return this.getCanvas(e,t).getContext("2d")},release:function(e){var t=e.canvas?e.canvas:e;t.getContext("2d").restore(),this.canvases.push(t)}},re=new function(){function e(e,t,n){return.2989*e+.587*t+.114*n}function t(t,n,r,i){var a=i-e(t,n,r);p=t+a,f=n+a,m=r+a;var i=e(p,f,m),o=g(p,f,m),s=v(p,f,m);if(0>o){var l=i-o;p=i+(p-i)*i/l,f=i+(f-i)*i/l,m=i+(m-i)*i/l}if(s>255){var u=255-i,c=s-i;p=i+(p-i)*u/c,f=i+(f-i)*u/c,m=i+(m-i)*u/c}}function n(e,t,n){return v(e,t,n)-g(e,t,n)}function r(e,t,n,r){var i,a=[e,t,n],o=v(e,t,n),s=g(e,t,n);s=s===e?0:s===t?1:2,o=o===e?0:o===t?1:2,i=0===g(s,o)?1===v(s,o)?2:1:0,a[o]>a[s]?(a[i]=(a[i]-a[s])*r/(a[o]-a[s]),a[o]=r):a[i]=a[o]=0,a[s]=0,p=a[0],f=a[1],m=a[2]}var i,a,o,l,u,c,h,d,p,f,m,g=Math.min,v=Math.max,y=Math.abs,w={multiply:function(){p=u*i/255,f=c*a/255,m=h*o/255},screen:function(){p=u+i-u*i/255,f=c+a-c*a/255,m=h+o-h*o/255},overlay:function(){p=128>u?2*u*i/255:255-2*(255-u)*(255-i)/255,f=128>c?2*c*a/255:255-2*(255-c)*(255-a)/255,m=128>h?2*h*o/255:255-2*(255-h)*(255-o)/255},"soft-light":function(){var e=i*u/255;p=e+u*(255-(255-u)*(255-i)/255-e)/255,e=a*c/255,f=e+c*(255-(255-c)*(255-a)/255-e)/255,e=o*h/255,m=e+h*(255-(255-h)*(255-o)/255-e)/255},"hard-light":function(){p=128>i?2*i*u/255:255-2*(255-i)*(255-u)/255,f=128>a?2*a*c/255:255-2*(255-a)*(255-c)/255,m=128>o?2*o*h/255:255-2*(255-o)*(255-h)/255},"color-dodge":function(){p=0===u?0:255===i?255:g(255,255*u/(255-i)),f=0===c?0:255===a?255:g(255,255*c/(255-a)),m=0===h?0:255===o?255:g(255,255*h/(255-o))},"color-burn":function(){p=255===u?255:0===i?0:v(0,255-255*(255-u)/i),f=255===c?255:0===a?0:v(0,255-255*(255-c)/a),m=255===h?255:0===o?0:v(0,255-255*(255-h)/o)},darken:function(){p=i>u?u:i,f=a>c?c:a,m=o>h?h:o},lighten:function(){p=u>i?u:i,f=c>a?c:a,m=h>o?h:o},difference:function(){p=u-i,0>p&&(p=-p),f=c-a,0>f&&(f=-f),m=h-o,0>m&&(m=-m)},exclusion:function(){p=u+i*(255-u-u)/255,f=c+a*(255-c-c)/255,m=h+o*(255-h-h)/255},hue:function(){r(i,a,o,n(u,c,h)),t(p,f,m,e(u,c,h))},saturation:function(){r(u,c,h,n(i,a,o)),t(p,f,m,e(u,c,h))},luminosity:function(){t(u,c,h,e(i,a,o))},color:function(){t(i,a,o,e(u,c,h))},add:function(){p=g(u+i,255),f=g(c+a,255),m=g(h+o,255)},subtract:function(){p=v(u-i,0),f=v(c-a,0),m=v(h-o,0)},average:function(){p=(u+i)/2,f=(c+a)/2,m=(h+o)/2},negation:function(){p=255-y(255-i-u),f=255-y(255-a-c),m=255-y(255-o-h)}},b=this.nativeModes=s.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(e){this[e]=!0},{}),_=ne.getContext(1,1);s.each(w,function(e,t){var n="darken"===t,r=!1;_.save();try{_.fillStyle=n?"#300":"#a00",_.fillRect(0,0,1,1),_.globalCompositeOperation=t,_.globalCompositeOperation===t&&(_.fillStyle=n?"#a00":"#300",_.fillRect(0,0,1,1),r=_.getImageData(0,0,1,1).data[0]!==n?170:51)}catch(i){}_.restore(),b[t]=r}),ne.release(_),this.process=function(e,t,n,r,s){var g=t.canvas,v="normal"===e;if(v||b[e])n.save(),n.setTransform(1,0,0,1,0,0),n.globalAlpha=r,v||(n.globalCompositeOperation=e),n.drawImage(g,s.x,s.y),n.restore();else{var y=w[e];if(!y)return;for(var _=n.getImageData(s.x,s.y,g.width,g.height),x=_.data,E=t.getImageData(0,0,g.width,g.height).data,C=0,N=x.length;N>C;C+=4){ -i=E[C],u=x[C],a=E[C+1],c=x[C+1],o=E[C+2],h=x[C+2],l=E[C+3],d=x[C+3],y();var k=l*r/255,S=1-k;x[C]=k*p+S*u,x[C+1]=k*f+S*c,x[C+2]=k*m+S*h,x[C+3]=l*r+S*d}n.putImageData(_,s.x,s.y)}}},ie=s.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],strokeScaling:["vector-effect","lookup",{"true":"none","false":"non-scaling-stroke"},function(e,t){return!t&&(e instanceof A||e instanceof S||e instanceof j)}],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],fontFamily:["font-family","string"],fontWeight:["font-weight","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(e,t){var n=s.capitalize(t),r=e[2];this[t]={type:e[1],property:t,attribute:e[0],toSVG:r,fromSVG:r&&s.each(r,function(e,t){this[e]=t},{}),exportFilter:e[3],get:"get"+n,set:"set"+n}},{}),ae={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function e(e,t){for(var n in t){var r=t[n],i=ae[n];"number"==typeof r&&(r=b.number(r)),i?e.setAttributeNS(i,n,r):e.setAttribute(n,r)}return e}function t(t,n){return e(document.createElementNS("http://www.w3.org/2000/svg",t),n)}function n(e,t,n){var r=new s,i=e.getTranslation();if(t){e=e.shiftless();var a=e._inverseTransform(i);r[n?"cx":"x"]=a.x,r[n?"cy":"y"]=a.y,i=null}if(!e.isIdentity()){var o=e.decompose();if(o&&!o.shearing){var l=[],u=o.rotation,c=o.scaling;i&&!i.isZero()&&l.push("translate("+b.point(i)+")"),d.isZero(c.x-1)&&d.isZero(c.y-1)||l.push("scale("+b.point(c)+")"),u&&l.push("rotate("+b.number(u)+")"),r.transform=l.join(" ")}else r.transform="matrix("+e.getValues().join(",")+")"}return r}function r(r,i){for(var a=n(r._matrix),o=r._children,s=t("g",a),l=0,u=o.length;u>l;l++){var c=o[l],h=y(c,i);if(h)if(c.isClipMask()){var d=t("clipPath");d.appendChild(h),g(c,d,"clip"),e(s,{"clip-path":"url(#"+d.id+")"})}else s.appendChild(h)}return s}function i(e,r){var i=n(e._matrix,!0),a=e.getSize(),o=e.getImage();return i.x-=a.width/2,i.y-=a.height/2,i.width=a.width,i.height=a.height,i.href=r.embedImages===!1&&o&&o.src||e.toDataURL(),t("image",i)}function a(e,r){var i=r.matchShapes;if(i){var a=e.toShape(!1);if(a)return o(a,r)}var s,l=e._segments,u=n(e._matrix);if(0===l.length)return null;if(i&&!e.hasHandles())if(l.length>=3){s=e._closed?"polygon":"polyline";for(var c=[],h=0,d=l.length;d>h;h++)c.push(b.point(l[h]._point));u.points=c.join(" ")}else{s="line";var p=l[0]._point,f=l[l.length-1]._point;u.set({x1:p.x,y1:p.y,x2:f.x,y2:f.y})}else s="path",u.d=e.getPathData(null,r.precision);return t(s,u)}function o(e){var r=e._type,i=e._radius,a=n(e._matrix,!0,"rectangle"!==r);if("rectangle"===r){r="rect";var o=e._size,s=o.width,l=o.height;a.x-=s/2,a.y-=l/2,a.width=s,a.height=l,i.isZero()&&(i=null)}return i&&("circle"===r?a.r=i:(a.rx=i.width,a.ry=i.height)),t(r,a)}function l(e,r){var i=n(e._matrix),a=e.getPathData(null,r.precision);return a&&(i.d=a),t("path",i)}function u(e,r){var i=n(e._matrix,!0),a=e.getSymbol(),o=m(a,"symbol"),s=a.getDefinition(),l=s.getBounds();return o||(o=t("symbol",{viewBox:b.rectangle(l)}),o.appendChild(y(s,r)),g(a,o,"symbol")),i.href="#"+o.id,i.x+=l.x,i.y+=l.y,i.width=b.number(l.width),i.height=b.number(l.height),i.overflow="visible",t("use",i)}function c(e){var n=m(e,"color");if(!n){var r,i=e.getGradient(),a=i._radial,o=e.getOrigin().transform(),s=e.getDestination().transform();if(a){r={cx:o.x,cy:o.y,r:o.getDistance(s)};var l=e.getHighlight();l&&(l=l.transform(),r.fx=l.x,r.fy=l.y)}else r={x1:o.x,y1:o.y,x2:s.x,y2:s.y};r.gradientUnits="userSpaceOnUse",n=t((a?"radial":"linear")+"Gradient",r);for(var u=i._stops,c=0,h=u.length;h>c;c++){var d=u[c],p=d._color,f=p.getAlpha();r={offset:d._rampPoint,"stop-color":p.toCSS(!0)},1>f&&(r["stop-opacity"]=f),n.appendChild(t("stop",r))}g(e,n,"color")}return"url(#"+n.id+")"}function p(e){var r=t("text",n(e._matrix,!0));return r.textContent=e._content,r}function f(t,n,r){var i={},a=!r&&t.getParent();return null!=t._name&&(i.id=t._name),s.each(ie,function(e){var n=e.get,r=e.type,o=t[n]();if(e.exportFilter?e.exportFilter(t,o):!a||!s.equals(a[n](),o)){if("color"===r&&null!=o){var l=o.getAlpha();1>l&&(i[e.attribute+"-opacity"]=l)}i[e.attribute]=null==o?"none":"number"===r?b.number(o):"color"===r?o.gradient?c(o,t):o.toCSS(!0):"array"===r?o.join(","):"lookup"===r?e.toSVG[o]:o}}),1===i.opacity&&delete i.opacity,t._visible||(i.visibility="hidden"),e(n,i)}function m(e,t){return _||(_={ids:{},svgs:{}}),e&&_.svgs[t+"-"+e._id]}function g(e,t,n){_||m();var r=_.ids[n]=(_.ids[n]||0)+1;t.id=n+"-"+r,_.svgs[n+"-"+e._id]=t}function v(e,n){var r=e,i=null;if(_){r="svg"===e.nodeName.toLowerCase()&&e;for(var a in _.svgs)i||(r||(r=t("svg"),r.appendChild(e)),i=r.insertBefore(t("defs"),r.firstChild)),i.appendChild(_.svgs[a]);_=null}return n.asString?(new XMLSerializer).serializeToString(r):r}function y(e,t,n){var r=E[e._class],i=r&&r(e,t);if(i){var a=t.onExport;a&&(i=a(e,i,t)||i);var o=JSON.stringify(e._data);o&&"{}"!==o&&"null"!==o&&i.setAttribute("data-paper-data",o)}return i&&f(e,i,n)}function w(e){return e||(e={}),b=new h(e.precision),e}var b,_,E={Group:r,Layer:r,Raster:i,Path:a,Shape:o,CompoundPath:l,PlacedSymbol:u,PointText:p};C.inject({exportSVG:function(e){return e=w(e),v(y(this,e,!0),e)}}),x.inject({exportSVG:function(e){e=w(e);var r=this.layers,i=this.getView(),a=i.getViewSize(),o=t("svg",{x:0,y:0,width:a.width,height:a.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=o,l=i._matrix;l.isIdentity()||(s=o.appendChild(t("g",n(l))));for(var u=0,c=r.length;c>u;u++)s.appendChild(y(r[u],e,!0));return v(o,e)}})},new function(){function e(e,t,n,r){var i=ae[t],a=i?e.getAttributeNS(i,t):e.getAttribute(t);return"null"===a&&(a=null),null==a?r?null:n?"":0:n?a:parseFloat(a)}function t(t,n,r,i){return n=e(t,n,!1,i),r=e(t,r,!1,i),!i||null!=n&&null!=r?new f(n,r):null}function n(t,n,r,i){return n=e(t,n,!1,i),r=e(t,r,!1,i),!i||null!=n&&null!=r?new g(n,r):null}function r(e,t,n){return"none"===e?null:"number"===t?parseFloat(e):"array"===t?e?e.split(/[\s,]+/g).map(parseFloat):[]:"color"===t?v(e)||e:"lookup"===t?n[e]:e}function i(e,t,n,r){var i=e.childNodes,a="clippath"===t,o=new N,s=o._project,l=s._currentStyle,u=[];if(a||(o=m(o,e,r),s._currentStyle=o._style.clone()),r)for(var c=e.querySelectorAll("defs"),h=0,d=c.length;d>h;h++)w(c[h],n,!1);for(var h=0,d=i.length;d>h;h++){var p,f=i[h];1!==f.nodeType||"defs"===f.nodeName.toLowerCase()||!(p=w(f,n,!1))||p instanceof E||u.push(p)}return o.addChildren(u),a&&(o=m(o.reduce(),e,r)),s._currentStyle=l,(a||"defs"===t)&&(o.remove(),o=null),o}function l(e,t){for(var n=e.getAttribute("points").match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g),r=[],i=0,a=n.length;a>i;i+=2)r.push(new f(parseFloat(n[i]),parseFloat(n[i+1])));var o=new L(r);return"polygon"===t&&o.closePath(),o}function u(e){var t=e.getAttribute("d"),n={pathData:t};return(t.match(/m/gi)||[]).length>1||/z\S+/i.test(t)?new z(n):new L(n)}function c(n,r){var i,a=(e(n,"href",!0)||"").substring(1),o="radialgradient"===r;if(a)i=O[a].getGradient();else{for(var s=n.childNodes,l=[],u=0,c=s.length;c>u;u++){var h=s[u];1===h.nodeType&&l.push(m(new W,h))}i=new U(l,o)}var d,p,f;return o?(d=t(n,"cx","cy"),p=d.add(e(n,"r"),0),f=t(n,"fx","fy",!0)):(d=t(n,"x1","y1"),p=t(n,"x2","y2")),m(new q(i,d,p,f),n),null}function h(e,t,n,r){for(var i=(r.getAttribute(n)||"").split(/\)\s*/g),a=new b,o=0,s=i.length;s>o;o++){var l=i[o];if(!l)break;for(var u=l.split(/\(\s*/),c=u[0],h=u[1].split(/[\s,]+/g),d=0,p=h.length;p>d;d++)h[d]=parseFloat(h[d]);switch(c){case"matrix":a.concatenate(new b(h[0],h[1],h[2],h[3],h[4],h[5]));break;case"rotate":a.rotate(h[0],h[1],h[2]);break;case"translate":a.translate(h[0],h[1]);break;case"scale":a.scale(h);break;case"skewX":a.skew(h[0],0);break;case"skewY":a.skew(0,h[0])}}e.transform(a)}function d(e,t,n){var r=e["fill-opacity"===n?"getFillColor":"getStrokeColor"]();r&&r.setAlpha(parseFloat(t))}function p(e,t,n){var r=e.attributes[t],i=r&&r.value;if(!i){var a=s.camelize(t);i=e.style[a],i||n.node[a]===n.parent[a]||(i=n.node[a])}return i?"none"===i?null:i:o}function m(e,t,n){var r={node:H.getStyles(t)||{},parent:!n&&H.getStyles(t.parentNode)||{}};return s.each(k,function(n,i){var a=p(t,i,r);a!==o&&(e=s.pick(n(e,a,i,t,r),e))}),e}function v(e){var t=e&&e.match(/\((?:#|)([^)']+)/);return t&&O[t[1]]}function w(e,t,n){function r(e){a=o;var r=w(e,t,n),i=t.onLoad,s=o.project&&o.getView();i&&i.call(this,r),s.update()}if(!e)return null;t?"function"==typeof t&&(t={onLoad:t}):t={};var i=e,o=a;if(n)if("string"!=typeof e||/^.*a;a++){var s=i[a];if(1===s.nodeType){var l=s.nextSibling;document.body.appendChild(s);var u=w(s,n,r);return l?e.insertBefore(s,l):e.appendChild(s),u}}},g:i,svg:i,clippath:i,polygon:l,polyline:l,path:u,lineargradient:c,radialgradient:c,image:function(r){var i=new P(e(r,"href",!0));return i.on("load",function(){var e=n(r,"width","height");this.setSize(e);var i=this._matrix._transformPoint(t(r,"x","y").add(e.divide(2)));this.translate(i)}),i},symbol:function(e,t,n,r){return new E(i(e,t,n,r),!0)},defs:i,use:function(n){var r=(e(n,"href",!0)||"").substring(1),i=O[r],a=t(n,"x","y");return i?i instanceof E?i.place(a):i.clone().translate(a):null},circle:function(n){return new S.Circle(t(n,"cx","cy"),e(n,"r"))},ellipse:function(e){return new S.Ellipse({center:t(e,"cx","cy"),radius:n(e,"rx","ry")})},rect:function(e){var r=t(e,"x","y"),i=n(e,"width","height"),a=n(e,"rx","ry");return new S.Rectangle(new y(r,i),a)},line:function(e){return new L.Line(t(e,"x1","y1"),t(e,"x2","y2"))},text:function(e){var n=new F(t(e,"x","y").add(t(e,"dx","dy")));return n.setContent(e.textContent.trim()||""),n}},k=s.set(s.each(ie,function(e){this[e.attribute]=function(t,n){if(t[e.set](r(n,e.type,e.fromSVG)),"color"===e.type&&t instanceof S){var i=t[e.get]();i&&i.transform((new b).translate(t.getPosition(!0).negate()))}}},{}),{id:function(e,t){O[t]=e,e.setName&&e.setName(t)},"clip-path":function(e,t){var n=v(t);if(n){if(n=n.clone(),n.setClipMask(!0),!(e instanceof N))return new N(n,e);e.insertChild(0,n)}},gradientTransform:h,transform:h,"fill-opacity":d,"stroke-opacity":d,visibility:function(e,t){e.setVisible("visible"===t)},display:function(e,t){e.setVisible(null!==t)},"stop-color":function(e,t){e.setColor&&e.setColor(t)},"stop-opacity":function(e,t){e._color&&e._color.setAlpha(parseFloat(t))},offset:function(e,t){var n=t.match(/(.*)%$/);e.setRampPoint(n?n[1]/100:parseFloat(t))},viewBox:function(e,t,i,a,o){var s=new y(r(t,"array")),l=n(a,"width","height",!0);if(e instanceof N){var u=l?s.getSize().divide(l):1,c=(new b).translate(s.getPoint()).scale(u);e.transform(c.inverted())}else if(e instanceof E){l&&s.setSize(l);var h="visible"!=p(a,"overflow",o),d=e._definition;h&&!s.contains(d.getBounds())&&(h=new S.Rectangle(s).transform(d._matrix),h.setClipMask(!0),d.addChild(h))}}}),O={};C.inject({importSVG:function(e,t){return this.addChild(w(e,t,!0))}}),x.inject({importSVG:function(e,t){return this.activate(),w(e,t,!0)}})},a=new(u.inject(s.exports,{enumerable:!0,Base:s,Numerical:d,Key:J})),r=a,i="function"==typeof r?r.call(t,n,t,e):r,!(i!==o&&(e.exports=i)),a}},function(e,t,n){"use strict";var r=n(2),i=r.createClass({displayName:"SectionHeader",render:function(){return r.createElement("h2",{id:this.props.name,"data-num":this.props.number},r.createElement("a",{href:"#"+this.props.name},this.props.title))}});e.exports=i},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Whatis",getDefaultProps:function(){return{title:"So what makes a Bézier Curve?"}},setup:function(e){e.setPanelCount(3);var t=e.getDefaultQuadratic();e.setCurve(t),e.step=25},draw:function(e,t){var n,r,i,a,o,s,l,u,c=e.getPanelWidth(),h=t.points,d=h[0],p=h[1],f=h[2],m={x:0,y:0};for(e.reset(),e.setColor("black"),e.setFill("black"),e.drawSkeleton(t,m),e.text("First linear interpolation at "+e.step+"% steps",{x:5,y:15},m),m.x+=c,e.drawLine({x:0,y:0},{x:0,y:this.dim},m),e.drawSkeleton(t,m),e.text("Second interpolation at "+e.step+"% steps",{x:5,y:15},m),m.x+=c,e.drawLine({x:0,y:0},{x:0,y:this.dim},m),e.drawSkeleton(t,m),e.text("Curve points generated this way",{x:5,y:15},m),e.setColor("lightgrey"),a=1,s=20,u;s>a;a++)l=a/s,u=t.get(l),e.drawCircle(u,2,m);for(o=3*e.step;o>0;o-=e.step)a=o/100,a>1||(e.setRandomColor(),n={x:d.x+a*(p.x-d.x),y:d.y+a*(p.y-d.y)},r={x:p.x+a*(f.x-p.x),y:p.y+a*(f.y-p.y)},i={x:n.x+a*(r.x-n.x),y:n.y+a*(r.y-n.y)},m={x:0,y:0},e.drawCircle(n,3,m),e.drawCircle(r,3,m),e.setWeight(.5),e.drawLine(n,r,m),e.setWeight(1.5),e.drawLine(d,n,m),e.drawLine(p,r,m),e.setWeight(1),m.x+=c,e.drawCircle(n,3,m),e.drawCircle(r,3,m),e.setWeight(.5),e.drawLine(n,r,m),e.setWeight(1.5),e.drawLine(n,i,m),e.setWeight(1),e.drawCircle(i,3,m),m.x+=c,e.drawCircle(i,3,m),e.text(o+"%, or t = "+e.utils.round(a,2),{x:i.x+10+m.x,y:i.y+10+m.y}))},values:{38:1,40:-1},onKeyDown:function(e,t){var n=this.values[e.keyCode];n&&(e.preventDefault(),t.step+=n,t.step<1&&(t.step=1))},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"Playing with the points for curves may have given you a feel for how Bézier curves behaves, but what ",r.createElement("em",null,"are")," Bézier curves, really? There are two ways to explain what a Bézier curve is, and they turn out to be the entirely equivalent, but one of them uses complicated maths, and the other uses really simple maths. So... let's start with the simple explanation:"),r.createElement("p",null,"Bezier curves are the result of ",r.createElement("a",{href:"https://en.wikipedia.org/wiki/Linear_interpolation"},"linear interpolations"),". That sounds complicated but you've been doing linear interpolation since you were very young: any time you had to point at something between two other things, you've been applying linear interpolation. It's simply \"picking a point between two, points\"."),r.createElement("p",null,"If we know the distance between those two points, and we want a new point that is, say, 20% the distance away from the first point (and thus 80% the distance away from the second point) then we can compute that really easily:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/75bb049d813d8ee084b076531823f2109cc1660f.svg",style:{width:"36.750150000000005rem",height:"6.37515rem"}})),r.createElement("p",null,"So let's look at that in action: the following graphic is interactive in that you can use your up and down arrow keys to increase or decrease the interpolation distance, to see what happens. We start with three points, which gives us two lines. Linear interpolation over those lines gives use two points, between which we can again perform linear interpolation, yielding a single point. And that point —and all points we can form in this way for all distances taken together— form our Bézier curve:"),r.createElement(i,{title:"Linear Interpolation leading to Bézier curves",setup:this.setup,draw:this.draw,onKeyDown:this.onKeyDown}),r.createElement("p",null,"And that brings us to the complicated maths: calculus."),r.createElement("p",null,'While it doesn\'t look like that\'s what we\'ve just done, we actually just drew a quadratic curve, in steps, rather than in a single go. One of the fascinating parts about Bézier curves is that they can both be described in terms of polynomial functions, as well as in terms of very simple interpolations of interpolations of [...]. That, in turn, means we can look at what these curves can do based on both "real maths" (by examining the functions, their derivatives, and all that stuff), as well as by looking at the "mechanical" composition (which tells us that a curve will never extend beyond the points we used to construct it, for instance)'),r.createElement("p",null,"So let's start looking at Bézier curves a bit more in depth. Their mathematical expressions, the properties we can derive from those, and the various things we can do to, and with, Bézier curves."))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=n(226),s=r.createClass({displayName:"Explanation",statics:{keyHandlingOptions:{propName:"step",values:{38:.1,40:-.1},controller:function(e){e.step<.1&&(e.step=.1)}}},getDefaultProps:function(){return{title:"The mathematics of Bézier curves"}},setup:function(e){e.step=5},draw:function(e,t){var n=e.getPanelWidth(),r=n,i=n,a=r/2,o=i/2,s=a/2,l=o/2;e.reset(),e.setColor("black"),e.drawLine({x:0,y:o},{x:r,y:o}),e.drawLine({x:a,y:0},{x:a,y:i});for(var u,c={x:a,y:o},h=0;h<=e.step;h+=.1){u={x:s*Math.cos(h),y:l*Math.sin(h)},e.drawPoint(u,c);var d=h%1;(.05>d||d>.95)&&(e.text("t = "+Math.round(h),{x:c.x+1.25*s*Math.cos(h)-10,y:c.y+1.25*l*Math.sin(h)+5}),e.drawCircle(u,2,c))}},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'Bézier curves are a form of "parametric" function. Mathematically speaking, parametric functions are cheats: a "function" is actually a well defined term representing a mapping from any number of inputs to a ',r.createElement("strong",null,"single")," output. Numbers go in, a single number comes out. Change the numbers that go in, and the number that comes out is still a single number. Parametric functions cheat. They basically say \"alright, well, we want multiple values coming out, so we'll just use more than one function\". An illustration: Let's say we have a function that maps some value, let's call it ",r.createElement("i",null,"x"),", to some other value, using some kind of number manipulation:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/785e792c343b71d4e674ac94d8800940b30917ac.svg",style:{width:"6.22485rem",height:"1.125rem"}})),r.createElement("p",null,"The notation ",r.createElement("i",null,"f(x)")," is the standard way to show that it's a function (by convention called ",r.createElement("i",null,"f")," if we're only listing one) and its output changes based on one variable (in this case, ",r.createElement("i",null,"x"),"). Change ",r.createElement("i",null,"x"),", and the output for ",r.createElement("i",null,"f(x)")," changes."),r.createElement("p",null,"So far so good. Now, let's look at parametric functions, and how they cheat. Let's take the following two functions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/0dfe7562b43441e72201ff4cdd2e8b6e2e3ecb2d.svg",style:{width:"6.525rem",height:"2.6248500000000003rem"}})),r.createElement("p",null,"There's nothing really remarkable about them, they're just a sine and cosine function, but you'll notice the inputs have different names. If we change the value for ",r.createElement("i",null,"a"),", we're not going to change the output value for ",r.createElement("i",null,"f(b)"),", since ",r.createElement("i",null,"a")," isn't used in that function. Parametric functions cheat by changing that. In a parametric function all the different functions share a variable, like this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/ed6f533530199d1e99b3319ba137c1327b0459c0.svg",style:{width:"7.349849999999999rem",height:"2.6248500000000003rem"}})),r.createElement("p",null,"Multiple functions, but only one variable. If we change the value for ",r.createElement("i",null,"t"),", we change the outcome of both ",r.createElement("i",null,"f",r.createElement("sub",null,"a"),"(t)")," and ",r.createElement("i",null,"f",r.createElement("sub",null,"b"),"(t)"),". You might wonder how that's useful, and the answer is actually pretty simple: if we change the labels ",r.createElement("i",null,"f",r.createElement("sub",null,"a"),"(t)")," and ",r.createElement("i",null,"f",r.createElement("sub",null,"b"),"(t)")," with what we usually mean with them for parametric curves, things might be a lot more obvious:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/ea632ea75d6a2aeb6fe69c07feb6e76f81884746.svg",style:{width:"5.77485rem",height:"2.6248500000000003rem"}})),r.createElement("p",null,"There we go. ",r.createElement("i",null,"x"),"/",r.createElement("i",null,"y")," coordinates, linked through some mystery value ",r.createElement("i",null,"t"),"."),r.createElement("p",null,"So, parametric curves don't define a ",r.createElement("i",null,"y")," coordinate in terms of an ",r.createElement("i",null,"x"),' coordinate, like normal functions do, but they instead link the values to a "control" variable. If we vary the value of ',r.createElement("i",null,"t"),", then with every change we get ",r.createElement("strong",null,"two")," values, which we can use as (",r.createElement("i",null,"x"),",",r.createElement("i",null,"y"),") coordinates in a graph. The above set of functions, for instance, generates points on a circle: We can range ",r.createElement("i",null,"t")," from negative to positive infinity, and the resulting (",r.createElement("i",null,"x"),",",r.createElement("i",null,"y"),") coordinates will always lie on a circle with radius 1 around the origin (0,0). If we plot it for ",r.createElement("i",null,"t")," from 0 to 5, we get this (use your up and down arrow keys to change the plot end value):"),r.createElement(i,{preset:"empty",title:"A (partial) circle: x=sin(t), y=cos(t)","static":!0,setup:this.setup,draw:this.draw,onKeyDown:this.props.onKeyDown}),r.createElement("p",null,"Bézier curves are (one in many classes of) parametric functions, and are characterised by using the same base function for all its dimensions. Unlike the above example, where the ",r.createElement("i",null,"x")," and ",r.createElement("i",null,"y"),' values use different functions (one uses a sine, the other a cosine), Bézier curves use the "binomial polynomial" for both ',r.createElement("i",null,"x")," and ",r.createElement("i",null,"y"),". So what are binomial polynomials?"),r.createElement("p",null,"You may remember polynomials from high school, where they're those sums that look like:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/3e8b26cf8833db7089d65e9c6b3953a3140bb19f.svg",style:{width:"14.32485rem",height:"1.20015rem"}})),r.createElement("p",null,"If they have a highest order term ",r.createElement("i",null,"x³")," they're called \"cubic\" polynomials, if it's",r.createElement("i",null,"x²")," it's a \"square\" polynomial, if it's just ",r.createElement("i",null,"x")," it's a line (and if there aren't even any terms with ",r.createElement("i",null,"x")," it's not a polynomial!)"),r.createElement("p",null,"Bézier curves are polynomials of ",r.createElement("i",null,"t"),", rather than ",r.createElement("i",null,"x"),", with the value for ",r.createElement("i",null,"t"),"fixed being between 0 and 1, with coefficients ",r.createElement("i",null,"a"),", ",r.createElement("i",null,"b"),' etc. taking the "binomial" form, which sounds fancy but is actually a pretty simple description for mixing values:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/24e915ab4c69b85951f1ea9018b0ece9e52a10dd.svg",style:{width:"24.89985rem",height:"4.1998500000000005rem"}})),r.createElement("p",null,"I know what you're thinking: that doesn't look too simple, but if we remove ",r.createElement("i",null,"t"),' and add in "times one", things suddenly look pretty easy. Check out these binomial terms:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/448d10d21afd49135055cf685fedf6c494984b53.svg",style:{width:"14.475150000000001rem",height:"5.175rem"}})),r.createElement("p",null,'Notice that 2 is the same as 1+1, and 3 is 2+1 and 1+2, and 6 is 3+3... As you can see, each time we go up a dimension, we simply start and end with 1, and everything in between is just "the two numbers above it, added together". Now ',r.createElement("i",null,"that's")," easy to remember."),r.createElement("p",null,"There's an equally simple way to figure out how the polynomial terms work: if we rename ",r.createElement("i",null,"(1-t)")," to ",r.createElement("i",null,"a")," and ",r.createElement("i",null,"t")," to ",r.createElement("i",null,"b"),", and remove the weights for a moment, we get this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/87c7f5294b902def4ea56e8f6cf24265a37143b6.svg",style:{width:"20.84985rem",height:"3.825rem"}})),r.createElement("p",null,"It's basically just a sum of \"every combination of ",r.createElement("i",null,"a")," and ",r.createElement("i",null,"b"),'", progressively replacing ',r.createElement("i",null,"a"),"'s with ",r.createElement("i",null,"b"),"'s after every + sign. So that's actually pretty simple too. So now you know binomial polynomials, and just for completeness I'm going to show you the generic function for this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d79bf595a0911c17e2ac86d8806a0a8ab6ba7dfe.svg",style:{width:"20.39985rem",height:"3.90015rem"}})),r.createElement("p",null,"And that's the full description for Bézier curves. Σ in this function indicates that this is a series of additions (using the variable listed below the Σ, starting at ...= and ending at the value listed on top of the Σ)."),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"How to implement the basis function"),r.createElement("p",null,"We could naively implement the basis function as a mathematical construct, using the function as our guide, like this:"),r.createElement("pre",null,"function Bezier(n,t):","\n"," sum = 0","\n"," for(k=0; k= lut.length):","\n"," s = lut.length","\n"," nextRow = new array(size=s+1)","\n"," nextRow[0] = 1","\n"," for(i=1, prev=s-1; i<prev; i++):","\n"," nextRow[i] = lut[prev][i-1] + lut[prev][i]","\n"," nextRow[s] = 1","\n"," lut.add(nextRow)","\n"," return lut[n][k]"),r.createElement("p",null,"So what's going on here? First, we declare a lookup table with a size that's reasonably large enough to accommodate most lookups. Then, we declare a function to get us the values we need, and we make sure that if an n/k pair is requested that isn't in the LUT yet, we expand it first. Our basis function now looks like this:"),r.createElement("pre",null,"function Bezier(n,t):","\n"," sum = 0","\n"," for(k=0; k=n&&i.x<=t-n){this.drawLerpBox(e,t,n,i);var a=(i.x-n)/r;this.drawLerpPoint(e,(1-a)*(1-a),n,r,i),this.drawLerpPoint(e,2*(1-a)*a,n,r,i),this.drawLerpPoint(e,a*a,n,r,i)}this.drawFunction(e,"first term",{x:2*n,y:r},function(e){return{x:n+e*r,y:n+r*(1-e)*(1-e)}}),this.drawFunction(e,"second term",{x:t/2-1.5*n,y:t/2+n},function(e){return{x:n+e*r,y:n+2*r*(1-e)*e}}),this.drawFunction(e,"third term",{x:r-2.5*n,y:r},function(e){return{x:n+e*r,y:n+r*e*e}})},drawCubicLerp:function(e){e.reset();var t=e.getPanelWidth(),n=20,r=t-2*n;e.drawAxes(n,"t",0,1,"S","0%","100%");var i=e.hover;if(i&&i.x>=n&&i.x<=t-n){this.drawLerpBox(e,t,n,i);var a=(i.x-n)/r;this.drawLerpPoint(e,(1-a)*(1-a)*(1-a),n,r,i),this.drawLerpPoint(e,2*(1-a)*(1-a)*a,n,r,i),this.drawLerpPoint(e,3*(1-a)*a*a,n,r,i),this.drawLerpPoint(e,a*a*a,n,r,i)}this.drawFunction(e,"first term",{ +i=E[C],u=x[C],a=E[C+1],c=x[C+1],o=E[C+2],h=x[C+2],l=E[C+3],d=x[C+3],y();var k=l*r/255,S=1-k;x[C]=k*p+S*u,x[C+1]=k*f+S*c,x[C+2]=k*m+S*h,x[C+3]=l*r+S*d}n.putImageData(_,s.x,s.y)}}},ie=s.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],strokeScaling:["vector-effect","lookup",{"true":"none","false":"non-scaling-stroke"},function(e,t){return!t&&(e instanceof A||e instanceof S||e instanceof j)}],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],fontFamily:["font-family","string"],fontWeight:["font-weight","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(e,t){var n=s.capitalize(t),r=e[2];this[t]={type:e[1],property:t,attribute:e[0],toSVG:r,fromSVG:r&&s.each(r,function(e,t){this[e]=t},{}),exportFilter:e[3],get:"get"+n,set:"set"+n}},{}),ae={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function e(e,t){for(var n in t){var r=t[n],i=ae[n];"number"==typeof r&&(r=b.number(r)),i?e.setAttributeNS(i,n,r):e.setAttribute(n,r)}return e}function t(t,n){return e(document.createElementNS("http://www.w3.org/2000/svg",t),n)}function n(e,t,n){var r=new s,i=e.getTranslation();if(t){e=e.shiftless();var a=e._inverseTransform(i);r[n?"cx":"x"]=a.x,r[n?"cy":"y"]=a.y,i=null}if(!e.isIdentity()){var o=e.decompose();if(o&&!o.shearing){var l=[],u=o.rotation,c=o.scaling;i&&!i.isZero()&&l.push("translate("+b.point(i)+")"),d.isZero(c.x-1)&&d.isZero(c.y-1)||l.push("scale("+b.point(c)+")"),u&&l.push("rotate("+b.number(u)+")"),r.transform=l.join(" ")}else r.transform="matrix("+e.getValues().join(",")+")"}return r}function r(r,i){for(var a=n(r._matrix),o=r._children,s=t("g",a),l=0,u=o.length;u>l;l++){var c=o[l],h=y(c,i);if(h)if(c.isClipMask()){var d=t("clipPath");d.appendChild(h),g(c,d,"clip"),e(s,{"clip-path":"url(#"+d.id+")"})}else s.appendChild(h)}return s}function i(e,r){var i=n(e._matrix,!0),a=e.getSize(),o=e.getImage();return i.x-=a.width/2,i.y-=a.height/2,i.width=a.width,i.height=a.height,i.href=r.embedImages===!1&&o&&o.src||e.toDataURL(),t("image",i)}function a(e,r){var i=r.matchShapes;if(i){var a=e.toShape(!1);if(a)return o(a,r)}var s,l=e._segments,u=n(e._matrix);if(0===l.length)return null;if(i&&!e.hasHandles())if(l.length>=3){s=e._closed?"polygon":"polyline";for(var c=[],h=0,d=l.length;d>h;h++)c.push(b.point(l[h]._point));u.points=c.join(" ")}else{s="line";var p=l[0]._point,f=l[l.length-1]._point;u.set({x1:p.x,y1:p.y,x2:f.x,y2:f.y})}else s="path",u.d=e.getPathData(null,r.precision);return t(s,u)}function o(e){var r=e._type,i=e._radius,a=n(e._matrix,!0,"rectangle"!==r);if("rectangle"===r){r="rect";var o=e._size,s=o.width,l=o.height;a.x-=s/2,a.y-=l/2,a.width=s,a.height=l,i.isZero()&&(i=null)}return i&&("circle"===r?a.r=i:(a.rx=i.width,a.ry=i.height)),t(r,a)}function l(e,r){var i=n(e._matrix),a=e.getPathData(null,r.precision);return a&&(i.d=a),t("path",i)}function u(e,r){var i=n(e._matrix,!0),a=e.getSymbol(),o=m(a,"symbol"),s=a.getDefinition(),l=s.getBounds();return o||(o=t("symbol",{viewBox:b.rectangle(l)}),o.appendChild(y(s,r)),g(a,o,"symbol")),i.href="#"+o.id,i.x+=l.x,i.y+=l.y,i.width=b.number(l.width),i.height=b.number(l.height),i.overflow="visible",t("use",i)}function c(e){var n=m(e,"color");if(!n){var r,i=e.getGradient(),a=i._radial,o=e.getOrigin().transform(),s=e.getDestination().transform();if(a){r={cx:o.x,cy:o.y,r:o.getDistance(s)};var l=e.getHighlight();l&&(l=l.transform(),r.fx=l.x,r.fy=l.y)}else r={x1:o.x,y1:o.y,x2:s.x,y2:s.y};r.gradientUnits="userSpaceOnUse",n=t((a?"radial":"linear")+"Gradient",r);for(var u=i._stops,c=0,h=u.length;h>c;c++){var d=u[c],p=d._color,f=p.getAlpha();r={offset:d._rampPoint,"stop-color":p.toCSS(!0)},1>f&&(r["stop-opacity"]=f),n.appendChild(t("stop",r))}g(e,n,"color")}return"url(#"+n.id+")"}function p(e){var r=t("text",n(e._matrix,!0));return r.textContent=e._content,r}function f(t,n,r){var i={},a=!r&&t.getParent();return null!=t._name&&(i.id=t._name),s.each(ie,function(e){var n=e.get,r=e.type,o=t[n]();if(e.exportFilter?e.exportFilter(t,o):!a||!s.equals(a[n](),o)){if("color"===r&&null!=o){var l=o.getAlpha();1>l&&(i[e.attribute+"-opacity"]=l)}i[e.attribute]=null==o?"none":"number"===r?b.number(o):"color"===r?o.gradient?c(o,t):o.toCSS(!0):"array"===r?o.join(","):"lookup"===r?e.toSVG[o]:o}}),1===i.opacity&&delete i.opacity,t._visible||(i.visibility="hidden"),e(n,i)}function m(e,t){return _||(_={ids:{},svgs:{}}),e&&_.svgs[t+"-"+e._id]}function g(e,t,n){_||m();var r=_.ids[n]=(_.ids[n]||0)+1;t.id=n+"-"+r,_.svgs[n+"-"+e._id]=t}function v(e,n){var r=e,i=null;if(_){r="svg"===e.nodeName.toLowerCase()&&e;for(var a in _.svgs)i||(r||(r=t("svg"),r.appendChild(e)),i=r.insertBefore(t("defs"),r.firstChild)),i.appendChild(_.svgs[a]);_=null}return n.asString?(new XMLSerializer).serializeToString(r):r}function y(e,t,n){var r=E[e._class],i=r&&r(e,t);if(i){var a=t.onExport;a&&(i=a(e,i,t)||i);var o=JSON.stringify(e._data);o&&"{}"!==o&&"null"!==o&&i.setAttribute("data-paper-data",o)}return i&&f(e,i,n)}function w(e){return e||(e={}),b=new h(e.precision),e}var b,_,E={Group:r,Layer:r,Raster:i,Path:a,Shape:o,CompoundPath:l,PlacedSymbol:u,PointText:p};C.inject({exportSVG:function(e){return e=w(e),v(y(this,e,!0),e)}}),x.inject({exportSVG:function(e){e=w(e);var r=this.layers,i=this.getView(),a=i.getViewSize(),o=t("svg",{x:0,y:0,width:a.width,height:a.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=o,l=i._matrix;l.isIdentity()||(s=o.appendChild(t("g",n(l))));for(var u=0,c=r.length;c>u;u++)s.appendChild(y(r[u],e,!0));return v(o,e)}})},new function(){function e(e,t,n,r){var i=ae[t],a=i?e.getAttributeNS(i,t):e.getAttribute(t);return"null"===a&&(a=null),null==a?r?null:n?"":0:n?a:parseFloat(a)}function t(t,n,r,i){return n=e(t,n,!1,i),r=e(t,r,!1,i),!i||null!=n&&null!=r?new f(n,r):null}function n(t,n,r,i){return n=e(t,n,!1,i),r=e(t,r,!1,i),!i||null!=n&&null!=r?new g(n,r):null}function r(e,t,n){return"none"===e?null:"number"===t?parseFloat(e):"array"===t?e?e.split(/[\s,]+/g).map(parseFloat):[]:"color"===t?v(e)||e:"lookup"===t?n[e]:e}function i(e,t,n,r){var i=e.childNodes,a="clippath"===t,o=new N,s=o._project,l=s._currentStyle,u=[];if(a||(o=m(o,e,r),s._currentStyle=o._style.clone()),r)for(var c=e.querySelectorAll("defs"),h=0,d=c.length;d>h;h++)w(c[h],n,!1);for(var h=0,d=i.length;d>h;h++){var p,f=i[h];1!==f.nodeType||"defs"===f.nodeName.toLowerCase()||!(p=w(f,n,!1))||p instanceof E||u.push(p)}return o.addChildren(u),a&&(o=m(o.reduce(),e,r)),s._currentStyle=l,(a||"defs"===t)&&(o.remove(),o=null),o}function l(e,t){for(var n=e.getAttribute("points").match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g),r=[],i=0,a=n.length;a>i;i+=2)r.push(new f(parseFloat(n[i]),parseFloat(n[i+1])));var o=new L(r);return"polygon"===t&&o.closePath(),o}function u(e){var t=e.getAttribute("d"),n={pathData:t};return(t.match(/m/gi)||[]).length>1||/z\S+/i.test(t)?new z(n):new L(n)}function c(n,r){var i,a=(e(n,"href",!0)||"").substring(1),o="radialgradient"===r;if(a)i=O[a].getGradient();else{for(var s=n.childNodes,l=[],u=0,c=s.length;c>u;u++){var h=s[u];1===h.nodeType&&l.push(m(new W,h))}i=new U(l,o)}var d,p,f;return o?(d=t(n,"cx","cy"),p=d.add(e(n,"r"),0),f=t(n,"fx","fy",!0)):(d=t(n,"x1","y1"),p=t(n,"x2","y2")),m(new q(i,d,p,f),n),null}function h(e,t,n,r){for(var i=(r.getAttribute(n)||"").split(/\)\s*/g),a=new b,o=0,s=i.length;s>o;o++){var l=i[o];if(!l)break;for(var u=l.split(/\(\s*/),c=u[0],h=u[1].split(/[\s,]+/g),d=0,p=h.length;p>d;d++)h[d]=parseFloat(h[d]);switch(c){case"matrix":a.concatenate(new b(h[0],h[1],h[2],h[3],h[4],h[5]));break;case"rotate":a.rotate(h[0],h[1],h[2]);break;case"translate":a.translate(h[0],h[1]);break;case"scale":a.scale(h);break;case"skewX":a.skew(h[0],0);break;case"skewY":a.skew(0,h[0])}}e.transform(a)}function d(e,t,n){var r=e["fill-opacity"===n?"getFillColor":"getStrokeColor"]();r&&r.setAlpha(parseFloat(t))}function p(e,t,n){var r=e.attributes[t],i=r&&r.value;if(!i){var a=s.camelize(t);i=e.style[a],i||n.node[a]===n.parent[a]||(i=n.node[a])}return i?"none"===i?null:i:o}function m(e,t,n){var r={node:H.getStyles(t)||{},parent:!n&&H.getStyles(t.parentNode)||{}};return s.each(k,function(n,i){var a=p(t,i,r);a!==o&&(e=s.pick(n(e,a,i,t,r),e))}),e}function v(e){var t=e&&e.match(/\((?:#|)([^)']+)/);return t&&O[t[1]]}function w(e,t,n){function r(e){a=o;var r=w(e,t,n),i=t.onLoad,s=o.project&&o.getView();i&&i.call(this,r),s.update()}if(!e)return null;t?"function"==typeof t&&(t={onLoad:t}):t={};var i=e,o=a;if(n)if("string"!=typeof e||/^.*a;a++){var s=i[a];if(1===s.nodeType){var l=s.nextSibling;document.body.appendChild(s);var u=w(s,n,r);return l?e.insertBefore(s,l):e.appendChild(s),u}}},g:i,svg:i,clippath:i,polygon:l,polyline:l,path:u,lineargradient:c,radialgradient:c,image:function(r){var i=new P(e(r,"href",!0));return i.on("load",function(){var e=n(r,"width","height");this.setSize(e);var i=this._matrix._transformPoint(t(r,"x","y").add(e.divide(2)));this.translate(i)}),i},symbol:function(e,t,n,r){return new E(i(e,t,n,r),!0)},defs:i,use:function(n){var r=(e(n,"href",!0)||"").substring(1),i=O[r],a=t(n,"x","y");return i?i instanceof E?i.place(a):i.clone().translate(a):null},circle:function(n){return new S.Circle(t(n,"cx","cy"),e(n,"r"))},ellipse:function(e){return new S.Ellipse({center:t(e,"cx","cy"),radius:n(e,"rx","ry")})},rect:function(e){var r=t(e,"x","y"),i=n(e,"width","height"),a=n(e,"rx","ry");return new S.Rectangle(new y(r,i),a)},line:function(e){return new L.Line(t(e,"x1","y1"),t(e,"x2","y2"))},text:function(e){var n=new F(t(e,"x","y").add(t(e,"dx","dy")));return n.setContent(e.textContent.trim()||""),n}},k=s.set(s.each(ie,function(e){this[e.attribute]=function(t,n){if(t[e.set](r(n,e.type,e.fromSVG)),"color"===e.type&&t instanceof S){var i=t[e.get]();i&&i.transform((new b).translate(t.getPosition(!0).negate()))}}},{}),{id:function(e,t){O[t]=e,e.setName&&e.setName(t)},"clip-path":function(e,t){var n=v(t);if(n){if(n=n.clone(),n.setClipMask(!0),!(e instanceof N))return new N(n,e);e.insertChild(0,n)}},gradientTransform:h,transform:h,"fill-opacity":d,"stroke-opacity":d,visibility:function(e,t){e.setVisible("visible"===t)},display:function(e,t){e.setVisible(null!==t)},"stop-color":function(e,t){e.setColor&&e.setColor(t)},"stop-opacity":function(e,t){e._color&&e._color.setAlpha(parseFloat(t))},offset:function(e,t){var n=t.match(/(.*)%$/);e.setRampPoint(n?n[1]/100:parseFloat(t))},viewBox:function(e,t,i,a,o){var s=new y(r(t,"array")),l=n(a,"width","height",!0);if(e instanceof N){var u=l?s.getSize().divide(l):1,c=(new b).translate(s.getPoint()).scale(u);e.transform(c.inverted())}else if(e instanceof E){l&&s.setSize(l);var h="visible"!=p(a,"overflow",o),d=e._definition;h&&!s.contains(d.getBounds())&&(h=new S.Rectangle(s).transform(d._matrix),h.setClipMask(!0),d.addChild(h))}}}),O={};C.inject({importSVG:function(e,t){return this.addChild(w(e,t,!0))}}),x.inject({importSVG:function(e,t){return this.activate(),w(e,t,!0)}})},a=new(u.inject(s.exports,{enumerable:!0,Base:s,Numerical:d,Key:J})),r=a,i="function"==typeof r?r.call(t,n,t,e):r,!(i!==o&&(e.exports=i)),a}},function(e,t,n){"use strict";var r=n(2),i=r.createClass({displayName:"SectionHeader",render:function(){return r.createElement("h2",{id:this.props.name,"data-num":this.props.number},r.createElement("a",{href:"#"+this.props.name},this.props.title))}});e.exports=i},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Whatis",getDefaultProps:function(){return{title:"So what makes a Bézier Curve?"}},setup:function(e){e.setPanelCount(3);var t=e.getDefaultQuadratic();e.setCurve(t),e.step=25},draw:function(e,t){var n,r,i,a,o,s,l,u,c=e.getPanelWidth(),h=t.points,d=h[0],p=h[1],f=h[2],m={x:0,y:0};for(e.reset(),e.setColor("black"),e.setFill("black"),e.drawSkeleton(t,m),e.text("First linear interpolation at "+e.step+"% steps",{x:5,y:15},m),m.x+=c,e.drawLine({x:0,y:0},{x:0,y:this.dim},m),e.drawSkeleton(t,m),e.text("Second interpolation at "+e.step+"% steps",{x:5,y:15},m),m.x+=c,e.drawLine({x:0,y:0},{x:0,y:this.dim},m),e.drawSkeleton(t,m),e.text("Curve points generated this way",{x:5,y:15},m),e.setColor("lightgrey"),a=1,s=20,u;s>a;a++)l=a/s,u=t.get(l),e.drawCircle(u,2,m);for(o=3*e.step;o>0;o-=e.step)a=o/100,a>1||(e.setRandomColor(),n={x:d.x+a*(p.x-d.x),y:d.y+a*(p.y-d.y)},r={x:p.x+a*(f.x-p.x),y:p.y+a*(f.y-p.y)},i={x:n.x+a*(r.x-n.x),y:n.y+a*(r.y-n.y)},m={x:0,y:0},e.drawCircle(n,3,m),e.drawCircle(r,3,m),e.setWeight(.5),e.drawLine(n,r,m),e.setWeight(1.5),e.drawLine(d,n,m),e.drawLine(p,r,m),e.setWeight(1),m.x+=c,e.drawCircle(n,3,m),e.drawCircle(r,3,m),e.setWeight(.5),e.drawLine(n,r,m),e.setWeight(1.5),e.drawLine(n,i,m),e.setWeight(1),e.drawCircle(i,3,m),m.x+=c,e.drawCircle(i,3,m),e.text(o+"%, or t = "+e.utils.round(a,2),{x:i.x+10+m.x,y:i.y+10+m.y}))},values:{38:1,40:-1},onKeyDown:function(e,t){var n=this.values[e.keyCode];n&&(e.preventDefault(),t.step+=n,t.step<1&&(t.step=1))},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"Playing with the points for curves may have given you a feel for how Bézier curves behaves, but what ",r.createElement("em",null,"are")," Bézier curves, really? There are two ways to explain what a Bézier curve is, and they turn out to be the entirely equivalent, but one of them uses complicated maths, and the other uses really simple maths. So... let's start with the simple explanation:"),r.createElement("p",null,"Bezier curves are the result of ",r.createElement("a",{href:"https://en.wikipedia.org/wiki/Linear_interpolation"},"linear interpolations"),". That sounds complicated but you've been doing linear interpolation since you were very young: any time you had to point at something between two other things, you've been applying linear interpolation. It's simply \"picking a point between two, points\"."),r.createElement("p",null,"If we know the distance between those two points, and we want a new point that is, say, 20% the distance away from the first point (and thus 80% the distance away from the second point) then we can compute that really easily:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/75bb049d813d8ee084b076531823f2109cc1660f.svg",style:{width:"36.750150000000005rem",height:"6.37515rem"}})),r.createElement("p",null,"So let's look at that in action: the following graphic is interactive in that you can use your up and down arrow keys to increase or decrease the interpolation distance, to see what happens. We start with three points, which gives us two lines. Linear interpolation over those lines gives use two points, between which we can again perform linear interpolation, yielding a single point. And that point —and all points we can form in this way for all distances taken together— form our Bézier curve:"),r.createElement(i,{title:"Linear Interpolation leading to Bézier curves",setup:this.setup,draw:this.draw,onKeyDown:this.onKeyDown}),r.createElement("p",null,"And that brings us to the complicated maths: calculus."),r.createElement("p",null,'While it doesn\'t look like that\'s what we\'ve just done, we actually just drew a quadratic curve, in steps, rather than in a single go. One of the fascinating parts about Bézier curves is that they can both be described in terms of polynomial functions, as well as in terms of very simple interpolations of interpolations of [...]. That, in turn, means we can look at what these curves can do based on both "real maths" (by examining the functions, their derivatives, and all that stuff), as well as by looking at the "mechanical" composition (which tells us that a curve will never extend beyond the points we used to construct it, for instance)'),r.createElement("p",null,"So let's start looking at Bézier curves a bit more in depth. Their mathematical expressions, the properties we can derive from those, and the various things we can do to, and with, Bézier curves."))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=n(226),s=r.createClass({displayName:"Explanation",statics:{keyHandlingOptions:{propName:"step",values:{38:.1,40:-.1},controller:function(e){e.step<.1&&(e.step=.1)}}},getDefaultProps:function(){return{title:"The mathematics of Bézier curves"}},setup:function(e){e.step=5},draw:function(e,t){var n=e.getPanelWidth(),r=n,i=n,a=r/2,o=i/2,s=a/2,l=o/2;e.reset(),e.setColor("black"),e.drawLine({x:0,y:o},{x:r,y:o}),e.drawLine({x:a,y:0},{x:a,y:i});for(var u,c={x:a,y:o},h=0;h<=e.step;h+=.1){u={x:s*Math.cos(h),y:l*Math.sin(h)},e.drawPoint(u,c);var d=h%1;(.05>d||d>.95)&&(e.text("t = "+Math.round(h),{x:c.x+1.25*s*Math.cos(h)-10,y:c.y+1.25*l*Math.sin(h)+5}),e.drawCircle(u,2,c))}},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'Bézier curves are a form of "parametric" function. Mathematically speaking, parametric functions are cheats: a "function" is actually a well defined term representing a mapping from any number of inputs to a ',r.createElement("strong",null,"single")," output. Numbers go in, a single number comes out. Change the numbers that go in, and the number that comes out is still a single number. Parametric functions cheat. They basically say \"alright, well, we want multiple values coming out, so we'll just use more than one function\". An illustration: Let's say we have a function that maps some value, let's call it ",r.createElement("i",null,"x"),", to some other value, using some kind of number manipulation:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/785e792c343b71d4e674ac94d8800940b30917ac.svg",style:{width:"6.22485rem",height:"1.125rem"}})),r.createElement("p",null,"The notation ",r.createElement("i",null,"f(x)")," is the standard way to show that it's a function (by convention called ",r.createElement("i",null,"f")," if we're only listing one) and its output changes based on one variable (in this case, ",r.createElement("i",null,"x"),"). Change ",r.createElement("i",null,"x"),", and the output for ",r.createElement("i",null,"f(x)")," changes."),r.createElement("p",null,"So far so good. Now, let's look at parametric functions, and how they cheat. Let's take the following two functions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/0dfe7562b43441e72201ff4cdd2e8b6e2e3ecb2d.svg",style:{width:"6.525rem",height:"2.6248500000000003rem"}})),r.createElement("p",null,"There's nothing really remarkable about them, they're just a sine and cosine function, but you'll notice the inputs have different names. If we change the value for ",r.createElement("i",null,"a"),", we're not going to change the output value for ",r.createElement("i",null,"f(b)"),", since ",r.createElement("i",null,"a")," isn't used in that function. Parametric functions cheat by changing that. In a parametric function all the different functions share a variable, like this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/ed6f533530199d1e99b3319ba137c1327b0459c0.svg",style:{width:"7.349849999999999rem",height:"2.6248500000000003rem"}})),r.createElement("p",null,"Multiple functions, but only one variable. If we change the value for ",r.createElement("i",null,"t"),", we change the outcome of both ",r.createElement("i",null,"f",r.createElement("sub",null,"a"),"(t)")," and ",r.createElement("i",null,"f",r.createElement("sub",null,"b"),"(t)"),". You might wonder how that's useful, and the answer is actually pretty simple: if we change the labels ",r.createElement("i",null,"f",r.createElement("sub",null,"a"),"(t)")," and ",r.createElement("i",null,"f",r.createElement("sub",null,"b"),"(t)")," with what we usually mean with them for parametric curves, things might be a lot more obvious:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/ea632ea75d6a2aeb6fe69c07feb6e76f81884746.svg",style:{width:"5.77485rem",height:"2.6248500000000003rem"}})),r.createElement("p",null,"There we go. ",r.createElement("i",null,"x"),"/",r.createElement("i",null,"y")," coordinates, linked through some mystery value ",r.createElement("i",null,"t"),"."),r.createElement("p",null,"So, parametric curves don't define a ",r.createElement("i",null,"y")," coordinate in terms of an ",r.createElement("i",null,"x"),' coordinate, like normal functions do, but they instead link the values to a "control" variable. If we vary the value of ',r.createElement("i",null,"t"),", then with every change we get ",r.createElement("strong",null,"two")," values, which we can use as (",r.createElement("i",null,"x"),",",r.createElement("i",null,"y"),") coordinates in a graph. The above set of functions, for instance, generates points on a circle: We can range ",r.createElement("i",null,"t")," from negative to positive infinity, and the resulting (",r.createElement("i",null,"x"),",",r.createElement("i",null,"y"),") coordinates will always lie on a circle with radius 1 around the origin (0,0). If we plot it for ",r.createElement("i",null,"t")," from 0 to 5, we get this (use your up and down arrow keys to change the plot end value):"),r.createElement(i,{preset:"empty",title:"A (partial) circle: x=sin(t), y=cos(t)","static":!0,setup:this.setup,draw:this.draw,onKeyDown:this.props.onKeyDown}),r.createElement("p",null,"Bézier curves are (one in many classes of) parametric functions, and are characterised by using the same base function for all its dimensions. Unlike the above example, where the ",r.createElement("i",null,"x")," and ",r.createElement("i",null,"y"),' values use different functions (one uses a sine, the other a cosine), Bézier curves use the "binomial polynomial" for both ',r.createElement("i",null,"x")," and ",r.createElement("i",null,"y"),". So what are binomial polynomials?"),r.createElement("p",null,"You may remember polynomials from high school, where they're those sums that look like:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/3e8b26cf8833db7089d65e9c6b3953a3140bb19f.svg",style:{width:"14.32485rem",height:"1.20015rem"}})),r.createElement("p",null,"If they have a highest order term ",r.createElement("i",null,"x³")," they're called \"cubic\" polynomials, if it's",r.createElement("i",null,"x²")," it's a \"square\" polynomial, if it's just ",r.createElement("i",null,"x")," it's a line (and if there aren't even any terms with ",r.createElement("i",null,"x")," it's not a polynomial!)"),r.createElement("p",null,"Bézier curves are polynomials of ",r.createElement("i",null,"t"),", rather than ",r.createElement("i",null,"x"),", with the value for ",r.createElement("i",null,"t"),"fixed being between 0 and 1, with coefficients ",r.createElement("i",null,"a"),", ",r.createElement("i",null,"b"),' etc. taking the "binomial" form, which sounds fancy but is actually a pretty simple description for mixing values:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/24e915ab4c69b85951f1ea9018b0ece9e52a10dd.svg",style:{width:"24.89985rem",height:"4.1998500000000005rem"}})),r.createElement("p",null,"I know what you're thinking: that doesn't look too simple, but if we remove ",r.createElement("i",null,"t"),' and add in "times one", things suddenly look pretty easy. Check out these binomial terms:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/448d10d21afd49135055cf685fedf6c494984b53.svg",style:{width:"14.475150000000001rem",height:"5.175rem"}})),r.createElement("p",null,'Notice that 2 is the same as 1+1, and 3 is 2+1 and 1+2, and 6 is 3+3... As you can see, each time we go up a dimension, we simply start and end with 1, and everything in between is just "the two numbers above it, added together". Now ',r.createElement("i",null,"that's")," easy to remember."),r.createElement("p",null,"There's an equally simple way to figure out how the polynomial terms work: if we rename ",r.createElement("i",null,"(1-t)")," to ",r.createElement("i",null,"a")," and ",r.createElement("i",null,"t")," to ",r.createElement("i",null,"b"),", and remove the weights for a moment, we get this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/87c7f5294b902def4ea56e8f6cf24265a37143b6.svg",style:{width:"20.84985rem",height:"3.825rem"}})),r.createElement("p",null,"It's basically just a sum of \"every combination of ",r.createElement("i",null,"a")," and ",r.createElement("i",null,"b"),'", progressively replacing ',r.createElement("i",null,"a"),"'s with ",r.createElement("i",null,"b"),"'s after every + sign. So that's actually pretty simple too. So now you know binomial polynomials, and just for completeness I'm going to show you the generic function for this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d79bf595a0911c17e2ac86d8806a0a8ab6ba7dfe.svg",style:{width:"20.39985rem",height:"3.90015rem"}})),r.createElement("p",null,"And that's the full description for Bézier curves. Σ in this function indicates that this is a series of additions (using the variable listed below the Σ, starting at ...= and ending at the value listed on top of the Σ)."),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"How to implement the basis function"),r.createElement("p",null,"We could naively implement the basis function as a mathematical construct, using the function as our guide, like this:"),r.createElement("pre",null,"function Bezier(n,t):","\n"," sum = 0","\n"," for(k=0; k= lut.length):","\n"," s = lut.length","\n"," nextRow = new array(size=s+1)","\n"," nextRow[0] = 1","\n"," for(i=1, prev=s-1; i<prev; i++):","\n"," nextRow[i] = lut[prev][i-1] + lut[prev][i]","\n"," nextRow[s] = 1","\n"," lut.add(nextRow)","\n"," return lut[n][k]"),r.createElement("p",null,"So what's going on here? First, we declare a lookup table with a size that's reasonably large enough to accommodate most lookups. Then, we declare a function to get us the values we need, and we make sure that if an n/k pair is requested that isn't in the LUT yet, we expand it first. Our basis function now looks like this:"),r.createElement("pre",null,"function Bezier(n,t):","\n"," sum = 0","\n"," for(k=0; k=n&&i.x<=t-n){this.drawLerpBox(e,t,n,i);var a=(i.x-n)/r;this.drawLerpPoint(e,(1-a)*(1-a),n,r,i),this.drawLerpPoint(e,2*(1-a)*a,n,r,i),this.drawLerpPoint(e,a*a,n,r,i)}this.drawFunction(e,"first term",{x:2*n,y:r},function(e){return{x:n+e*r,y:n+r*(1-e)*(1-e)}}),this.drawFunction(e,"second term",{x:t/2-1.5*n,y:t/2+n},function(e){return{x:n+e*r,y:n+2*r*(1-e)*e}}),this.drawFunction(e,"third term",{x:r-2.5*n,y:r},function(e){return{x:n+e*r,y:n+r*e*e}})},drawCubicLerp:function(e){e.reset();var t=e.getPanelWidth(),n=20,r=t-2*n;e.drawAxes(n,"t",0,1,"S","0%","100%");var i=e.hover;if(i&&i.x>=n&&i.x<=t-n){this.drawLerpBox(e,t,n,i);var a=(i.x-n)/r;this.drawLerpPoint(e,(1-a)*(1-a)*(1-a),n,r,i),this.drawLerpPoint(e,3*(1-a)*(1-a)*a,n,r,i),this.drawLerpPoint(e,3*(1-a)*a*a,n,r,i),this.drawLerpPoint(e,a*a*a,n,r,i)}this.drawFunction(e,"first term",{ x:2*n,y:r},function(e){return{x:n+e*r,y:n+r*(1-e)*(1-e)*(1-e)}}),this.drawFunction(e,"second term",{x:t/2-4*n,y:t/2},function(e){return{x:n+e*r,y:n+3*r*(1-e)*(1-e)*e}}),this.drawFunction(e,"third term",{x:t/2+2*n,y:t/2},function(e){return{x:n+e*r,y:n+3*r*(1-e)*e*e}}),this.drawFunction(e,"fourth term",{x:r-2.5*n,y:r},function(e){return{x:n+e*r,y:n+r*e*e*e}})},draw15thLerp:function(e){e.reset();var t=e.getPanelWidth(),n=20,r=t-2*n;e.drawAxes(n,"t",0,1,"S","0%","100%");var i,a=[1,15,105,455,1365,3003,5005,6435,6435,5005,3003,1365,455,105,15,1],o=e.hover;if(o&&o.x>=n&&o.x<=t-n)for(this.drawLerpBox(e,t,n,o),i=0;15>=i;i++){var s=(o.x-n)/r,l=a[i]*Math.pow(1-s,15-i)*Math.pow(s,i);this.drawLerpPoint(e,l,n,r,o)}for(i=0;15>=i;i++){var u=!1,c=!1;0===i&&(u="first term",c={x:n+5,y:r}),15===i&&(u="last term",c={x:t-3.5*n,y:r}),this.drawFunction(e,u,c,function(e){return{x:n+e*r,y:n+r*a[i]*Math.pow(1-e,15-i)*Math.pow(e,i)}})}},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'Bézier curves are (like all "splines") interpolation functions, meaning they take a set of points, and generate values somewhere "between" those points. (One of the consequences of this is that you\'ll never be able to generate a point that lies outside the outline for the control points, commonly called the "hull" for the curve. Useful information!). In fact, we can visualize how each point contributes to the value generated by the function, so we can see which points are important, where, in the curve.'),r.createElement("p",null,'The following graphs show the interpolation functions for quadratic and cubic curves, with "S" being the strength of a point\'s contribution to the total sum of the Bézier function. Click or click-drag to see the interpolation percentages for each curve-defining point at a specific ',r.createElement("i",null,"t")," value."),r.createElement("div",{className:"figure"},r.createElement(i,{inline:!0,preset:"simple",title:"Quadratic interpolations",draw:this.drawQuadraticLerp}),r.createElement(i,{inline:!0,preset:"simple",title:"Cubic interpolations",draw:this.drawCubicLerp}),r.createElement(i,{inline:!0,preset:"simple",title:"15th order interpolations",draw:this.draw15thLerp})),r.createElement("p",null,"Also shown is the interpolation function for a 15",r.createElement("sup",null,"th")," order Bézier function. As you can see, the start and end point contribute considerably more to the curve's shape than any other point in the control point set."),r.createElement("p",null,'If we want to change the curve, we need to change the weights of each point, effectively changing the interpolations. The way to do this is about as straight forward as possible: just multiply each point with a value that changes its strength. These values are conventionally called "Weights", and we can add them to our original Bézier function:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/b98618f8061e9e58289abccc06a624a14561d40f.svg",style:{width:"23.70015rem",height:"3.90015rem"}})),r.createElement("p",null,'That looks complicated, but as it so happens, the "weights" are actually just the coordinate values we want our curve to have: for an ',r.createElement("i",null,"n",r.createElement("sup",null,"th"))," order curve, w",r.createElement("sub",null,"0")," is our start coordinate, w",r.createElement("sub",null,"n")," is our last coordinate, and everything in between is a controlling coordinate. Say we want a cubic curve that starts at (120,160), is controlled by (35,200) and (220,260) and ends at (220,40), we use this Bézier curve:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/853858526831a7ef3eb170efe49de397bb4913a1.svg",style:{width:"32.025150000000004rem",height:"2.77515rem"}})),r.createElement("p",null,"Which gives us the curve we saw at the top of the article:"),r.createElement(i,{preset:"simple",title:"Our cubic Bézier curve",setup:this.drawCubic,draw:this.drawCurve}),r.createElement("p",null,"What else can we do with Bézier curves? Quite a lot, actually. The rest of this article covers a multitude of possible operations and algorithms that we can apply, and the tasks they achieve."),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"How to implement the weighted basis function"),r.createElement("p",null,"Given that we already know how to implement basis function, adding in the control points is remarkably easy:"),r.createElement("pre",null,"function Bezier(n,t,w[]):","\n"," sum = 0","\n"," for(k=0; k=n;n+=i)r=t.get(n),e.drawLine(o,r),o=r;o=t.get(1);var s=10;for(n=1+i;s>=n;n+=i)r=t.get(n),e.drawLine(o,r),o=r},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"Now that we know the mathematics behind Bézier curves, there's one curious thing that you may have noticed: they always run from ",r.createElement("i",null,"t-0")," to ",r.createElement("i",null,"t=1"),". Why that particular interval?"),r.createElement("p",null,'It all has to do with how we run from "the start" of our curve to "the end" of our curve. If we have a value that is a mixture of two other values, then the general formula for this is:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/7f5ebb8489a8d04beb28f47c8aac2632b78ae764.svg",style:{width:"14.99985rem",height:"0.9rem"}})),r.createElement("p",null,"The obvious start and end values here need to be ",r.createElement("i",null,"a=1, b=0"),", so that the mixed value is 100% value 1, and 0% value 2, and ",r.createElement("i",null,"a=0, b=1"),', so that the mixed value is 0% value 1 and 100% value 2. Additionally, we don\'t want "a" and "b" to be independent: if they are, then we could just pick whatever values we like, and end up with a mixed value that is, for example, 100% value 1 ',r.createElement("strong",null,"and")," 100% value 2. In principle that's fine, but for Bézier curves we always want mixed values ",r.createElement("em",null,"between"),' the start and end point, so we need to make sure we can never set "a" and "b" to some values that lead to a mix value that sums to more than 100%. And that\'s easy:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d326c8f323ccd2da00d998b533ac26a1c04fcfba.svg",style:{width:"14.774849999999999rem",height:"1.125rem"}})),r.createElement("p",null,"With this we can guarantee that we never sum above 100%. By restricting ",r.createElement("i",null,"a")," to values in the interval [0,1], we will always be somewhere between our two values (inclusively), and we will always sum to a 100% mix."),r.createElement("p",null,'But... what if we use this form, used in the assumption that we will only ever use values between 0 and 1, and instead use values outside of that interval? Do things go horribly wrong? Well... not really, but we get to "see more".'),r.createElement("p",null,'In the case of Bézier curves, extending the interval simply makes our curve "keep going". Bézier curves are simply segments on some polynomial curve, so if we pick a wider interval we simply get to see more of the curve. So what do they look like?'),r.createElement("p",null,'The following two graphics show you Bézier curves rendered "the usual way", as well as the curves they "lie on" if we were to extend the ',r.createElement("i",null,"t"),' values much further. As you can see, there\'s a lot more "shape" hidden in the rest of the curve, and we can model those parts by moving the curve points around.'),r.createElement(i,{preset:"simple",title:"Quadratic infinite interval Bézier curve",setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"simple",title:"Cubic infinite interval Bézier curve",setup:this.setupCubic,draw:this.draw}),r.createElement("p",null,"In fact, there are curves used in graphics design and computer modelling that do the opposite of Bézier curves, where rather than fixing the interval, and giving you free coordinates, they fix the coordinates, but give you freedom over the interval. A great example of this is the ",r.createElement("a",{href:"http://levien.com/phd/phd.html"},'"Spiro" curve'),", which is a curve based on part of a ",r.createElement("a",{href:"https://en.wikipedia.org/wiki/Euler_spiral"},"Cornu Spiral, also known as Euler's Spiral"),". It's a very easthetically pleasing curve and you'll find it in quite a few graphics packages like ",r.createElement("a",{href:"https://fontforge.github.io"},"FontForge")," and ",r.createElement("a",{href:"https://inkscape.org"},"Inkscape"),", having even been used in font design (such as for the Inconsolata font)."))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(223),a=r.createClass({displayName:"Matrix",getDefaultProps:function(){return{title:"Bézier curvatures as matrix operations"}},render:function(){return r.createElement("section",null,r.createElement(i,this.props),r.createElement("p",null,"We can also represent Bézier as matrix operations, by expressing the Bézier formula as a polynomial basis function, the weight matrix, and the actual coordinates as matrix. Let's look at what this means for the cubic curve :"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d961171d6d1dfc22bb1756901e79102147914360.svg",style:{width:"31.12515rem",height:"1.20015rem"}})),r.createElement("p",null,"Disregarding our actual coordinates for a moment, we have:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/f925c339011e6c38e47b9c3a571e02fca80eb5c3.svg",style:{width:"23.475150000000003rem",height:"1.20015rem"}})),r.createElement("p",null,"We can write this as a sum of four expressions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/30d76165668bf15f62986503bea100f39c5b9fec.svg",style:{width:"10.42515rem",height:"5.8500000000000005rem"}})),r.createElement("p",null,"And we can expand these expressions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/7ca5abe1124ba1e51b7f12e0469cb4b1407593b8.svg",style:{width:"27.82485rem",height:"5.8500000000000005rem"}})),r.createElement("p",null,"Furthermore, we can make all the 1 and 0 factors explicit:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/bccbb94942e3ff79579e4719106f4701c157727e.svg",style:{width:"15.67485rem",height:"5.625rem"}})),r.createElement("p",null,"And ",r.createElement("em",null,"that"),", we can view as a series of four matrix operations:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d5f85d80fbbc62e1e8d58621b76f3d0224876b62.svg",style:{width:"45.225rem",height:"5.47515rem"}})),r.createElement("p",null,"If we compact this into a single matrix operation, we get:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/7140be48f45b2e7190fa8dffef5c05c47c038ab0.svg",style:{width:"16.875rem",height:"5.47515rem"}})),r.createElement("p",null,"This kind of polynomial basis representation is generally written with the bases in increasing order, which means we need to flip our ",r.createElement("em",null,"t"),' matrix horizontally, and our big "mixing" matrix upside down:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/4e1849950a5c13f5135aa3412e0ee634cdc67301.svg",style:{width:"16.875rem",height:"5.47515rem"}})),r.createElement("p",null,"And then finally, we can add in our original coordinates as a single third matrix:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/5910e25a46d9e86ab34513017f1274628a40e5a7.svg",style:{width:"23.925150000000002rem",height:"5.47515rem"}})),r.createElement("p",null,"We can perform the same trick for the quadratic curve, in which case we end up with:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/e56e78e406d625c2a5ec584216f79a5fee00d8ea.svg",style:{width:"19.65015rem",height:"3.97485rem"}})),r.createElement("p",null,"If we plug in a ",r.createElement("em",null,"t")," value, and then multiply the matrices, we will get exactly the same values as when we evaluate the original polynomial function, or as when we evaluate the curve using progessive linear interpolation."),r.createElement("p",null,r.createElement("strong",null,"So: why would we bother with matrices?")," Matrix representations allow us to discover things about functions that would otherwise be hard to tell. It turns out that the curves form ",r.createElement("a",{href:"https://en.wikipedia.org/wiki/Triangular_matrix"},"triangular matrices"),", and they have a determinant equal to the product of the actual coordinates we use for our curve. It's also invertible, which means there's",r.createElement("a",{href:"https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theorem"},"a ton of properties")," that are all satisfied. Of course, the main question is: \"Why is this useful to us, now?\", and the answer to that is that it's not immediately useful, but you'll be seeing some instances where certain curve properties can be either computed via function manipulation, or via clever use of matrices, and sometimes the matrix approach can be (drastically) faster."),r.createElement("p",null,"So for now, just remember that we can represent curves this way, and let's move on."))}});e.exports=a},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"deCasteljau",getDefaultProps:function(){return{title:"de Casteljau's algorithm"}},setup:function(e){var t=[{x:90,y:110},{x:25,y:40},{x:230,y:40},{x:150,y:240}];e.setCurve(new e.Bezier(t))},draw:function(e,t){if(e.reset(),e.drawSkeleton(t),e.drawCurve(t),e.hover){e.setColor("rgb(200,100,100)");for(var n=e.getPanelWidth(),r=e.hover.x/n,i=e.drawHull(t,r),a=4;8>=a;a++)e.drawCircle(i[a],3);var o=t.get(r);e.drawCircle(o,5),e.setFill("black"),e.drawCircle(o,3);var s=100*r|0;r=s/100,e.text("Sequential interpolation for "+s+"% (t="+r+")",{x:10,y:15})}},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"If we want to draw Bézier curves we can run through all values of ",r.createElement("i",null,"t")," from 0 to 1 and then compute the weighted basis function, getting the ",r.createElement("i",null,"x"),"/",r.createElement("i",null,"y"),' values we need to plot, but the more complex the curve gets, the more expensive this becomes. Instead, we can use "de Casteljau\'s algorithm" to draw curves, which is a geometric approach to drawing curves, and really easy to implement. So easy, in fact, you can do it by hand with a pencil and ruler.'),r.createElement("p",null,"Rather than using our calculus function to find ",r.createElement("i",null,"x"),"/",r.createElement("i",null,"y")," values for ",r.createElement("i",null,"t"),", let's do this instead:"),r.createElement("ul",null,r.createElement("li",null,"treat ",r.createElement("i",null,"t")," as a ratio (which it is). t=0 is 0% along a line, t=1 is 100% along a line."),r.createElement("li",null,"Take all lines between the curve's defining points. For an order ",r.createElement("i",null,"n")," curve, that's ",r.createElement("i",null,"n")," lines."),r.createElement("li",null,"Place markers along each of these line, at distance ",r.createElement("i",null,"t"),". So if ",r.createElement("i",null,"t")," is 0.2, place the mark at 20% from the start, 80% from the end."),r.createElement("li",null,"Now form lines between ",r.createElement("i",null,"those")," points. This gives ",r.createElement("i",null,"n-1")," lines."),r.createElement("li",null,"Place markers along each of these line at distance ",r.createElement("i",null,"t"),"."),r.createElement("li",null,"Form lines between ",r.createElement("i",null,"those")," points. This'll be ",r.createElement("i",null,"n-2")," lines."),r.createElement("li",null,"place markers, form lines, place markers, etc."),r.createElement("li",null,"repeat this until you have only one line left. The point ",r.createElement("i",null,"t")," on that line coincides with the original curve point at ",r.createElement("i",null,"t"),".")),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"How to implement de Casteljau's algorithm"),r.createElement("p",null,"Let's just use the algorithm we just specified, and implement that:"),r.createElement("pre",null,"function drawCurve(points[], t):","\n"," if(points.length==1):","\n"," draw(points[0])","\n"," else:","\n"," newpoints=array(points.size-1)","\n"," for(i=0; ia;a+=r)n=t.get(Math.min(a,1)),e.setColor("red"),e.drawLine(i,n),i=n;e.setFill("black"),e.text("Curve approximation using "+e.steps+" segments",{x:10,y:15})},values:{38:1,40:-1},onKeyDown:function(e,t){var n=this.values[e.keyCode];n&&(e.preventDefault(),t.steps+=n,t.steps<1&&(t.steps=1))},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'We can also simplify the drawing process by "sampling" the curve at certain points, and then joining those points up with straight lines, a process known as "flattening", as we are reducing a curve to a simple sequence of straight, "flat" lines.'),r.createElement("p",null,'We can do this is by saying "we want X segments", and then sampling the curve at intervals that are spaced such that we end up with the number of segments we wanted. The advantage of this method is that it\'s fast: instead of evaluating 100 or even 1000 curve coordinates, we can sample a much lower number and still end up with a curve that sort-of-kind-of looks good enough. The disadvantage of course is that we lose the precision of working with "the real curve", so we usually can\'t use the flattened for for doing true intersection detection, or curvature alignment.'),r.createElement(i,{preset:"twopanel",title:"Flattening a quadratic curve",setup:this.setupQuadratic,draw:this.drawFlattened,onKeyDown:this.onKeyDown}),r.createElement(i,{preset:"twopanel",title:"Flattening a cubic curve",setup:this.setupCubic,draw:this.drawFlattened,onKeyDown:this.onKeyDown}),r.createElement("p",null,"Try clicking on the sketch and using your up and down arrow keys to lower the number of segments for both the quadratic and cubic curve. You'll notice that for certain curvatures, a low number of segments works quite well, but for more complex curvatures (try this for the cubic curve), a higher number is required to capture the curvature changes properly."),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"How to implement curve flattening"),r.createElement("p",null,"Let's just use the algorithm we just specified, and implement that:"),r.createElement("pre",null,"function flattenCurve(curve, segmentCount):","\n"," step = 1/segmentCount;","\n"," coordinates = [curve.getXValue(0), curve.getYValue(0)]","\n"," for(i=1; i <= segmentCount; i++):","\n"," t = i*step;","\n"," coordinates.push[curve.getXValue(t), curve.getYValue(t)]","\n"," return coordinates;"),r.createElement("p",null,'And done, that\'s the algorithm implemented. That just leaves drawing the resulting "curve" as a sequence of lines:'),r.createElement("pre",null,"function drawFlattenedCurve(curve, segmentCount):","\n"," coordinates = flattenCurve(curve, segmentCount)","\n"," coord = coordinates[0], _coords;","\n"," for(i=1; i < coordinates.length; i++):","\n"," _coords = coordinates[i]","\n"," line(coords, _coords)","\n"," coords = _coords"),r.createElement("p",null,"We start with the first coordinate as reference point, and then just draw lines between each point and its next point.")))}});e.exports=o(s)},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Splitting",getDefaultProps:function(){return{title:"Splitting curves"}},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t),e.forward=!0},drawSplit:function(e,t){e.setPanelCount(2),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n={x:0,y:0},r=.5,i=t.get(.5),a=t.split(r);e.drawCurve(a.left),e.drawCurve(a.right),e.setColor("red"),e.drawCircle(i,3),e.setColor("black"),n.x=e.getPanelWidth(),e.drawLine({x:0,y:0},{x:0,y:e.getPanelHeight()},n),e.setColor("lightgrey"),e.drawCurve(t,n),e.drawCircle(i,4),n.x-=20,n.y-=20,e.drawSkeleton(a.left,n,!0),e.drawCurve(a.left,n),n.x+=40,n.y+=40,e.drawSkeleton(a.right,n,!0),e.drawCurve(a.right,n)},drawAnimated:function(e,t){e.setPanelCount(3),e.reset();var n=e.getFrame(),r=5*e.getPlayInterval(),i=n%r/r,a=r>n%(2*r);a?i%=1:i=1-i%1;var o={x:0,y:0};e.setColor("lightblue"),e.drawHull(t,i),e.drawSkeleton(t),e.drawCurve(t);var s=t.get(i);e.drawCircle(s,4),e.setColor("black"),o.x+=e.getPanelWidth(),e.drawLine({x:0,y:0},{x:0,y:e.getPanelHeight()},o);var l=t.split(i);e.setColor("lightgrey"),e.drawCurve(t,o),e.drawHull(t,i,o),e.setColor("black"),e.drawCurve(l.left,o),e.drawPoints(l.left.points,o),e.setFill("black"),e.text("Left side of curve split at t = "+(100*i|0)/100,{x:10+o.x,y:15+o.y}),o.x+=e.getPanelWidth(),e.drawLine({x:0,y:0},{x:0,y:e.getPanelHeight()},o),e.setColor("lightgrey"),e.drawCurve(t,o),e.drawHull(t,i,o),e.setColor("black"),e.drawCurve(l.right,o),e.drawPoints(l.right.points,o),e.setFill("black"),e.text("Right side of curve split at t = "+(100*i|0)/100,{x:10+o.x,y:15+o.y})},togglePlay:function(e,t){t.playing?t.pause():t.play()},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"With de Casteljau's algorithm we also find all the points we need to split up a Bézier curve into two, smaller curves, which taken together form the original curve. When we construct de Casteljau's skeleton for some value",r.createElement("i",null,"t"),", the procedure gives us all the points we need to split a curve at that ",r.createElement("i",null,"t")," value: one curve is defined by all the inside skeleton points found prior to our on-curve point, with the other curve being defined by all the inside skeleton points after our on-curve point."),r.createElement(i,{title:"Splitting a curve",setup:this.setupCubic,draw:this.drawSplit}),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"implementing curve splitting"),r.createElement("p",null,"We can implement curve splitting by bolting some extra logging onto the de Casteljau function:"),r.createElement("pre",null,"left=[]","\n","right=[]","\n","function drawCurve(points[], t):","\n"," if(points.length==1):","\n"," left.add(points[0])","\n"," right.add(points[0])","\n"," draw(points[0])","\n"," else:","\n"," newpoints=array(points.size-1)","\n"," for(i=0; ii;i++)t.push({x:n/2+20*Math.random()+Math.cos(2*Math.PI*i/10)*(n/2-40),y:r/2+20*Math.random()+Math.sin(2*Math.PI*i/10)*(r/2-40)});var a=new e.Bezier(t);e.setCurve(a)},draw:function(e,t){e.reset();var n=t.points;this.setState({order:n.length});for(var r=n[0],i=0;1>=i;i+=.01){for(var a=JSON.parse(JSON.stringify(n));a.length>1;){for(var o=0;o=n;n++)r=n/10,i=t.get(r),a=t.derivative(r),s=Math.sqrt(a.x*a.x+a.y*a.y),a={x:a.x/s,y:a.y/s},o=t.normal(r),e.setColor("blue"),e.drawLine(i,{x:i.x+a.x*l,y:i.y+a.y*l}),e.setColor("red"),e.drawLine(i,{x:i.x+o.x*l,y:i.y+o.y*l}),e.setColor("black"),e.drawCircle(i,3)},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'If you want to move objects along a curve, or "away from" a curve, the two vectors you\'re most interested in are the tangent vector and normal vector for curve points. These are actually really easy to find. For moving, and orienting, along a curve we use the tangent, which indicates the direction travel at specific points, and is literally just the first derivative of our curve:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/2271ae26977a681a1695d14ea8255564e716916e.svg",style:{width:"10.35rem",height:"2.77515rem"}})),r.createElement("p",null,"This gives us the directional vector we want. We can normalize it to give us uniform directional vectors (having a length of 1.0) at each point, and then do whatever it is we want to do based on those directions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/3cb2c4f5806142e83c66e1312520d0783d15201c.svg",style:{width:"17.62515rem",height:"2.025rem"}})),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/72826b8f5053c299dbb2082678191e3564bb50a6.svg",style:{width:"20.62485rem",height:"4.7250000000000005rem"}})),r.createElement("p",null,"The tangent is very useful for moving along a line, but what if we want to move away from the curve instead, perpendicular to the curve at some point ",r.createElement("i",null,"t"),'? In that case we want the "normal" vector. This vector runs at a right angle to the direction of the curve, and is typically of length 1.0, so all we have to do is rotate the normalized directional vector and we\'re done:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/6cb29c325e059e236343bdd448c149ecc6d8795f.svg",style:{width:"22.800150000000002rem",height:"4.57515rem"}})),r.createElement("div",{className:"note"},r.createElement("p",null,'Rotating coordinates is actually very easy, if you know the rule for it. You might find it explained as "applying a ',r.createElement("a",{href:"https://en.wikipedia.org/wiki/Rotation_matrix"},"rotation matrix"),'", which is what we\'ll look at here, too. Essentially, the idea is to take the circles over which we can rotate, and simply "sliding the coordinates" over those circles by the desired angle. If we want a quarter circle turn, we take the coordinate, slide it along the cirle by a quarter turn, and done.'),r.createElement("p",null,"To turn any point ",r.createElement("i",null,"(x,y)")," into a rotated point ",r.createElement("i",null,"(x',y')")," (over 0,0) by some angle φ, we apply this nicely easy computation:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d3932ac925ad9f238029d888dc5432f6678f6491.svg",style:{width:"12.225150000000001rem",height:"2.84985rem"}})),r.createElement("p",null,'Which is the "long" version of the following matrix transformation:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/7297632eb150a8f5f37178612f71e5d0f2c367b1.svg",style:{width:"15.150150000000002rem",height:"2.77515rem"}})),r.createElement("p",null,"And that's all we need to rotate any coordinate. Note that for quarter, half and three quarter turns these functions become even easier, since ",r.createElement("i",null,"sin")," and",r.createElement("i",null,"cos")," for these angles are, respectively: 0 and 1, -1 and 0, and 0 and -1."),r.createElement("p",null,"But ",r.createElement("strong",null,r.createElement("em",null,"why"))," does this work? Why this matrix multiplication?",r.createElement("a",{href:"http://en.wikipedia.org/wiki/Rotation_matrix#Decomposition_into_shears"},"wikipedia"),"(Technically, Thomas Herter and Klaus Lott) tells us that a rotation matrix can be treated as a sequence of three (elementary) shear operations. When we combine this into a single matrix operation (because all matrix multiplications can be collapsed), we get the matrix that you see above.",r.createElement("a",{href:"http://datagenetics.com/blog/august32013/index.html"},"DataGenetics")," have an excellent article about this very thing: it's really quite cool, and I strongly recommend taking a quick break from this primer to read that article.")),r.createElement("p",null,"The following two graphics show the tangent and normal along a quadratic and cubic curve, with the direction vector coloured blue, and the normal vector coloured red (the markers are spaced out evenly as ",r.createElement("i",null,"t"),"-intervals, not spaced equidistant)."),r.createElement("div",{className:"figure"},r.createElement(i,{preset:"simple",title:"Quadratic Bézier tangents and normals",inline:!0,setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"simple",title:"Cubic Bézier tangents and normals",inline:!0,setup:this.setupCubic,draw:this.draw})))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Components",getDefaultProps:function(){return{title:"Component functions"}},setupQuadratic:function(e){var t=e.getDefaultQuadratic();t.points[2].x=210,e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.setPanelCount(3),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=t.order+1,r=20,i=t.points,a=e.getPanelWidth(),o=e.getPanelHeight(),s={x:a,y:0},l=JSON.parse(JSON.stringify(i)).map(function(e,t){return{x:a*t/n,y:e.x}});e.drawLine({x:0,y:0},{x:0,y:o},s),e.drawAxes(r,"t",0,1,"x",0,a,s),s.x+=r,e.drawCurve(new e.Bezier(l),s),s.x+=a-r;var u=JSON.parse(JSON.stringify(i)).map(function(e,t){return{x:a*t/n,y:e.y}});e.drawLine({x:0,y:0},{x:0,y:o},s),e.drawAxes(r,"t",0,1,"y",0,a,s),s.x+=r,e.drawCurve(new e.Bezier(u),s)},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'One of the first things people run into when they start using Bézier curves in their own programs is "I know how to draw the curve, but how do I determine the bounding box?". It\'s actually reasonably straight forward to do so, but it requires having some knowledge on exploiting math to get the values we need. For bounding boxes, we aren\'t actually interested in the curve itself, but only in its "extremities": the minimum and maximum values the curve has for its x- and y-axis values. If you remember your calculus (provided you ever took calculus, otherwise it\'s going to be hard to remember) we can determine function extremities using the first derivative of that function, but this poses a problem, since our function is parametric: every axis has its own function.'),r.createElement("p",null,"The solution: compute the derivative for each axis separately, and then fit them back together in the same way we do for the original."),r.createElement("p",null,'Let\'s look at how a parametric Bézier curve "splits up" into two normal functions, one for the x-axis and one for the y-axis. Note the left-most figure is again an interactive curve, without labeled axes (you get coordinates in the graph instead). The center and right-most figures are the component functions for computing the x-axis value, given a value for ',r.createElement("i",null,"t")," (between 0 and 1 inclusive), and the y-axis value, respectively."),r.createElement("p",null,"If you move points in a curve sideways, you should only see the middle graph change; likely, moving points vertically should only show a change in the right graph."),r.createElement(i,{preset:"simple",title:"Quadratic Bézier curve components",setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"simple",title:"Cubic Bézier curve components",setup:this.setupCubic,draw:this.draw}))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Extremities",getDefaultProps:function(){return{title:"Finding extremities: root finding"}},setupQuadratic:function(e){var t=e.getDefaultQuadratic();t.points[2].x=210,e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.setPanelCount(3),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=t.order+1,r=20,i=t.points,a=e.getPanelWidth(),o=e.getPanelHeight(),s={x:a,y:0},l=JSON.parse(JSON.stringify(i)).map(function(e,t){return{x:a*t/n,y:e.x}});e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:o},s),e.drawAxes(r,"t",0,1,"x",0,a,s),s.x+=r;var u=new e.Bezier(l);e.drawCurve(u,s),e.setColor("red"),u.extrema().y.forEach(function(t){var n=u.get(t);e.drawCircle(n,3,s)}),s.x+=a-r;var c=JSON.parse(JSON.stringify(i)).map(function(e,t){return{x:a*t/n,y:e.y}});e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:o},s),e.drawAxes(r,"t",0,1,"y",0,a,s),s.x+=r;var h=new e.Bezier(c);e.drawCurve(h,s),e.setColor("red"),h.extrema().y.forEach(function(t){var n=h.get(t);e.drawCircle(n,3,s)})},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"Now that we understand (well, superficially anyway) the component functions, we can find the extremities of our Bézier curve by finding maxima and minima on the component functions, by solving the equations B'(t) = 0 and B''(t) = 0. Although, in the case of quadratic curves there is no B''(t), so we only need to compute B'(t) = 0. So, how do we compute the first and second derivatives? Fairly easily, actually, until our derivatives are 4th order or higher... then things get really hard. But let's start simple:"),r.createElement("h3",null,"Quadratic curves: linear derivatives."),r.createElement("p",null,'Finding the solution for "where is this line 0" should be trivial:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/9929fd19d54366db382b7d453491d90f894352a7.svg",style:{width:"9.450000000000001rem",height:"6.37515rem"}})),r.createElement("p",null,"Done. And quadratic curves have no meaningful second derivative, so we're ",r.createElement("em",null,"really")," done."),r.createElement("h3",null,"Cubic curves: the quadratic formula."),r.createElement("p",null,"The derivative of a cubic curve is a quadratic curve, and finding the roots for a quadratic Bézier curve means we can apply the ",r.createElement("a",{href:"https://en.wikipedia.org/wiki/Quadratic_formula"},"Quadratic formulat"),". If you've seen it before, you'll remember it, and if you haven't, it looks like this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d5882cc83b002196c8e701ad273ced103e2b4484.svg",style:{width:"28.72485rem",height:"2.475rem"}})),r.createElement("p",null,"So, if we can express a Bézier component function as a plain polynomial, we're done: we just plug in the values into the quadratic formula, check if that square root is negative or not (if it is, there are no roots) and then just compute the two values that come out (because of that plus/minus sign we get two). Any value between 0 and 1 is a root that matters for Bézier curves, anything below or above that is irrelevant (because Bézier curves are only defined over the interval [0,1]). So, how do we convert?"),r.createElement("p",null,"First we turn our cubic Bézier function into a quadratic one, by following the rule mentioned at the end of the ",r.createElement("a",{href:"#derivatives"},"derivatives section"),":"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d904e86a3967e7e5bdba8a5f6b943a8fde3ad458.svg",style:{width:"45rem",height:"2.77515rem"}})),r.createElement("p",null,"And then, using these ",r.createElement("em",null,"v")," values, we can find out what our ",r.createElement("em",null,"a"),", ",r.createElement("em",null,"b"),", and ",r.createElement("em",null,"c")," should be:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/c638a85a950ffb535fbf2056958bed5f44be5067.svg",style:{width:"21.375rem",height:"7.2rem"}})),r.createElement("p",null,"So we can find the roots by using:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/076b74a0f2bcb43a3b2d39fdc52c58c6f89ce33a.svg",style:{width:"20.84985rem",height:"3.97485rem"}})),r.createElement("p",null,"Easy peasy. We also note that the second derivative of a cubic curve means computing the first derivative of a quadratic curve, and we just saw how to do that in the section above."),r.createElement("h3",null,"Quartic curves: Cardano's algorithm."),r.createElement("p",null,"Quartic—fourth degree—curves have a cubic function as derivative. Now, cubic functions are a bit of a problem because they're really hard to solve. But, way back in the 16",r.createElement("sup",null,"th")," century, ",r.createElement("a",{ href:"https://en.wikipedia.org/wiki/Gerolamo_Cardano"},"Gerolamo Cardano"),' figured out that even if the general cubic function is really hard to solve, it can be rewritten to a form for which finding the roots is "easy", and then the only hard part is figuring out how to go from that form to the generic form. So:'),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/a16a0da87e138b1307973397275c296eb475b1b1.svg",style:{width:"45rem",height:"2.77515rem"}})),r.createElement("p",null,'This is easier because for the "easier formula" we can use ',r.createElement("a",{href:"http://www.wolframalpha.com/input/?i=t^3+%2B+pt+%2B+q"},"regular calculus")," to find the roots (as a cubic function, however, it can have up to three roots, but two of those can be complex. For the purpose of Bézier curve extremities, we can completely ignore those complex roots, since our ",r.createElement("em",null,"t")," is a plain real number from 0 to 1)."),r.createElement("p",null,"So, the trick is to figure out how to turn the first formula into the second formula, and to then work out the maths that gives us the roots. This is explained in detail over at ",r.createElement("a",{href:"http://www.trans4mind.com/personal_development/mathematics/polynomials/cubicAlgebra.htm"},"Ken J. Ward's page")," for solving the cubic equation, so instead of showing the maths, I'm simply going to show the programming code for solving the cubic equation, with the complex roots getting totally ignored."),r.createElement("div",{className:"howtocode"},r.createElement("h3",null,"Implementing Cardano's algorithm for finding all real roots"),r.createElement("p",null,'The "real roots" part is fairly important, because while you cannot take a square, cube, etc. root of a negative number in the "real" number space (denoted with ℝ), this is perfectly fine in the ',r.createElement("a",{href:"https://en.wikipedia.org/wiki/Complex_number"},'"complex" number')," space (denoted with ℂ). And, as it so happens, Cardano is also attributed as the first mathematician in history to have made use of complex numbers in his calculations. For this very algorithm!"),r.createElement("pre",null,"// A helper function to filter for values in the [0,1] interval:","\n","function accept(t) ","{","\n"," return 0<=t && t <=1;","\n","}","\n","\n","// A real-cuberoots-only function:","\n","function crt(v) ","{","\n"," if(v<0) return -Math.pow(-v,1/3);","\n"," return Math.pow(v,1/3);","\n","}","\n","\n","// Now then: given cubic coordinates ","{","pa, pb, pc, pd","}"," find all roots.","\n","function getCubicRoots(pa, pb, pc, pd) ","{","\n"," var d = (-pa + 3*pb - 3*pc + pd),","\n"," a = (3*pa - 6*pb + 3*pc) / d,","\n"," b = (-3*pa + 3*pb) / d,","\n"," c = pa / d;","\n","\n"," var p = (3*b - a*a)/3,","\n"," p3 = p/3,","\n"," q = (2*a*a*a - 9*a*b + 27*c)/27,","\n"," q2 = q/2,","\n"," discriminant = q2*q2 + p3*p3*p3;","\n","\n"," // and some variables we're going to use later on:","\n"," var u1,v1,root1,root2,root3;","\n","\n"," // three possible real roots:","\n"," if (discriminant < 0) ","{","\n"," var mp3 = -p/3,","\n"," mp33 = mp3*mp3*mp3,","\n"," r = sqrt( mp33 ),","\n"," t = -q / (2*r),","\n"," cosphi = t<-1 ? -1 : t>1 ? 1 : t,","\n"," phi = acos(cosphi),","\n"," crtr = cuberoot(r),","\n"," t1 = 2*crtr;","\n"," root1 = t1 * cos(phi/3) - a/3;","\n"," root2 = t1 * cos((phi+2*pi)/3) - a/3;","\n"," root3 = t1 * cos((phi+4*pi)/3) - a/3;","\n"," return [root1, root2, root3].filter(accept);","\n"," ","}","\n","\n"," // three real roots, but two of them are equal:","\n"," else if(discriminant === 0) ","{","\n"," u1 = q2 < 0 ? cuberoot(-q2) : -cuberoot(q2);","\n"," root1 = 2*u1 - a/3;","\n"," root2 = -u1 - a/3;","\n"," return [root1, root2].filter(accept);","\n"," ","}","\n","\n"," // one real root, two complex roots","\n"," else ","{","\n"," var sd = sqrt(discriminant);","\n"," u1 = cuberoot(sd - q2);","\n"," v1 = cuberoot(sd + q2);","\n"," root1 = u1 - v1 - a/3;","\n"," return [root1].filter(accept);","\n"," ","}","\n","}")),r.createElement("p",null,'And that\'s it. The maths is complicated, but the code is pretty much just "follow the maths, while caching as many values as we can to reduce recomputing things as much as possible" and now we have a way to find all roots for a cubic function and can just move on with using that to find extremities of our curves.'),r.createElement("h3",null,"Quintic and higher order curves: finding numerical solutions"),r.createElement("p",null,"The problem with this is that as the order of the curve goes up, we can't actually solve those equations the normal way. We can't take the function, and then work out what the solutions are. Not to mention that even solving a third order derivative (for a fourth order curve) is already a royal pain in the backside. We need a better solution. We need numerical approaches."),r.createElement("p",null,'That\'s a fancy word for saying "rather than solve the function, treat the problem as a sequence of identical operations, the performing of which gets us closer and closer to the real answer". As it turns out, there is a really nice numerical root finding algorithm, called the ',r.createElement("a",{href:"http://en.wikipedia.org/wiki/Newton-Raphson"},"Newton-Raphson")," root finding method (yes, after ",r.createElement("em",null,r.createElement("a",{href:"https://en.wikipedia.org/wiki/Isaac_Newton"},"that"))," Newton), which we can make use of."),r.createElement("p",null,"The Newton-Raphson approach consists of picking a value ",r.createElement("i",null,"t")," (any will do), and getting the corresponding value at that ",r.createElement("i",null,"t")," value. For normal functions, we can treat that value as a height. If the height is zero, we're done, we have found a root. If it's not, we take the tangent of the curve at that point, and extend it until it passes the x-axis, which will be at some new point ",r.createElement("i",null,"t"),". We then repeat the procedure with this new value, and we keep doing this until we find our root."),r.createElement("p",null,"Mathematically, this means that for some ",r.createElement("i",null,"t"),", at step ",r.createElement("i",null,"n=1"),", we perform the following calculation until ",r.createElement("i",null,"f",r.createElement("sub",null,"y")),"(",r.createElement("i",null,"t"),") is zero, so that the next ",r.createElement("i",null,"t")," is the same as the one we already have:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/b563256be7016370365935944308cf878cdbc29c.svg",style:{width:"8.625150000000001rem",height:"2.9250000000000003rem"}})),r.createElement("p",null,"(The wikipedia article has a decent animation for this process, so I'm not adding a sketch for that here)"),r.createElement("p",null,"Now, this works well only if we can pick good starting points, and our curve is continuously differentiable and doesn't have oscillations. Glossing over the exact meaning of those terms, the curves we're dealing with conform to those constraints, so as long as we pick good starting points, this will work. So the question is: which starting points do we pick?"),r.createElement("p",null,"As it turns out, Newton-Raphson is so blindingly fast, so we could get away with just not picking: we simply run the algorithm from ",r.createElement("i",null,"t=0")," to ",r.createElement("i",null,"t=1")," at small steps (say, 1/200",r.createElement("sup",null,"th"),") and the result will be all the roots we want. Of course, this may pose problems for high order Bézier curves: 200 steps for a 200",r.createElement("sup",null,"th")," order Bézier curve is going to go wrong, but that's okay: there is no reason, ever, to use Bézier curves of crazy high orders. You might use a fifth order curve to get the \"nicest still remotely workable\" approximation of a full circle with a single Bézier curve, that's pretty much as high as you'll ever need to go."),r.createElement("h3",null,"In conclusion:"),r.createElement("p",null,"So now that we know how to do root finding, we can determine the first and second derivative roots for our Bézier curves, and show those roots overlaid on the previous graphics:"),r.createElement(i,{preset:"simple",title:"Quadratic Bézier curve extremities",setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"simple",title:"Cubic Bézier curve extremities",setup:this.setupCubic,draw:this.draw}))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"BoundingBox",getDefaultProps:function(){return{title:"Bounding boxes"}},setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.reset(),e.setColor("#00FF00"),e.drawbbox(t.bbox()),e.setColor("black"),e.drawSkeleton(t),e.drawCurve(t)},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"If we have the extremities, and the start/end points, a simple for loop that tests for min/max values for x and y means we have the four values we need to box in our curve:"),r.createElement("p",null,r.createElement("i",null,"Computing the bounding box for a Bézier curve"),":"),r.createElement("ol",null,r.createElement("li",null,"Find all ",r.createElement("i",null,"t")," value(s) for the curve derivative's x- and y-roots."),r.createElement("li",null,"Discard any ",r.createElement("i",null,"t")," value that's lower than 0 or higher than 1, because Bézier curves only use the interval [0,1]."),r.createElement("li",null,"Determine the lowest and highest value when plugging the values ",r.createElement("i",null,"t=0"),", ",r.createElement("i",null,"t=1")," and each of the found roots into the original functions: the lowest value is the lower bound, and the highest value is the upper bound for the bounding box we want to construct.")),r.createElement("p",null,"Applying this approach to our previous root finding, we get the following bounding boxes (with curve extremities coloured the same as in the root finding graphics):"),r.createElement(i,{preset:"simple",title:"Quadratic Bézier bounding box",setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"simple",title:"Cubic Bézier bounding box",setup:this.setupCubic,draw:this.draw}),r.createElement("p",null,"We can construct even nicer boxes by aligning them along our curve, rather than along the x- and y-axis, but in order to do so we first need to look at how aligning works."))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Aligning",getDefaultProps:function(){return{title:"Aligning curves"}},setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},align:function(e,t){var n=t.p1.x,r=t.p1.y,i=-Math.atan2(t.p2.y-r,t.p2.x-n),a=Math.cos,o=Math.sin,s=function(e){return{x:(e.x-n)*a(i)-(e.y-r)*o(i),y:(e.x-n)*o(i)+(e.y-r)*a(i)}};return e.map(s)},draw:function(e,t){e.setPanelCount(2),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=t.points,r={p1:n[0],p2:n[n.length-1]},i=this.align(n,r),a=new e.Bezier(i),o=e.getPanelWidth(),s=e.getPanelHeight(),l={x:o,y:0};e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:s},l),l.x+=o/4,l.y+=s/2,e.setColor("grey"),e.drawLine({x:0,y:-s/2},{x:0,y:s/2},l),e.drawLine({x:-o/4,y:0},{x:o,y:0},l),e.setFill("grey"),e.setColor("black"),e.drawSkeleton(a,l),e.drawCurve(a,l)},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'While there are an incredible number of curves we can define by varying the x- and y-coordinates for the control points, not all curves are actually distinct. For instance, if we define a curve, and then rotate it 90 degrees, it\'s still the same curve, and we\'ll find its extremities in the same spots, just at different draw coordinates. As such, one way to make sure we\'re working with a "unique" curve is to "axis-align" it.'),r.createElement("p",null,"Aligning also simplifies a curve's functions. We can translate (move) the curve so that the first point lies on (0,0), which turns our ",r.createElement("i",null,"n")," term polynomial functions into ",r.createElement("i",null,"n-1")," term functions. The order stays the same, but we have less terms. Then, we can rotate the curves so that the last point always lies on the x-axis, too, making its coordinate (...,0). This further simplifies the function for the y-component to an ",r.createElement("i",null,"n-2")," term function. For instance, if we have a cubic curve such as this:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d253dc7ff011a8ae46f3351975f1d4beedd7a794.svg",style:{width:"34.12485rem",height:"2.77515rem"}})),r.createElement("p",null,"Then translating it so that the first coordinate lies on (0,0), moving all ",r.createElement("i",null,"x")," coordinates by -120, and all ",r.createElement("i",null,"y")," coordinates by -160, gives us:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/b3ec747086a146c1b2c682afea6b1eae016c9a7a.svg",style:{width:"33.075rem",height:"2.77515rem"}})),r.createElement("p",null,"If we then rotate the curve so that its end point lies on the x-axis, the coordinates (integer-rounded for illustrative purposes here) become:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/fd82fad845da25b074dff33bbc4aa563d5f367a7.svg",style:{width:"32.54985rem",height:"2.77515rem"}})),r.createElement("p",null,"If we drop all the zero-terms, this gives us:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/b4d6e220358b2d00f0cf516f433fbe5ecb58f25d.svg",style:{width:"25.79985rem",height:"2.77515rem"}})),r.createElement("p",null,"We can see that our original curve definition has been simplified considerably. The following graphics illustrate the result of aligning our example curves to the x-axis, with the cubic case using the coordinates that were just used in the example formulae:"),r.createElement(i,{preset:"twopanel",title:"Aligning a quadratic curve",setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"twopanel",title:"Aligning a cubic curve",setup:this.setupCubic,draw:this.draw}))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"TightBounds",getDefaultProps:function(){return{title:"Tight boxes"}},setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},align:function(e,t){var n=t.p1.x,r=t.p1.y,i=-Math.atan2(t.p2.y-r,t.p2.x-n),a=Math.cos,o=Math.sin,s=function(e){return{x:(e.x-n)*a(i)-(e.y-r)*o(i),y:(e.x-n)*o(i)+(e.y-r)*a(i),a:i}};return e.map(s)},transpose:function(e,t,n){var r=n.x,i=n.y,a=Math.cos,o=Math.sin,s=[e.x.min,e.y.min,e.x.max,e.y.max];return[{x:s[0],y:s[1]},{x:s[2],y:s[1]},{x:s[2],y:s[3]},{x:s[0],y:s[3]}].map(function(e){var n=e.x,s=e.y;return{x:n*a(t)-s*o(t)+r,y:n*o(t)+s*a(t)+i}})},draw:function(e,t){e.reset();var n=t.points,r={p1:n[0],p2:n[n.length-1]},i=this.align(n,r),a=-i[0].a,o=new e.Bezier(i),s=o.bbox(),l=this.transpose(s,a,n[0]);e.setColor("#00FF00"),e.drawLine(l[0],l[1]),e.drawLine(l[1],l[2]),e.drawLine(l[2],l[3]),e.drawLine(l[3],l[0]),e.setColor("black"),e.drawSkeleton(t),e.drawCurve(t)},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,'With our knowledge of bounding boxes, and curve alignment, We can now form the "tight" bounding box for curves. We first align our curve, recording the translation we performed, "T", and the rotation angle we used, "R". We then determine the aligned curve\'s normal bounding box. Once we have that, we can map that bounding box back to our original curve by rotating it by -R, and then translating it by -T. We now have nice tight bounding boxes for our curves:'),r.createElement(i,{preset:"twopanel",title:"Aligning a quadratic curve",setup:this.setupQuadratic,draw:this.draw}),r.createElement(i,{preset:"twopanel",title:"Aligning a cubic curve",setup:this.setupCubic,draw:this.draw}),r.createElement("p",null,"These are, strictly speaking, not necessarily the tightest possible bounding boxes. It is possible to compute the optimal bounding box by determining which spanning lines we need to effect a minimal box area, but because of the parametric nature of Bézier curves this is actually a rather costly operation, and the gain in bounding precision is often not worth it. If there is high demand for it, I'll add a section on how to precisely compute the best fit bounding box, but the maths is fairly gruelling and just not really worth spending time on."))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"ABC",getDefaultProps:function(){return{title:"Curve inflections"}},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t),t.inflections().forEach(function(n){e.drawCircle(t.get(n),5)})},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"Now that we know how to align a curve, there's one more thing we can calculate: inflection points. Imagine we have a variable size circle that we can slide up against our curve. We place it against the curve and adjust its radius so that where it touches the curve, the curvatures of the curve and the circle are the same, and then we start to slide the circle along the curve - for quadratic curves, we can always do this without the circle behaviour oddly: we might have to change the radius of the circle as we slide it alone, but it'll always sit against the same side of the curve."),r.createElement("p",null,'But what happens with cubic curves? Imagine we have an S curve and we place our circle at the start of the curve, and start sliding it along. For a while we can simply adjust the radius and things will be fine, but once we get to the midpoint of that S, something odd happens: the circle "flips" from one side of the curve to the other side, in order for the curvatures to keep matching. This is called an inflection, and we can find out where those happen relatively easily.'),r.createElement("p",null,"What we need to do is solve a simple equation:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/b039194e01b6081628efaf4aa169a4c50fa4aae4.svg",style:{width:"3.90015rem",height:"1.125rem"}})),r.createElement("p",null,"What we're saying here is that given the curvature function ",r.createElement("i",null,"C(t)"),", we want to know for which values of ",r.createElement("i",null,"t"),' this function is zero, meaning there is no "curvature", which will be exactly at the point between our circle being on one side of the curve, and our circle being on the other side of the curve. So what does ',r.createElement("i",null,"C(t)")," look like? Actually something that seems not too hard:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/2488885d57cfc55b50b1c8ad808180e50337b411.svg",style:{width:"27.37485rem",height:"1.125rem"}})),r.createElement("p",null,"So the function ",r.createElement("i",null,"C(t)")," is wholly defined by the first and second derivative functions for the parametric dimensions of our curve. And as already shown, derivatives of Bézier curves are just simpler Bézier curves, with very easy to compute new coefficients, so this should be pretty easy."),r.createElement("p",null,"However as we've seen in the section on aligning, aligning lets us simplify things ",r.createElement("em",null,"a lot"),", by completely removing the contributions of the first coordinate from most mathematical evaluations, and removing the last ",r.createElement("i",null,"y")," coordinate as well by virtue of the last point lying on the x-axis. So, while we can evaluate ",r.createElement("i",null,"C(t) = 0")," for our curve, it'll be much easier to first axis-align the curve and ",r.createElement("em",null,"then")," evalutating the curvature function."),r.createElement("div",{className:"note"},r.createElement("h3",null,"Let's derive the full formula anyway"),r.createElement("p",null,"Of course, before we do our aligned check, let's see what happens if we compute the curvature function without axis-aligning. We start with the first and second derivatives, given our basis functions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/462664d174062cec5f7252d5912057210783776c.svg",style:{width:"41.250150000000005rem",height:"4.35015rem"}})),r.createElement("p",null,"And of course the same functions for ",r.createElement("i",null,"y"),":"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/9390cb8ff4f3a9471db41c033b415a0a90b69404.svg",style:{width:"27rem",height:"4.35015rem"}})),r.createElement("p",null,"Asking a computer to now compose the ",r.createElement("i",null,"C(t)")," function for us (and to expand it to a readable form of simple terms) gives us this rather overly complicated set of arithmetic expressions:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/92350c75ebfba40fcab87d091f1f46e4c01be720.svg",style:{width:"29.62485rem",height:"7.12485rem"}})),r.createElement("p",null,"That is... unwieldy. So, we note that there are a lot of terms that involve multiplications involving x1, y1, and y4, which would all disappear if we axis-align our curve, which is why aligning is a great idea.")),r.createElement("p",null,"Aligning our curve so that three of the eight coefficients become zero, we end up with the following simple term function for ",r.createElement("i",null,"C(t)"),":"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/f61c01094f0de8ca4c7f26a229f0206d54b13930.svg",style:{width:"37.49985rem",height:"1.35rem"}})),r.createElement("p",null,"That's a lot easier to work with: we see a fair number of terms that we can compute and then cache, giving us the following simplification:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/43ea1c1ea2c15f37d7390c16dfc77834b461777e.svg",style:{width:"33.75rem",height:"5.54985rem"}})),r.createElement("p",null,"This is a plain quadratic curve, and we know how to solve ",r.createElement("i",null,"C(t) = 0"),"; we use the quadratic formula:"),r.createElement("p",null,r.createElement("img",{className:"LaTeX SVG",src:"images/latex/368099657b735b0d17becbbe7be915e88e8c04c5.svg",style:{width:"30.675150000000002rem",height:"4.1998500000000005rem"}})),r.createElement("p",null,"We can easily compute this value ",r.createElement("em",null,"if")," the descriminator isn't a negative number (because we only want real roots, not complex roots), and ",r.createElement("em",null,"if")," v",r.createElement("sub",null,"1")," is not zero, because divisions by zero are rather useless."),r.createElement("p",null,"Taking that into account, we compute ",r.createElement("i",null,"t"),", we disregard any ",r.createElement("i",null,"t")," value that isn't in the Bézier interval [0,1], and we now know at which ",r.createElement("i",null,"t")," value(s) our curve will inflect."),r.createElement(i,{title:"Finding cubic Bézier curve inflections",setup:this.setupCubic,draw:this.draw}))}});e.exports=o},function(e,t,n){"use strict";var r=n(2),i=n(215),a=n(223),o=r.createClass({displayName:"Canonical",getDefaultProps:function(){return{title:"Canonical form (for cubic curves)"}},setup:function(e){var t=e.getDefaultCubic();e.setCurve(t),e.reset(),e._map_loaded=!1},draw:function(e,t){var n=400,r=n,i=this.unit,a={x:n/2,y:r/2};e.setSize(n,r),e.setPanelCount(2),e.reset(),e.drawSkeleton(t),e.drawCurve(t),e.offset.x+=400,e._map_loaded?e.image(e._map_image):setTimeout(function(){this.drawBase(e,t),this.draw(e,t)}.bind(this),100),e.drawLine({x:0,y:0},{x:0,y:r});var o=[{x:0,y:0},{x:0,y:i},{x:i,y:i},this.forwardTransform(t.points,i)],s=new e.Bezier(o);e.setColor("blue"),e.drawCurve(s,a),e.drawCircle(o[3],3,a)},forwardTransform:function(e,t){t=t||1;var n=e[0],r=e[1],i=e[2],a=e[3],o=-n.x+a.x-(-n.x+r.x)*(-n.y+a.y)/(-n.y+r.y),s=-n.x+i.x-(-n.x+r.x)*(-n.y+i.y)/(-n.y+r.y),l=t*o/s,u=t*(-n.y+a.y)/(-n.y+r.y),c=t-t*(-n.y+i.y)/(-n.y+r.y),h=c*o/s,d=u+h;return{x:l,y:d}},drawBase:function(e,t){e.reset();var n=400,r=n,i=this.unit=n/5,a={x:n/2,y:r/2};e.setSize(n,r),e.setColor("lightgrey");for(var o=0;n>o;o+=i/2)e.drawLine({x:o,y:0},{x:o,y:r});for(var s=0;r>s;s+=i/2)e.drawLine({x:0,y:s},{x:n,y:s});e.setColor("black"),e.drawLine({x:n/2,y:0},{x:n/2,y:r}),e.drawLine({x:0,y:r/2},{x:n,y:r/2}),e.setColor("green"),e.drawLine({x:-n/2,y:i},{x:n/2,y:i},a),e.setColor("black"),e.setFill("black"),e.drawCircle({x:0,y:0},4,a),e.text("(0,0)",{x:5+a.x,y:15+a.y}),e.drawCircle({x:0,y:i},4,a),e.text("(0,1)",{x:5+a.x,y:i+15+a.y}),e.drawCircle({x:i,y:i},4,a),e.text("(1,1)",{x:i+5+a.x,y:i+15+a.y}),e.setWeight(1.5),e.setColor("#FF0000"),e.setFill(e.getColor());var l=[],u=1,c=1;for(o=-10;1>=o;o+=.01)s=(-o*o+2*o+3)/4,o>-10&&(l.push({x:i*u,y:i*c}),e.drawLine({x:i*u,y:i*c},{x:i*o,y:i*s},a)),u=o,c=s;l.push({x:i*u,y:i*c}),e.text("Curve form has cusp →",{x:n/2-2*i,y:r/2+i/2.5}),e.setColor("#FF00FF"),e.setFill(e.getColor());var h=Math.sqrt;for(o=1;o>=0;o-=.005)l.push({x:i*u,y:i*c}),s=.5*(h(3)*h(4*o-o*o)-o),e.drawLine({x:i*u,y:i*c},{x:i*o,y:i*s},a),u=o,c=s;for(l.push({x:i*u,y:i*c}),e.text("← Curve forms a loop at t = 1",{x:n/2+i/4,y:r/2+i/1.5}),e.setColor("#3300FF"),e.setFill(e.getColor()),o=0;o>-n;o-=.01)l.push({x:i*u,y:i*c}),s=(-o*o+3*o)/3,e.drawLine({x:i*u,y:i*c},{x:i*o,y:i*s},a),u=o,c=s;l.push({x:i*u,y:i*c}),e.text("← Curve forms a loop at t = 0",{x:n/2-i+10,y:r/2-1.25*i}),e.setColor("transparent"),e.setFill("rgba(255,120,100,0.2)"),e.drawPath(l,a),l=[{x:-n/2,y:i},{x:n/2,y:i},{x:n/2,y:r},{x:-n/2,y:r}],e.setFill("rgba(0,200,0,0.2)"),e.drawPath(l,a),e.setColor("black"),e.setFill(e.getColor()),e.text("← Curve form has one inflection →",{x:n/2-i,y:r/2+1.75*i}),e.text("← Plain curve ↕",{x:n/2+i/2,y:r/6}),e.text("↕ Double inflection",{x:10,y:r/2-10}),e._map_image=e.toImage(),e._map_loaded=!0},render:function(){return r.createElement("section",null,r.createElement(a,this.props),r.createElement("p",null,"While quadratic curves are relatively simple curves to analyze, the same cannot be said of the cubic curve. As a curvature controlled by more than one control points, it exhibits all kinds of features like loops, cusps, odd colinear features, and up to two inflection points because the curvature can change direction up to three times. Now, knowing what kind of curve we're dealing with means that some algorithms can be run more efficiently than if we have to implement them as generic solvers, so is there a way to determine the curve type without lots of work?"),r.createElement("p",null,"As it so happens, the answer is yes and the solution we're going to look at was presented by Maureen C. Stone from Xerox PARC and Tony D. deRose from the University of Washington in their joint paper",r.createElement("a",{href:"http://graphics.pixar.com/people/derose/publications/CubicClassification/paper.pdf"},'"A Geometric Characterization of Parametric Cubic curves"'),'. It was published in 1989, and defines curves as having a "canonical" form (i.e. a form that all curves can be reduced to) from which we can immediately tell which features a curve will have. So how does it work?'),r.createElement("p",null,'The first observation that makes things work is that if we have a cubic curve with four points, we can apply a linear transformation to these points such that three of the points end up on (0,0), (0,1) and (1,1), with the last point then being "somewhere". After applying that transformation, the location of that last point can then tell us what kind of curve we\'re dealing with. Specifically, we see the following breakdown:'),r.createElement(i,{"static":!0,preset:"simple",title:"The canonical curve map",setup:this.setup,draw:this.drawBase}),r.createElement("p",null,"This is a fairly funky image, so let's see how it breaks down. We see the three fixed points at (0,0), (0,1) and (1,1), and then the fourth point is somewhere. Depending on where it is, our curve will have certain features. Namely, if the fourth point is..."),r.createElement("ol",null,r.createElement("li",null,"anywhere on and in the red zone, the curve will be self-intersecting, yielding either a cusp or a loop. Anywhere inside the the red zone, this will be a loop. We won't know ",r.createElement("i",null,"where")," that loop is (in terms of ",r.createElement("i",null,"t")," values), but we are guaranteed that there is one."),r.createElement("li",null,"on the left (red) edge, the curve will have a cusp. We again don't know ",r.createElement("em",null,"where"),", just that it has one. This edge is described by the function: ",r.createElement("img",{className:"LaTeX SVG",src:"images/latex/ae5a63e86bb367e6266a394962387344d0a92b10.svg",style:{width:"12.45015rem",height:"2.3998500000000003rem"}})),r.createElement("li",null,"on the lower right (pink) edge, the curve will have a loop at t=1, so we know the end coordinate of the curve also lies ",r.createElement("em",null,"on")," the curve. This edge is described by the function: ",r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d389fcde05a773be99f84db5fc9ed7ef043bf406.svg",style:{width:"16.050150000000002rem",height:"2.6248500000000003rem"}})),r.createElement("li",null,"on the top (blue) edge, the curve will have a loop at t=0, so we know the start coordinate of the curve also lies ",r.createElement("em",null,"on")," the curve. This edge is described by the function: ",r.createElement("img",{className:"LaTeX SVG",src:"images/latex/d97181a9d0ada19862a0ff2cebb08bdee00868d7.svg",style:{width:"10.650150000000002rem",height:"2.3998500000000003rem"}})),r.createElement("li",null,"inside the green zone, the curve will have a single inflection, switching concave/convex once."),r.createElement("li",null,"between the red and green zones, the curve has two inflections, meaning its curvature switches between concave/convex form twice."),r.createElement("li",null,"anywhere on the right of the red zone, the curve will have no inflections. It'll just be a well-behaved arch.")),r.createElement("p",null,"Of course, this map is fairly small, but the regions extend to infinity, with well defined boundaries."),r.createElement("div",{className:"note"},r.createElement("h3",null,"Wait, where do those lines come from?"),r.createElement("p",null,'Without repeating the paper mentioned at the top of this section, the loop-boundaries come from rewriting the curve into canonical form, and then solving the formulae for which constraints must hold for which possible curve properties. In the paper these functions yield formulae for where you will find cusp points, or loops where we know t=0 or t=1, but those functions are derived for the full cubic expression, meaning they apply to t=-∞ to t=∞... For Bézier curves we only care about the "clipped interval" t=0 to t=1, so some of the properties that apply when you look at the curve over an infinite interval simply don\'t apply to the Bézier curve interval.'),r.createElement("p",null,'The right bound for the loop region, indicating where the curve switches from "having inflections" to "having a loop", for the general cubic curve, is actually mirrored over x=1, but for Bézier curves this right half doesn\'t apply, so we don\'t need to pay attention to it. Similarly, the boundaries for t=0 and t=1 loops are also nice clean curves but get "cut off" when we only look at what the general curve does over the interval t=0 to t=1.'),r.createElement("p",null,'For the full details, head over to the paper and read through sections 3 and 4. If you still remember your high school precalculus, you can probably follow along with this paper, although you might have to read it a few times before all the bits "click".')),r.createElement("p",null,"So now the question becomes: how do we manipulate our curve so that it fits this canonical form, with three fixed points, and one \"free\" point? Enter linear algerba. Don't worry, I'll be doing all the math for you, as well as show you what the effect is on our curves, but basically we're going to be using linear algebra, rather than calculus, because \"it's way easier\". Sometimes a calculus approach is very hard to work with, when the equivalent geometrical solution is super obvious."),r.createElement("p",null,"The approach is going to start with a curve that doesn't have all-colinear points (so we need to make sure the points don't all fall on a straight line), and then applying four graphics operations that you will probably have heard of: translation (moving all points by some fixed x- and y-distance), scaling (multiplying all points by some x and y scale factor), and shearing (an operation that turns rectangles into parallelograms)."),r.createElement("p",null,"Step 1: we translate any curve by -p1.x and -p1.y, so that the curve starts at (0,0). We're going to make use of an interesting trick here, by pretending our 2D coordinates are 3D, with the ",r.createElement("i",null,"z"),"coordinate simply always being 1. This is an old trick in graphics to overcome the limitations of 2D transformations: without it, we can only turn (x,y) coordinates into new coordinates of the form (ax + by, cx + dy), which means we can't do translation, since that requires we end up with some kind of (x + a, y + b). If we add a bogus ",r.createElement("i",null,"z")," coordinate that is always 1, then we can suddenly add arbitrary values. For example:"),r.createElement("p",null,r.createElement("img",{ diff --git a/components/sections/control/index.js b/components/sections/control/index.js index 245febd5..7a75e1f2 100644 --- a/components/sections/control/index.js +++ b/components/sections/control/index.js @@ -96,7 +96,7 @@ var Control = React.createClass({ this.drawLerpBox(api, dim, pad, p); var t = (p.x-pad)/fwh; this.drawLerpPoint(api, (1-t)*(1-t)*(1-t), pad, fwh, p); - this.drawLerpPoint(api, 2*(1-t)*(1-t)*(t), pad, fwh, p); + this.drawLerpPoint(api, 3*(1-t)*(1-t)*(t), pad, fwh, p); this.drawLerpPoint(api, 3*(1-t)*(t)*(t), pad, fwh, p); this.drawLerpPoint(api, (t)*(t)*(t), pad, fwh, p); } diff --git a/stylesheets/style.css b/stylesheets/style.css index 14ba82ad..e69de29b 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -1,320 +0,0 @@ -html, -body { - font-family: Verdana; - width: 100%; - margin: 0; - padding: 0; -} -body { - background: url('../images/paper.png'); -} -header, -section, -footer { - width: 960px; - margin: 0 auto; -} -header { - font-family: Times; - text-align: center; - margin-bottom: 2rem; -} -header h1 { - font-size: 360%; - margin: 0; - margin-bottom: 1rem; -} -header h2 { - font-size: 125%; - margin: 0; -} -article { - font-family: Verdana; - width: 960px; - height: auto; - margin: auto; - background: rgba(255, 255, 255, 0.74); - border: solid rgba(255, 0, 0, 0.35); - border-width: 0; - border-left-width: 1px; - padding: 1em; - box-shadow: 25px 0px 25px 25px rgba(255, 255, 255, 0.74); -} -a, -a:visited { - color: #0000c8; - text-decoration: none; -} -footer { - font-style: italic; - margin: 2em 0 1em 0; - background: inherit; -} -.ribbon { - position: fixed; - top: 0; - right: 0; - height: 0; - overflow: visible; -} -.ribbon img { - position: relative; - z-index: 999; -} -navigation { - font-family: Georgia; - display: block; - width: 70%; - margin: 0 auto; - padding: 0; - border: 1px solid grey; -} -navigation ul { - background: #F2F2F9; - list-style: none; - margin: 0; - padding: 0.5em 1em; -} -navigation ul li:nth-child(n+2)[data-number]:before { - content: "§" attr(data-number) ". "; -} -navigation ul li:nth-child(n+2):not([data-number]) { - margin: 5px 0; -} -navigation.compact { - width: 100%; - border: none; - border-top: 1px solid grey; - padding-top: 2em; - margin-top: 2em; -} -navigation.compact ul { - background: inherit; -} -navigation.compact ul li { - display: inline-block; -} -navigation.compact ul li:not(:last-child) { - margin-right: 1em; -} -section { - margin-top: 4em; -} -section p { - text-align: justify; -} -section h2[data-num] { - border-bottom: 1px solid grey; -} -section h2[data-num]:before { - content: "§" attr(data-num) " — "; -} -section h2 a, -section h2 a:active, -section h2 a:hover, -section h2 a:visited { - text-decoration: none; - color: inherit; -} -section table { - margin: auto; -} -section table p { - text-align: center; -} -div.note { - font-size: 90%; - margin: 1em 2em; - padding: 1em; - border: 1px solid grey; - background: rgba(150, 150, 50, 0.05); -} -div.note h1, -div.note h2, -div.note h3, -div.note h4, -div.note h5, -div.note h6, -div.note p { - margin: 0; - padding: 0; -} -div.note p { - margin: 1em 0; -} -div.note div.MathJax_Display { - margin: 1em 0; -} -.howtocode { - border: 1px solid #8d94bd; - padding: 0 1em; - margin: 0 2em; - overflow-x: hidden; -} -.howtocode h3 { - margin: 0 -1em; - padding: 0; - background: #91bef7; - padding-left: 0.5em; - color: white; - text-shadow: 1px 1px 0 #000000; - cursor: pointer; -} -.howtocode pre { - border: 1px solid #8d94bd; - background: rgba(223, 226, 243, 0.32); - margin: 0.5em; - padding: 0.5em; -} -figure { - display: inline-block; - border: 1px solid grey; - background: #F0F0F0; - padding: 0.5em 0.5em 0 0.5em; - text-align: center; -} -figure.inline { - border: none; - margin: 0; -} -figure canvas { - display: inline-block; - background: white; - border: 1px solid lightgrey; -} -figure canvas:focus { - border: 1px solid grey; - outline: none; -} -figure figcaption { - text-align: center; - padding: 0.5em 0; - font-style: italic; - font-size: 90%; -} -figure figcaption button { - font-family: Verdana; - border: 1px solid grey; - border-radius: 3px; - background: #FDFDFD; -} -figure figcaption button.selected { - background: #c8c8ff; -} -figure figcaption button + button { - margin-left: 0.25em; -} -figure:not([class=inline]) + figure:not([class=inline]) { - margin-top: 2em; -} -div.figure { - display: inline-block; - border: 1px solid grey; - text-align: center; -} -github-issues { - position: relative; - display: block; - width: 100%; - border: 1px solid #EEE; - border-left: 0.3em solid #e5ecf3; - background: white; - padding: 0 0.3em; - width: 95%; - margin: auto; - min-height: 33px; - font: 13px Helvetica, arial, freesans, clean, sans-serif; -} -github-issues github-issue + github-issue { - margin-top: 1em; -} -github-issues github-issue h3 { - font-size: 100%; - background: #e5ecf3; - margin: 0; - position: relative; - left: -0.5%; - width: 101%; - font-weight: bold; - border-bottom: 1px solid #999; -} -github-issues github-issue a { - position: absolute; - top: 2px; - right: 10px; - padding: 0 4px; - color: #4183C4!important; - background: white; - line-height: 10px; - font-size: 10px; -} -img.LaTeX { - display: block; - margin-left: 2em; -} -table { - margin: 1em 2em; - padding: 0 1em; - border: 1px solid grey; - background: rgba(150, 150, 50, 0.05); -} -table img { - border: 1px solid lightgrey; -} -footer { - font-size: 85%; - font-family: Verdana; - border-top: 1px solid grey; - padding: 2em 1.25em 0; - box-sizing: content-box; - margin-left: -1rem; -} -.relatives { - width: 100%; - border: 1px solid #CCC; - padding: 0.25rem 1rem; - margin-left: -1rem; - box-sizing: content-box; -} -.relatives.before { - border-width: 1px 0px; - margin-bottom: -2rem; -} -.relatives.after { - margin-top: 2rem; - border-width: 1px 0 0 0; - border-color: grey; - margin-bottom: -1.5rem; -} -.relatives .prev:before { - content: "← "; -} -.relatives .next:after { - content: " →"; -} -.relatives tbody { - margin: 0; -} -.relatives tbody tr { - margin: 0; -} -.relatives tbody tr td { - width: 50%; -} -.relatives tbody tr td:nth-child(1) { - text-align: left; -} -.relatives tbody tr td.toc { - text-align: center; - white-space: nowrap; - width: 0%; -} -.relatives tbody tr td.toc:before { - content: "["; -} -.relatives tbody tr td.toc:after { - content: "]"; -} -.relatives tbody tr td:nth-child(3) { - text-align: right; -}