UNPKG

jointjs

Version:

JavaScript diagramming library

8 lines (6 loc) 400 kB
/*! JointJS v3.1.1 (2019-10-28) - JavaScript diagramming library This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ if(function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("backbone"),require("lodash"),require("jquery")):"function"==typeof define&&define.amd?define(["exports","backbone","lodash","jquery"],e):e((t=t||self).joint={},t.Backbone,t._,t.$)}(this,function(e,s,i,S){"use strict";var n,l,r,c;s=s&&s.hasOwnProperty("default")?s.default:s,i=i&&i.hasOwnProperty("default")?i.default:i,S=S&&S.hasOwnProperty("default")?S.default:S,Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,s=0|e,a=Math.max(0<=s?s:n-Math.abs(s),0);for(;a<n;){if((r=i[a])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;a++}return!1}}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}}),Array.from||(Array.from=(n=Object.prototype.toString,l=function(t){return"function"==typeof t||"[object Function]"===n.call(t)},r=Math.pow(2,53)-1,c=function(t){var e,i=(e=Number(t),isNaN(e)?0:0!==e&&isFinite(e)?(0<e?1:-1)*Math.floor(Math.abs(e)):e);return Math.min(Math.max(i,0),r)},function(t){var e=Object(t);if(null==t)throw new TypeError("Array.from requires an array-like object - not null or undefined");var i,n=1<arguments.length?arguments[1]:void 0;if(void 0!==n){if(!l(n))throw new TypeError("Array.from: when provided, the second argument must be a function");2<arguments.length&&(i=arguments[2])}for(var r,o=c(e.length),s=l(this)?Object(new this(o)):new Array(o),a=0;a<o;)r=e[a],s[a]=n?void 0===i?n(r,a):n.call(i,r,a):r,a+=1;return s.length=o,s})),Array.prototype.findIndex||Object.defineProperty(Array.prototype,"findIndex",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return r;r++}return-1}}),function(){var t=void 0!==e?e:this,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function l(t){this.message=t}(l.prototype=new Error).name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var e,i,n=String(t),r=0,o=a,s="";n.charAt(0|r)||(o="=",r%1);s+=o.charAt(63&e>>8-r%1*8)){if(255<(i=n.charCodeAt(r+=.75)))throw new l("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");e=e<<8|i}return s}),t.atob||(t.atob=function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,n,r=0,o=0,s="";n=e.charAt(o++);~n&&(i=r%4?64*i+n:n,r++%4)?s+=String.fromCharCode(255&i>>(-2*r&6)):0)n=a.indexOf(n);return s})}(),Number.isFinite=Number.isFinite||function(t){return"number"==typeof t&&isFinite(t)},Number.isNaN=Number.isNaN||function(t){return t!=t},String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),String.prototype.startsWith||(String.prototype.startsWith=function(t,e){return this.substr(e||0,t.length)===t}),function(){function n(t,e){return this.slice(t,e)}function r(t,e){arguments.length<2&&(e=0);for(var i=0,n=t.length;i<n;++i,++e)this[e]=255&t[i]}function t(t){var e;if("number"==typeof t){e=new Array(t);for(var i=0;i<t;++i)e[i]=0}else e=t.slice(0);return e.subarray=n,(e.buffer=e).byteLength=e.length,e.set=r,"object"==typeof t&&t.buffer&&(e.buffer=t.buffer),e}"undefined"==typeof Uint8Array&&"undefined"!=typeof window&&(window.Uint8Array=t,window.Uint32Array=t,window.Int32Array=t)}(),"undefined"!=typeof XMLHttpRequest&&("response"in XMLHttpRequest.prototype||"mozResponseArrayBuffer"in XMLHttpRequest.prototype||"mozResponse"in XMLHttpRequest.prototype||"responseArrayBuffer"in XMLHttpRequest.prototype||Object.defineProperty(XMLHttpRequest.prototype,"response",{get:function(){return new Uint8Array(new VBArray(this.responseBody).toArray())}}));var o=Math,Z=o.abs,g=o.cos,h=o.sin,L=o.sqrt,P=o.min,G=o.max,u=o.atan2,a=o.round,d=o.floor,f=o.PI,k=o.pow,t={curveThroughPoints:function(t){return console.warn("deprecated"),new O(p.throughPoints(t)).serialize()},getCurveControlPoints:function(t){console.warn("deprecated");var e,i=[],n=[],r=t.length-1;if(1==r)return i[0]=new E((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),n[0]=new E(2*i[0].x-t[0].x,2*i[0].y-t[0].y),[i,n];var o=[];for(e=1;e<r-1;e++)o[e]=4*t[e].x+2*t[e+1].x;o[0]=t[0].x+2*t[1].x,o[r-1]=(8*t[r-1].x+t[r].x)/2;var s=this.getFirstControlPoints(o);for(e=1;e<r-1;++e)o[e]=4*t[e].y+2*t[e+1].y;o[0]=t[0].y+2*t[1].y,o[r-1]=(8*t[r-1].y+t[r].y)/2;var a=this.getFirstControlPoints(o);for(e=0;e<r;e++)i.push(new E(s[e],a[e])),e<r-1?n.push(new E(2*t[e+1].x-s[e+1],2*t[e+1].y-a[e+1])):n.push(new E((t[r].x+s[r-1])/2,(t[r].y+a[r-1])/2));return[i,n]},getCurveDivider:function(t,e,i,n){console.warn("deprecated");var r=new p(t,e,i,n);return function(t){var e=r.divide(t);return[{p0:e[0].start,p1:e[0].controlPoint1,p2:e[0].controlPoint2,p3:e[0].end},{p0:e[1].start,p1:e[1].controlPoint1,p2:e[1].controlPoint2,p3:e[1].end}]}},getFirstControlPoints:function(t){console.warn("deprecated");var e=t.length,i=[],n=[],r=2;i[0]=t[0]/r;for(var o=1;o<e;o++)n[o]=1/r,r=(o<e-1?4:3.5)-n[o],i[o]=(t[o]-i[o-1])/r;for(o=1;o<e;o++)i[e-o-1]-=n[e-o]*i[e-o];return i},getInversionSolver:function(t,e,i,n){console.warn("deprecated");var r=new p(t,e,i,n);return function(t){return r.closestPointT(t)}}},p=function(t,e,i,n){return this instanceof p?t instanceof p?new p(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new E(t),this.controlPoint1=new E(e),this.controlPoint2=new E(i),void(this.end=new E(n))):new p(t,e,i,n)};p.throughPoints=function(){function l(t){var e=t.length,i=[],n=[],r=2;i[0]=t[0]/r;for(var o=1;o<e;o++)n[o]=1/r,r=(o<e-1?4:3.5)-n[o],i[o]=(t[o]-i[o-1])/r;for(o=1;o<e;o++)i[e-o-1]-=n[e-o]*i[e-o];return i}return function(t){if(!t||Array.isArray(t)&&t.length<2)throw new Error("At least 2 points are required");for(var e=function(t){var e,i=[],n=[],r=t.length-1;if(1==r)return i[0]=new E((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),n[0]=new E(2*i[0].x-t[0].x,2*i[0].y-t[0].y),[i,n];var o=[];for(e=1;e<r-1;e++)o[e]=4*t[e].x+2*t[e+1].x;o[0]=t[0].x+2*t[1].x,o[r-1]=(8*t[r-1].x+t[r].x)/2;var s=l(o);for(e=1;e<r-1;++e)o[e]=4*t[e].y+2*t[e+1].y;o[0]=t[0].y+2*t[1].y,o[r-1]=(8*t[r-1].y+t[r].y)/2;var a=l(o);for(e=0;e<r;e++)i.push(new E(s[e],a[e])),e<r-1?n.push(new E(2*t[e+1].x-s[e+1],2*t[e+1].y-a[e+1])):n.push(new E((t[r].x+s[r-1])/2,(t[r].y+a[r-1])/2));return[i,n]}(t),i=[],n=e[0].length,r=0;r<n;r++){var o=new E(e[0][r].x,e[0][r].y),s=new E(e[1][r].x,e[1][r].y);i.push(new p(t[r],o,s,t[r+1]))}return i}}(),p.prototype={bbox:function(){for(var t,e,i,n,r,o,s,a,l=this.start,c=this.controlPoint1,g=this.controlPoint2,h=this.end,u=l.x,d=l.y,f=c.x,p=c.y,I=g.x,m=g.y,A=h.x,v=h.y,C=new Array,w=new Array,y=[new Array,new Array],b=0;b<2;++b)if(i=0===b?(e=6*u-12*f+6*I,t=-3*u+9*f-9*I+3*A,3*f-3*u):(e=6*d-12*p+6*m,t=-3*d+9*p-9*m+3*v,3*p-3*d),Z(t)<1e-12){if(Z(e)<1e-12)continue;0<(n=-i/e)&&n<1&&w.push(n)}else a=L(s=e*e-4*i*t),s<0||(0<(r=(-e+a)/(2*t))&&r<1&&w.push(r),0<(o=(-e-a)/(2*t))&&o<1&&w.push(o));for(var N,M,x,S=w.length,k=S;S--;)M=(N=1-(n=w[S]))*N*N*u+3*N*N*n*f+3*N*n*n*I+n*n*n*A,y[0][S]=M,x=N*N*N*d+3*N*N*n*p+3*N*n*n*m+n*n*n*v,y[1][S]=x,C[S]={X:M,Y:x};w[k]=0,w[k+1]=1,C[k]={X:u,Y:d},C[k+1]={X:A,Y:v},y[0][k]=u,y[1][k]=d,y[0][k+1]=A,y[1][k+1]=v,w.length=k+2,y[0].length=k+2,y[1].length=k+2,C.length=k+2;var D=P.apply(null,y[0]),z=P.apply(null,y[1]),j=G.apply(null,y[0]),T=G.apply(null,y[1]);return new H(D,z,j-D,T-z)},clone:function(){return new p(this.start,this.controlPoint1,this.controlPoint2,this.end)},closestPoint:function(t,e){return this.pointAtT(this.closestPointT(t,e))},closestPointLength:function(t,e){var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:i}):e.subdivisions};return this.lengthAtT(this.closestPointT(t,n),n)},closestPointNormalizedLength:function(t,e){var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:i}):e.subdivisions},r=this.closestPointLength(t,n);if(!r)return 0;var o=this.length(n);return 0===o?0:r/o},closestPointT:function(t,e){for(var i,n,r,o,s,a,l,c=void 0===(e=e||{}).precision?this.PRECISION:e.precision,g=void 0===e.subdivisions?this.getSubdivisions({precision:c}):e.subdivisions,h=g.length,u=h?1/h:0,d=0;d<h;d++){var f=g[d],p=f.start.distance(t),I=f.end.distance(t),m=p+I;(!l||m<l)&&(n=d*u,r=(d+1)*u,o=p,s=I,a=(i=f).start.distance(f.end),l=m)}for(var A=k(10,-c);;){var v=o?Z(o-s)/o:0,C=s?Z(o-s)/s:0;if(v<A||C<A||(!o||o<a*A||(!s||s<a*A)))return o<=s?n:r;var w=i.divide(.5);u/=2;var y=w[0].start.distance(t),b=w[0].end.distance(t),N=y+b,M=w[1].start.distance(t),x=w[1].end.distance(t);s=N<=M+x?(i=w[0],r-=u,o=y,b):(i=w[1],n+=u,o=M,x)}},closestPointTangent:function(t,e){return this.tangentAtT(this.closestPointT(t,e))},containsPoint:function(t,e){return this.toPolyline(e).containsPoint(t)},divideAt:function(t,e){if(t<=0)return this.divideAtT(0);if(1<=t)return this.divideAtT(1);var i=this.tAt(t,e);return this.divideAtT(i)},divideAtLength:function(t,e){var i=this.tAtLength(t,e);return this.divideAtT(i)},divideAtT:function(t){var e=this.start,i=this.controlPoint1,n=this.controlPoint2,r=this.end;if(t<=0)return[new p(e,e,e,e),new p(e,i,n,r)];if(1<=t)return[new p(e,i,n,r),new p(r,r,r,r)];var o=this.getSkeletonPoints(t),s=o.startControlPoint1,a=o.startControlPoint2,l=o.divider,c=o.dividerControlPoint1,g=o.dividerControlPoint2;return[new p(e,s,a,l),new p(l,c,g,r)]},endpointDistance:function(){return this.start.distance(this.end)},equals:function(t){return!!t&&this.start.x===t.start.x&&this.start.y===t.start.y&&this.controlPoint1.x===t.controlPoint1.x&&this.controlPoint1.y===t.controlPoint1.y&&this.controlPoint2.x===t.controlPoint2.x&&this.controlPoint2.y===t.controlPoint2.y&&this.end.x===t.end.x&&this.end.y===t.end.y},getSkeletonPoints:function(t){var e=this.start,i=this.controlPoint1,n=this.controlPoint2,r=this.end;if(t<=0)return{startControlPoint1:e.clone(),startControlPoint2:e.clone(),divider:e.clone(),dividerControlPoint1:i.clone(),dividerControlPoint2:n.clone()};if(1<=t)return{startControlPoint1:i.clone(),startControlPoint2:n.clone(),divider:r.clone(),dividerControlPoint1:r.clone(),dividerControlPoint2:r.clone()};var o=new B(e,i).pointAt(t),s=new B(i,n).pointAt(t),a=new B(n,r).pointAt(t),l=new B(o,s).pointAt(t),c=new B(s,a).pointAt(t);return{startControlPoint1:o,startControlPoint2:l,divider:new B(l,c).pointAt(t),dividerControlPoint1:c,dividerControlPoint2:a}},getSubdivisions:function(t){var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,i=[new p(this.start,this.controlPoint1,this.controlPoint2,this.end)];if(0===e)return i;for(var n=this.endpointDistance(),r=k(10,-e),o=0;;){o+=1;for(var s=[],a=i.length,l=0;l<a;l++){var c=i[l].divide(.5);s.push(c[0],c[1])}for(var g=0,h=s.length,u=0;u<h;u++){g+=s[u].endpointDistance()}if(1<o&&(0!==g?(g-n)/g:0)<r)return s;i=s,n=g}},isDifferentiable:function(){var t=this.start,e=this.controlPoint1,i=this.controlPoint2,n=this.end;return!(t.equals(e)&&e.equals(i)&&i.equals(n))},length:function(t){for(var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,i=void 0===t.subdivisions?this.getSubdivisions({precision:e}):t.subdivisions,n=0,r=i.length,o=0;o<r;o++){n+=i[o].endpointDistance()}return n},lengthAtT:function(t,e){if(t<=0)return 0;var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision;return this.divide(t)[0].length({precision:i})},pointAt:function(t,e){if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var i=this.tAt(t,e);return this.pointAtT(i)},pointAtLength:function(t,e){var i=this.tAtLength(t,e);return this.pointAtT(i)},pointAtT:function(t){return t<=0?this.start.clone():1<=t?this.end.clone():this.getSkeletonPoints(t).divider},PRECISION:3,scale:function(t,e,i){return this.start.scale(t,e,i),this.controlPoint1.scale(t,e,i),this.controlPoint2.scale(t,e,i),this.end.scale(t,e,i),this},tangentAt:function(t,e){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var i=this.tAt(t,e);return this.tangentAtT(i)},tangentAtLength:function(t,e){if(!this.isDifferentiable())return null;var i=this.tAtLength(t,e);return this.tangentAtT(i)},tangentAtT:function(t){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var e=this.getSkeletonPoints(t),i=e.startControlPoint2,n=e.dividerControlPoint1,r=e.divider,o=new B(i,n);return o.translate(r.x-i.x,r.y-i.y),o},tAt:function(t,e){if(t<=0)return 0;if(1<=t)return 1;var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:i}):e.subdivisions},r=this.length(n)*t;return this.tAtLength(r,n)},tAtLength:function(t,e){var i=!0;t<0&&(i=!1,t=-t);for(var n,r,o,s,a,l=void 0===(e=e||{}).precision?this.PRECISION:e.precision,c=void 0===e.subdivisions?this.getSubdivisions({precision:l}):e.subdivisions,g={precision:l,subdivisions:c},h=0,u=c.length,d=1/u,f=0;f<u;f++){var p=i?f:u-1-f,I=c[f],m=I.endpointDistance();if(t<=h+m){n=I,r=p*d,o=(p+1)*d,s=i?t-h:m+h-t,a=i?m+h-t:t-h;break}h+=m}if(!n)return i?1:0;for(var A=this.length(g),v=k(10,-l);;){var C,w;if((0!==A?s/A:0)<v)return r;if((0!==A?a/A:0)<v)return o;var y=n.divide(.5);d/=2;var b=y[0].endpointDistance(),N=y[1].endpointDistance();w=s<=b?(n=y[0],o-=d,b-(C=s)):(n=y[1],r+=d,N-(C=s-b)),s=C,a=w}},toPoints:function(t){for(var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,i=void 0===t.subdivisions?this.getSubdivisions({precision:e}):t.subdivisions,n=[i[0].start.clone()],r=i.length,o=0;o<r;o++){var s=i[o];n.push(s.end.clone())}return n},toPolyline:function(t){return new D(this.toPoints(t))},toString:function(){return this.start+" "+this.controlPoint1+" "+this.controlPoint2+" "+this.end},translate:function(t,e){return this.start.translate(t,e),this.controlPoint1.translate(t,e),this.controlPoint2.translate(t,e),this.end.translate(t,e),this}},p.prototype.divide=p.prototype.divideAtT;var w=function(t,e,i){return this instanceof w?t instanceof w?new w(new E(t.x,t.y),t.a,t.b):(t=new E(t),this.x=t.x,this.y=t.y,this.a=e,void(this.b=i)):new w(t,e,i)};w.fromRect=function(t){return t=new H(t),new w(t.center(),t.width/2,t.height/2)},w.prototype={bbox:function(){return new H(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new E(this.x,this.y)},clone:function(){return new w(this)},containsPoint:function(t){return this.normalizedDistance(t)<=1},equals:function(t){return!!t&&t.x===this.x&&t.y===this.y&&t.a===this.a&&t.b===this.b},inflate:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.a+=2*t,this.b+=2*e,this},intersectionWithLine:function(t){var e=[],i=t.start,n=t.end,r=this.a,o=this.b,s=t.vector(),a=i.difference(new E(this)),l=new E(s.x/(r*r),s.y/(o*o)),c=new E(a.x/(r*r),a.y/(o*o)),g=s.dot(l),h=s.dot(c),u=h*h-g*(a.dot(c)-1);if(u<0)return null;if(0<u){var d=L(u),f=(-h-d)/g,p=(-h+d)/g;if((f<0||1<f)&&(p<0||1<p))return null;0<=f&&f<=1&&e.push(i.lerp(n,f)),0<=p&&p<=1&&e.push(i.lerp(n,p))}else{var I=-h/g;if(!(0<=I&&I<=1))return null;e.push(i.lerp(n,I))}return e},intersectionWithLineFromCenterToPoint:function(t,e){t=new E(t),e&&t.rotate(new E(this.x,this.y),e);var i,n=t.x-this.x,r=t.y-this.y;if(0===n)return i=this.bbox().pointNearestToPoint(t),e?i.rotate(new E(this.x,this.y),-e):i;var o=r/n,s=o*o,a=this.a*this.a,l=this.b*this.b,c=L(1/(1/a+s/l)),g=o*(c=n<0?-c:c);return i=new E(this.x+c,this.y+g),e?i.rotate(new E(this.x,this.y),-e):i},normalizedDistance:function(t){var e=t.x,i=t.y,n=this.a,r=this.b,o=this.x,s=this.y;return(e-o)*(e-o)/(n*n)+(i-s)*(i-s)/(r*r)},tangentTheta:function(t){var e,i,n=t.x,r=t.y,o=this.a,s=this.b,a=this.bbox().center(),l=a.x,c=a.y,g=n>a.x+o/2,h=n<a.x-o/2;return g||h?i=o*o/(n-l)-o*o*(r-c)*((e=n>a.x?r-30:r+30)-c)/(s*s*(n-l))+l:e=s*s/(r-c)-s*s*(n-l)*((i=r>a.y?n+30:n-30)-l)/(o*o*(r-c))+c,new E(i,e).theta(t)},toString:function(){return new E(this.x,this.y).toString()+" "+this.a+" "+this.b}};var B=function(t,e){return this instanceof B?t instanceof B?new B(t.start,t.end):(this.start=new E(t),void(this.end=new E(e))):new B(t,e)};B.prototype={angle:function(){var t=new E(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=P(this.start.x,this.end.x),e=P(this.start.y,this.end.y),i=G(this.start.x,this.end.x),n=G(this.start.y,this.end.y);return new H(t,e,i-t,n-e)},bearing:function(){var t=y(this.start.y),e=y(this.end.y),i=this.start.x,n=this.end.x,r=y(n-i),o=h(r)*g(e),s=g(t)*h(e)-h(t)*g(e)*g(r),a=A(u(o,s))-22.5;return a<0&&(a+=360),["NE","E","SE","S","SW","W","NW","N"][a=parseInt(a/45)]},clone:function(){return new B(this.start,this.end)},closestPoint:function(t){return this.pointAt(this.closestPointNormalizedLength(t))},closestPointLength:function(t){return this.closestPointNormalizedLength(t)*this.length()},closestPointNormalizedLength:function(t){var e=this.vector().dot(new B(this.start,t).vector()),i=P(1,G(0,e/this.squaredLength()));return i!=i?0:i},closestPointTangent:function(t){return this.tangentAt(this.closestPointNormalizedLength(t))},containsPoint:function(t){var e=this.start,i=this.end;if(0!==e.cross(t,i))return!1;var n=this.length();return!(new B(e,t).length()>n)&&!(new B(t,i).length()>n)},divideAt:function(t){var e=this.pointAt(t);return[new B(this.start,e),new B(e,this.end)]},divideAtLength:function(t){var e=this.pointAtLength(t);return[new B(this.start,e),new B(e,this.end)]},equals:function(t){return!!t&&this.start.x===t.start.x&&this.start.y===t.start.y&&this.end.x===t.end.x&&this.end.y===t.end.y},intersect:function(t,e){if(t instanceof B||t instanceof H||t instanceof D||t instanceof w||t instanceof O){var i=t.intersectionWithLine(this,e);return i&&t instanceof B&&(i=i[0]),i}return null},intersectionWithLine:function(t){var e=new E(this.end.x-this.start.x,this.end.y-this.start.y),i=new E(t.end.x-t.start.x,t.end.y-t.start.y),n=e.x*i.y-e.y*i.x,r=new E(t.start.x-this.start.x,t.start.y-this.start.y),o=r.x*i.y-r.y*i.x,s=r.x*e.y-r.y*e.x;if(0===n||o*n<0||s*n<0)return null;if(0<n){if(n<o||n<s)return null}else if(o<n||s<n)return null;return[new E(this.start.x+o*e.x/n,this.start.y+o*e.y/n)]},isDifferentiable:function(){return!this.start.equals(this.end)},length:function(){return L(this.squaredLength())},midpoint:function(){return new E((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},pointAt:function(t){var e=this.start,i=this.end;return t<=0?e.clone():1<=t?i.clone():e.lerp(i,t)},pointAtLength:function(t){var e=this.start,i=this.end,n=!0;t<0&&(n=!1,t=-t);var r=this.length();return r<=t?n?i.clone():e.clone():this.pointAt((n?t:r-t)/r)},pointOffset:function(t){t=new E(t);var e=this.start,i=this.end;return((i.x-e.x)*(t.y-e.y)-(i.y-e.y)*(t.x-e.x))/this.length()},rotate:function(t,e){return this.start.rotate(t,e),this.end.rotate(t,e),this},round:function(t){var e=k(10,t||0);return this.start.x=a(this.start.x*e)/e,this.start.y=a(this.start.y*e)/e,this.end.x=a(this.end.x*e)/e,this.end.y=a(this.end.y*e)/e,this},scale:function(t,e,i){return this.start.scale(t,e,i),this.end.scale(t,e,i),this},setLength:function(t){var e=this.length();if(!e)return this;var i=t/e;return this.scale(i,i,this.start)},squaredLength:function(){var t=this.start.x,e=this.start.y;return(t-=this.end.x)*t+(e-=this.end.y)*e},tangentAt:function(t){if(!this.isDifferentiable())return null;var e=this.start,i=this.end,n=this.pointAt(t),r=new B(e,i);return r.translate(n.x-e.x,n.y-e.y),r},tangentAtLength:function(t){if(!this.isDifferentiable())return null;var e=this.start,i=this.end,n=this.pointAtLength(t),r=new B(e,i);return r.translate(n.x-e.x,n.y-e.y),r},toString:function(){return this.start.toString()+" "+this.end.toString()},translate:function(t,e){return this.start.translate(t,e),this.end.translate(t,e),this},vector:function(){return new E(this.end.x-this.start.x,this.end.y-this.start.y)}},B.prototype.intersection=B.prototype.intersect;var O=function(t){if(!(this instanceof O))return new O(t);if("string"==typeof t)return new O.parse(t);var e,i;if(this.segments=[],t)if(Array.isArray(t)&&0!==t.length)if(i=(t=t.reduce(function(t,e){return t.concat(e)},[])).length,t[0].isSegment)for(e=0;e<i;e++){var n=t[e];this.appendSegment(n)}else{var r=null;for(e=0;e<i;e++){var o=t[e];if(!(o instanceof B||o instanceof p))throw new Error("Cannot construct a path segment from the provided object.");0===e&&this.appendSegment(O.createSegment("M",o.start)),r&&!r.end.equals(o.start)&&this.appendSegment(O.createSegment("M",o.start)),o instanceof B?this.appendSegment(O.createSegment("L",o.end)):o instanceof p&&this.appendSegment(O.createSegment("C",o.controlPoint1,o.controlPoint2,o.end)),r=o}}else if(t.isSegment)this.appendSegment(t);else if(t instanceof B)this.appendSegment(O.createSegment("M",t.start)),this.appendSegment(O.createSegment("L",t.end));else if(t instanceof p)this.appendSegment(O.createSegment("M",t.start)),this.appendSegment(O.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof D))throw new Error("Cannot construct a path from the provided object.");if(!t.points||0===t.points.length)return;for(i=t.points.length,e=0;e<i;e++){var s=t.points[e];0===e?this.appendSegment(O.createSegment("M",s)):this.appendSegment(O.createSegment("L",s))}}else;};O.parse=function(t){if(!t)return new O;for(var e=new O,i=t.match(/(?:[a-zA-Z] *)(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)? *,? *)|(?:-?\.\d+ *,? *))+|(?:[a-zA-Z] *)(?! |\d|-|\.)/g),n=i.length,r=0;r<n;r++){var o=i[r].match(/(?:[a-zA-Z])|(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)?))|(?:(?:-?\.\d+))/g),s=O.createSegment.apply(this,o);e.appendSegment(s)}return e},O.createSegment=function(t){var e=arguments;if(!t)throw new Error("Type must be provided.");var i=O.segmentTypes[t];if(!i)throw new Error(t+" is not a recognized path segment type.");for(var n=[],r=arguments.length,o=1;o<r;o++)n.push(e[o]);return x(i,n)},O.prototype={appendSegment:function(t){var e,i=this.segments,n=i.length,r=0!==n?i[n-1]:null;if(Array.isArray(t)){if(!(t=t.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");for(var o=t.length,s=0;s<o;s++){var a=t[s];e=this.prepareSegment(a,r,null),i.push(e),r=e}}else{if(!t||!t.isSegment)throw new Error("Segment required.");e=this.prepareSegment(t,r,null),i.push(e)}},bbox:function(){var t,e=this.segments,i=e.length;if(0===i)return null;for(var n=0;n<i;n++){var r=e[n];if(r.isVisible){var o=r.bbox();t=t?t.union(o):o}}if(t)return t;var s=e[i-1];return new H(s.end.x,s.end.y,0,0)},clone:function(){for(var t=this.segments,e=t.length,i=new O,n=0;n<e;n++){var r=t[n].clone();i.appendSegment(r)}return i},closestPoint:function(t,e){var i=this.closestPointT(t,e);return i?this.pointAtT(i):null},closestPointLength:function(t,e){var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):e.segmentSubdivisions},r=this.closestPointT(t,n);return r?this.lengthAtT(r,n):0},closestPointNormalizedLength:function(t,e){var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):e.segmentSubdivisions},r=this.closestPointLength(t,n);if(0===r)return 0;var o=this.length(n);return 0===o?0:r/o},closestPointT:function(t,e){var i=this.segments,n=i.length;if(0===n)return null;for(var r,o=void 0===(e=e||{}).precision?this.PRECISION:e.precision,s=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):e.segmentSubdivisions,a=1/0,l=0;l<n;l++){var c=i[l],g=s[l];if(c.isVisible){var h=c.closestPointT(t,{precision:o,subdivisions:g}),u=c.pointAtT(h),d=new B(u,t).squaredLength();d<a&&(r={segmentIndex:l,value:h},a=d)}}return r||{segmentIndex:n-1,value:1}},closestPointTangent:function(t,e){var i=this.segments,n=i.length;if(0===n)return null;for(var r,o=void 0===(e=e||{}).precision?this.PRECISION:e.precision,s=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):e.segmentSubdivisions,a=1/0,l=0;l<n;l++){var c=i[l],g=s[l];if(c.isDifferentiable()){var h=c.closestPointT(t,{precision:o,subdivisions:g}),u=c.pointAtT(h),d=new B(u,t).squaredLength();d<a&&(r=c.tangentAtT(h),a=d)}}return r||null},containsPoint:function(t,e){var i=this.toPolylines(e);if(!i)return!1;for(var n=i.length,r=0,o=0;o<n;o++){i[o].containsPoint(t)&&r++}return r%2==1},divideAt:function(t,e){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):e.segmentSubdivisions},r=this.length(n)*t;return this.divideAtLength(r,n)},divideAtLength:function(t,e){var i=this.segments.length;if(0===i)return null;var n=!0;t<0&&(n=!1,t=-t);var r,o,s,a,l,c,g,h=void 0===(e=e||{}).precision?this.PRECISION:e.precision,u=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:h}):e.segmentSubdivisions,d=0;for(r=0;r<i;r++){var f=n?r:i-1-r;o=this.getSegment(f);var p=u[f],I=o.length({precision:h,subdivisions:p});if(o.isDifferentiable()&&(l=o,c=f,t<=d+I)){a=f,s=o.divideAtLength((n?1:-1)*(t-d),{precision:h,subdivisions:p});break}d+=I}if(!l)return null;s||(a=c,g=n?1:0,s=l.divideAtT(g));var m=this.clone();m.replaceSegment(a,s);var A=a,v=a+1,C=a+2;s[0].isDifferentiable()||(m.removeSegment(A),v-=1,C-=1);var w=m.getSegment(v).start;m.insertSegment(v,O.createSegment("M",w)),C+=1,s[1].isDifferentiable()||(m.removeSegment(C-1),C-=1);var y=C-A-1;for(r=C;r<m.segments.length;r++){var b=this.getSegment(r-y);if("Z"===(o=m.getSegment(r)).type&&!b.subpathStartSegment.end.equals(o.subpathStartSegment.end)){var N=O.createSegment("L",b.end);m.replaceSegment(r,N)}}return[new O(m.segments.slice(0,v)),new O(m.segments.slice(v))]},equals:function(t){if(!t)return!1;var e=this.segments,i=t.segments,n=e.length;if(i.length!==n)return!1;for(var r=0;r<n;r++){var o=e[r],s=i[r];if(o.type!==s.type||!o.equals(s))return!1}return!0},getSegment:function(t){var e=this.segments,i=e.length;if(0===i)throw new Error("Path has no segments.");if(t<0&&(t=i+t),i<=t||t<0)throw new Error("Index out of range.");return e[t]},getSegmentSubdivisions:function(t){for(var e=this.segments,i=e.length,n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=[],o=0;o<i;o++){var s=e[o].getSubdivisions({precision:n});r.push(s)}return r},insertSegment:function(t,e){var i,n=this.segments,r=n.length;if(t<0&&(t=r+t+1),r<t||t<0)throw new Error("Index out of range.");var o=null,s=null;if(0!==r&&(s=1<=t?(o=n[t-1]).nextSegment:n[0]),Array.isArray(e)){if(!(e=e.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");for(var a=e.length,l=0;l<a;l++){var c=e[l];i=this.prepareSegment(c,o,s),n.splice(t+l,0,i),o=i}}else{if(!e||!e.isSegment)throw new Error("Segment required.");i=this.prepareSegment(e,o,s),n.splice(t,0,i)}},intersectionWithLine:function(t,e){var i=null,n=this.toPolylines(e);if(!n)return null;for(var r=0,o=n.length;r<o;r++){var s=n[r],a=t.intersect(s);a&&(i||(i=[]),Array.isArray(a)?Array.prototype.push.apply(i,a):i.push(a))}return i},isDifferentiable:function(){for(var t=this.segments,e=t.length,i=0;i<e;i++){if(t[i].isDifferentiable())return!0}return!1},isValid:function(){var t=this.segments;return 0===t.length||"M"===t[0].type},length:function(t){var e=this.segments,i=e.length;if(0===i)return 0;for(var n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=void 0===t.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):t.segmentSubdivisions,o=0,s=0;s<i;s++){var a=e[s],l=r[s];o+=a.length({subdivisions:l})}return o},lengthAtT:function(t,e){var i=this.segments,n=i.length;if(0===n)return 0;var r=t.segmentIndex;if(r<0)return 0;var o=t.value;n<=r?(r=n-1,o=1):o<0?o=0:1<o&&(o=1);for(var s,a=void 0===(e=e||{}).precision?this.PRECISION:e.precision,l=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:a}):e.segmentSubdivisions,c=0,g=0;g<r;g++){var h=i[g];s=l[g],c+=h.length({precisison:a,subdivisions:s})}return h=i[r],s=l[r],c+=h.lengthAtT(o,{precisison:a,subdivisions:s})},pointAt:function(t,e){if(0===this.segments.length)return null;if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):e.segmentSubdivisions},r=this.length(n)*t;return this.pointAtLength(r,n)},pointAtLength:function(t,e){var i=this.segments,n=i.length;if(0===n)return null;if(0===t)return this.start.clone();var r=!0;t<0&&(r=!1,t=-t);for(var o,s=void 0===(e=e||{}).precision?this.PRECISION:e.precision,a=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):e.segmentSubdivisions,l=0,c=0;c<n;c++){var g=r?c:n-1-c,h=i[g],u=a[g],d=h.length({precision:s,subdivisions:u});if(h.isVisible){if(t<=l+d)return h.pointAtLength((r?1:-1)*(t-l),{precision:s,subdivisions:u});o=h}l+=d}return o?r?o.end:o.start:i[n-1].end.clone()},pointAtT:function(t){var e=this.segments,i=e.length;if(0===i)return null;var n=t.segmentIndex;if(n<0)return e[0].pointAtT(0);if(i<=n)return e[i-1].pointAtT(1);var r=t.value;return r<0?r=0:1<r&&(r=1),e[n].pointAtT(r)},PRECISION:3,prepareSegment:function(t,e,i){t.previousSegment=e,t.nextSegment=i,e&&(e.nextSegment=t),i&&(i.previousSegment=t);var n=t;return t.isSubpathStart&&(t.subpathStartSegment=t,n=i),n&&this.updateSubpathStartSegment(n),t},removeSegment:function(t){var e=this.segments,i=e.length;if(0===i)throw new Error("Path has no segments.");if(t<0&&(t=i+t),i<=t||t<0)throw new Error("Index out of range.");var n=e.splice(t,1)[0],r=n.previousSegment,o=n.nextSegment;r&&(r.nextSegment=o),o&&(o.previousSegment=r),n.isSubpathStart&&o&&this.updateSubpathStartSegment(o)},replaceSegment:function(t,e){var i,n=this.segments,r=n.length;if(0===r)throw new Error("Path has no segments.");if(t<0&&(t=r+t),r<=t||t<0)throw new Error("Index out of range.");var o=n[t],s=o.previousSegment,a=o.nextSegment,l=o.isSubpathStart;if(Array.isArray(e)){if(!(e=e.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");n.splice(t,1);for(var c=e.length,g=0;g<c;g++){var h=e[g];i=this.prepareSegment(h,s,a),n.splice(t+g,0,i),s=i,l&&i.isSubpathStart&&(l=!1)}}else{if(!e||!e.isSegment)throw new Error("Segment required.");i=this.prepareSegment(e,s,a),n.splice(t,1,i),l&&i.isSubpathStart&&(l=!1)}l&&a&&this.updateSubpathStartSegment(a)},scale:function(t,e,i){for(var n=this.segments,r=n.length,o=0;o<r;o++){n[o].scale(t,e,i)}return this},segmentAt:function(t,e){var i=this.segmentIndexAt(t,e);return i?this.getSegment(i):null},segmentAtLength:function(t,e){var i=this.segmentIndexAtLength(t,e);return i?this.getSegment(i):null},segmentIndexAt:function(t,e){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):e.segmentSubdivisions},r=this.length(n)*t;return this.segmentIndexAtLength(r,n)},segmentIndexAtLength:function(t,e){var i=this.segments,n=i.length;if(0===n)return null;var r=!0;t<0&&(r=!1,t=-t);for(var o=void 0===(e=e||{}).precision?this.PRECISION:e.precision,s=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):e.segmentSubdivisions,a=null,l=0,c=0;c<n;c++){var g=r?c:n-1-c,h=i[g],u=s[g],d=h.length({precision:o,subdivisions:u});if(h.isVisible){if(t<=l+d)return g;a=g}l+=d}return a},serialize:function(){if(!this.isValid())throw new Error("Invalid path segments.");return this.toString()},tangentAt:function(t,e){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var i=void 0===(e=e||{}).precision?this.PRECISION:e.precision,n={precision:i,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):e.segmentSubdivisions},r=this.length(n)*t;return this.tangentAtLength(r,n)},tangentAtLength:function(t,e){var i=this.segments,n=i.length;if(0===n)return null;var r=!0;t<0&&(r=!1,t=-t);for(var o,s=void 0===(e=e||{}).precision?this.PRECISION:e.precision,a=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):e.segmentSubdivisions,l=0,c=0;c<n;c++){var g=r?c:n-1-c,h=i[g],u=a[g],d=h.length({precision:s,subdivisions:u});if(h.isDifferentiable()){if(t<=l+d)return h.tangentAtLength((r?1:-1)*(t-l),{precision:s,subdivisions:u});o=h}l+=d}if(o){var f=r?1:0;return o.tangentAtT(f)}return null},tangentAtT:function(t){var e=this.segments,i=e.length;if(0===i)return null;var n=t.segmentIndex;if(n<0)return e[0].tangentAtT(0);if(i<=n)return e[i-1].tangentAtT(1);var r=t.value;return r<0?r=0:1<r&&(r=1),e[n].tangentAtT(r)},toPoints:function(t){var e=this.segments,i=e.length;if(0===i)return null;for(var n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=void 0===t.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):t.segmentSubdivisions,o=[],s=[],a=0;a<i;a++){var l=e[a];if(l.isVisible){var c=r[a];if(0<c.length){var g=c.map(function(t){return t.start});Array.prototype.push.apply(s,g)}else s.push(l.start)}else 0<s.length&&(s.push(e[a-1].end),o.push(s),s=[])}return 0<s.length&&(s.push(this.end),o.push(s)),o},toPolylines:function(t){var e=[],i=this.toPoints(t);if(!i)return null;for(var n=0,r=i.length;n<r;n++)e.push(new D(i[n]));return e},toString:function(){for(var t=this.segments,e=t.length,i="",n=0;n<e;n++){i+=t[n].serialize()+" "}return i.trim()},translate:function(t,e){for(var i=this.segments,n=i.length,r=0;r<n;r++){i[r].translate(t,e)}return this},updateSubpathStartSegment:function(t){for(var e=t.previousSegment;t&&!t.isSubpathStart;)t.subpathStartSegment=e?e.subpathStartSegment:null,t=(e=t).nextSegment}},Object.defineProperty(O.prototype,"start",{configurable:!0,enumerable:!0,get:function(){var t=this.segments,e=t.length;if(0===e)return null;for(var i=0;i<e;i++){var n=t[i];if(n.isVisible)return n.start}return t[e-1].end}}),Object.defineProperty(O.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.segments,e=t.length;if(0===e)return null;for(var i=e-1;0<=i;i--){var n=t[i];if(n.isVisible)return n.end}return t[e-1].end}});var E=function(t,e){if(!(this instanceof E))return new E(t,e);if("string"==typeof t){var i=t.split(-1===t.indexOf("@")?" ":"@");t=parseFloat(i[0]),e=parseFloat(i[1])}else Object(t)===t&&(e=t.y,t=t.x);this.x=void 0===t?0:t,this.y=void 0===e?0:e};E.fromPolar=function(t,e,i){i=i&&new E(i)||new E(0,0);var n=Z(t*g(e)),r=Z(t*h(e)),o=C(A(e));return o<90?r=-r:o<180?(n=-n,r=-r):o<270&&(n=-n),new E(i.x+n,i.y+r)},E.random=function(t,e,i,n){return new E(m(t,e),m(i,n))},E.prototype={chooseClosest:function(t){var e=t.length;if(1===e)return new E(t[0]);for(var i=null,n=1/0,r=0;r<e;r++){var o=new E(t[r]),s=this.squaredDistance(o);s<n&&(i=o,n=s)}return i},adhereToRect:function(t){return t.containsPoint(this)||(this.x=P(G(this.x,t.x),t.x+t.width),this.y=P(G(this.y,t.y),t.y+t.height)),this},angleBetween:function(t,e){var i=this.equals(t)||this.equals(e)?NaN:this.theta(e)-this.theta(t);return i<0&&(i+=360),i},bearing:function(t){return new B(this,t).bearing()},changeInAngle:function(t,e,i){return this.clone().offset(-t,-e).theta(i)-this.theta(i)},clone:function(){return new E(this)},cross:function(t,e){return t&&e?(e.x-this.x)*(t.y-this.y)-(e.y-this.y)*(t.x-this.x):NaN},difference:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),new E(this.x-(t||0),this.y-(e||0))},distance:function(t){return new B(this,t).length()},dot:function(t){return t?this.x*t.x+this.y*t.y:NaN},equals:function(t){return!!t&&this.x===t.x&&this.y===t.y},lerp:function(t,e){var i=this.x,n=this.y;return new E((1-e)*i+e*t.x,(1-e)*n+e*t.y)},magnitude:function(){return L(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return Z(t.x-this.x)+Z(t.y-this.y)},move:function(t,e){var i=y(new E(t).theta(this));return this.offset(g(i)*e,-h(i)*e)},normalize:function(t){var e=(t||1)/this.magnitude();return this.scale(e,e)},offset:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),this.x+=t||0,this.y+=e||0,this},reflection:function(t){return new E(t).move(this,this.distance(t))},rotate:function(t,e){t=t||new E(0,0),e=y(C(-e));var i=g(e),n=h(e),r=i*(this.x-t.x)-n*(this.y-t.y)+t.x,o=n*(this.x-t.x)+i*(this.y-t.y)+t.y;return this.x=r,this.y=o,this},round:function(t){var e=k(10,t||0);return this.x=a(this.x*e)/e,this.y=a(this.y*e)/e,this},scale:function(t,e,i){return i=i&&new E(i)||new E(0,0),this.x=i.x+t*(this.x-i.x),this.y=i.y+e*(this.y-i.y),this},snapToGrid:function(t,e){return this.x=I(this.x,t),this.y=I(this.y,e||t),this},squaredDistance:function(t){return new B(this,t).squaredLength()},theta:function(t){var e=-((t=new E(t)).y-this.y),i=t.x-this.x,n=u(e,i);return n<0&&(n=2*f+n),180*n/f},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new E(t)||new E(0,0);var e=this.x,i=this.y;return this.x=L((e-t.x)*(e-t.x)+(i-t.y)*(i-t.y)),this.y=y(t.theta(new E(e,i))),this},toString:function(){return this.x+"@"+this.y},update:function(t,e){return this.x=t||0,this.y=e||0,this},vectorAngle:function(t){return new E(0,0).angleBetween(this,t)}},E.prototype.translate=E.prototype.offset;var D=function(t){return this instanceof D?"string"==typeof t?new D.parse(t):void(this.points=Array.isArray(t)?t.map(E):[]):new D(t)};D.parse=function(t){if(""===(t=t.trim()))return new D;for(var e=[],i=t.split(/\s*,\s*|\s+/),n=i.length,r=0;r<n;r+=2)e.push({x:+i[r],y:+i[r+1]});return new D(e)},D.prototype={bbox:function(){var t=1/0,e=-1/0,i=1/0,n=-1/0,r=this.points,o=r.length;if(0===o)return null;for(var s=0;s<o;s++){var a=r[s],l=a.x,c=a.y;l<t&&(t=l),e<l&&(e=l),c<i&&(i=c),n<c&&(n=c)}return new H(t,i,e-t,n-i)},clone:function(){var t=this.points,e=t.length;if(0===e)return new D;for(var i=[],n=0;n<e;n++){var r=t[n].clone();i.push(r)}return new D(i)},closestPoint:function(t){var e=this.closestPointLength(t);return this.pointAtLength(e)},closestPointLength:function(t){var e,i=this.points,n=i.length;if(0===n)return 0;if(1===n)return 0;for(var r=1/0,o=0,s=n-1,a=0;a<s;a++){var l=new B(i[a],i[a+1]),c=l.length(),g=l.closestPointNormalizedLength(t),h=l.pointAt(g).squaredDistance(t);h<r&&(r=h,e=o+g*c),o+=c}return e},closestPointNormalizedLength:function(t){var e=this.closestPointLength(t);if(0===e)return 0;var i=this.length();return 0===i?0:e/i},closestPointTangent:function(t){var e=this.closestPointLength(t);return this.tangentAtLength(e)},containsPoint:function(t){var e=this.points,i=e.length;if(0===i)return!1;for(var n=t.x,r=t.y,o=i-1,s=0,a=0;s<i;s++){var l=e[o],c=e[s];if(t.equals(l))return!0;var g=new B(l,c);if(g.containsPoint(t))return!0;if(r<=l.y&&r>c.y||r>l.y&&r<=c.y){var h=l.x-n>c.x-n?l.x-n:c.x-n;if(0<=h){var u=new E(n+h,r),d=new B(t,u);g.intersect(d)&&a++}}o=s}return a%2==1},convexHull:function(){var t,e,i,n=this.points,r=n.length;if(0===r)return new D;for(t=0;t<r;t++)void 0===i?i=n[t]:n[t].y<i.y?i=n[t]:n[t].y===i.y&&n[t].x>i.x&&(i=n[t]);var o=[];for(t=0;t<r;t++){var s=i.theta(n[t]);0===s&&(s=360);var a=[n[t],t,s];o.push(a)}if(o.sort(function(t,e){var i=t[2]-e[2];return 0===i&&(i=e[1]-t[1]),i}),2<o.length){var l=o[o.length-1];o.unshift(l)}for(var c,g,h,u,d,f,p,I={},m=[];0!==o.length;)if(g=(c=o.pop())[0],!I.hasOwnProperty(c[0]+"@@"+c[1]))for(var A=!1;!A;)if(m.length<2)m.push(c),A=!0;else{u=(h=m.pop())[0];var v=(f=(d=m.pop())[0]).cross(u,g);if(v<0)m.push(d),m.push(h),m.push(c),A=!0;else if(0===v){var C=u.angleBetween(f,g);Z(C-180)<1e-10?(I[h[0]+"@@"+h[1]]=u,m.push(d)):u.equals(g)||f.equals(u)?(I[h[0]+"@@"+h[1]]=u,m.push(d)):Z((C+1)%360-1)<1e-10&&(m.push(d),o.push(h))}else I[h[0]+"@@"+h[1]]=u,m.push(d)}2<m.length&&m.pop();var w=-1;for(e=m.length,t=0;t<e;t++){var y=m[t][1];(void 0===p||y<p)&&(p=y,w=t)}var b=[];if(0<w){var N=m.slice(w),M=m.slice(0,w);b=N.concat(M)}else b=m;var x=[];for(e=b.length,t=0;t<e;t++)x.push(b[t][0]);return new D(x)},equals:function(t){if(!t)return!1;var e=this.points,i=t.points,n=e.length;if(i.length!==n)return!1;for(var r=0;r<n;r++){var o=e[r],s=t.points[r];if(!o.equals(s))return!1}return!0},intersectionWithLine:function(t){for(var e=new B(t),i=[],n=this.points,r=0,o=n.length-1;r<o;r++){var s=n[r],a=n[r+1],l=new B(s,a),c=e.intersectionWithLine(l);c&&i.push(c[0])}return 0<i.length?i:null},isDifferentiable:function(){var t=this.points,e=t.length;if(0===e)return!1;for(var i=e-1,n=0;n<i;n++){var r=t[n],o=t[n+1];if(new B(r,o).isDifferentiable())return!0}return!1},length:function(){var t=this.points,e=t.length;if(0===e)return 0;for(var i=0,n=e-1,r=0;r<n;r++)i+=t[r].distance(t[r+1]);return i},pointAt:function(t){var e=this.points,i=e.length;if(0===i)return null;if(1===i)return e[0].clone();if(t<=0)return e[0].clone();if(1<=t)return e[i-1].clone();var n=this.length()*t;return this.pointAtLength(n)},pointAtLength:function(t){var e=this.points,i=e.length;if(0===i)return null;if(1===i)return e[0].clone();var n=!0;t<0&&(n=!1,t=-t);for(var r=0,o=i-1,s=0;s<o;s++){var a=n?s:o-1-s,l=e[a],c=e[a+1],g=new B(l,c),h=l.distance(c);if(t<=r+h)return g.pointAtLength((n?1:-1)*(t-r));r+=h}return(n?e[i-1]:e[0]).clone()},scale:function(t,e,i){var n=this.points,r=n.length;if(0===r)return this;for(var o=0;o<r;o++)n[o].scale(t,e,i);return this},simplify:function(t){void 0===t&&(t={});var e=this.points;if(e.length<3)return this;for(var i=t.threshold||0,n=0;e[n+2];){var r=n+1,o=n+2,s=e[n],a=e[r],l=e[o];new B(s,l).closestPoint(a).distance(a)<=i?e.splice(r,1):n+=1}return this},tangentAt:function(t){var e=this.points.length;if(0===e)return null;if(1===e)return null;t<0&&(t=0),1<t&&(t=1);var i=this.length()*t;return this.tangentAtLength(i)},tangentAtLength:function(t){var e=this.points,i=e.length;if(0===i)return null;if(1===i)return null;var n,r=!0;t<0&&(r=!1,t=-t);for(var o=0,s=i-1,a=0;a<s;a++){var l=r?a:s-1-a,c=e[l],g=e[l+1],h=new B(c,g),u=c.distance(g);if(h.isDifferentiable()){if(t<=o+u)return h.tangentAtLength((r?1:-1)*(t-o));n=h}o+=u}if(n){var d=r?1:0;return n.tangentAt(d)}return null},toString:function(){return this.points+""},translate:function(t,e){var i=this.points,n=i.length;if(0===n)return this;for(var r=0;r<n;r++)i[r].translate(t,e);return this},serialize:function(){var t=this.points,e=t.length;if(0===e)return"";for(var i="",n=0;n<e;n++){var r=t[n];i+=r.x+","+r.y+" "}return i.trim()}},Object.defineProperty(D.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(D.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});var H=function(t,e,i,n){if(!(this instanceof H))return new H(t,e,i,n);Object(t)===t&&(e=t.y,i=t.width,n=t.height,t=t.x),this.x=void 0===t?0:t,this.y=void 0===e?0:e,this.width=void 0===i?0:i,this.height=void 0===n?0:n};H.fromEllipse=function(t){return t=new w(t),new H(t.x-t.a,t.y-t.b,2*t.a,2*t.b)},H.prototype={bbox:function(t){if(!t)return this.clone();var e=y(t),i=Z(h(e)),n=Z(g(e)),r=this.width*n+this.height*i,o=this.width*i+this.height*n;return new H(this.x+(this.width-r)/2,this.y+(this.height-o)/2,r,o)},bottomLeft:function(){return new E(this.x,this.y+this.height)},bottomLine:function(){return new B(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new E(this.x+this.width/2,this.y+this.height)},center:function(){return new E(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new H(this)},containsPoint:function(t){return(t=new E(t)).x>=this.x&&t.x<=this.x+this.width&&t.y>=this.y&&t.y<=this.y+this.height},containsRect:function(t){var e=new H(this).normalize(),i=new H(t).normalize(),n=e.width,r=e.height,o=i.width,s=i.height;if(!(n&&r&&o&&s))return!1;var a=e.x,l=e.y,c=i.x,g=i.y;return o+=c,n+=a,s+=g,r+=l,a<=c&&o<=n&&l<=g&&s<=r},corner:function(){return new E(this.x+this.width,this.y+this.height)},equals:function(t){var e=new H(this).normalize(),i=new H(t).normalize();return e.x===i.x&&e.y===i.y&&e.width===i.width&&e.height===i.height},inflate:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e,this},intersect:function(t){var e=this.origin(),i=this.corner(),n=t.origin(),r=t.corner();if(r.x<=e.x||r.y<=e.y||n.x>=i.x||n.y>=i.y)return null;var o=G(e.x,n.x),s=G(e.y,n.y);return new H(o,s,P(i.x,r.x)-o,P(i.y,r.y)-s)},intersectionWithLine:function(t){var e,i,n=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],r=[],o=[],s=n.length;for(i=0;i<s;i++)null!==(e=t.intersect(n[i]))&&o.indexOf(e.toString())<0&&(r.push(e),o.push(e.toString()));return 0<r.length?r:null},intersectionWithLineFromCenterToPoint:function(t,e){t=new E(t);var i,n=new E(this.x+this.width/2,this.y+this.height/2);e&&t.rotate(n,e);for(var r=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],o=new B(n,t),s=r.length-1;0<=s;--s){var a=r[s].intersection(o);if(null!==a){i=a;break}}return i&&e&&i.rotate(n,-e),i},leftLine:function(){return new B(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new E(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,e){var i,n,r,o,s,a,l,c;t=new H(t),e||(e=t.center());var g=e.x,h=e.y;i=n=r=o=s=a=l=c=1/0;var u=t.topLeft();u.x<g&&(i=(this.x-g)/(u.x-g)),u.y<h&&(s=(this.y-h)/(u.y-h));var d=t.bottomRight();d.x>g&&(n=(this.x+this.width-g)/(d.x-g)),d.y>h&&(a=(this.y+this.height-h)/(d.y-h));var f=t.topRight();f.x>g&&(r=(this.x+this.width-g)/(f.x-g)),f.y<h&&(l=(this.y-h)/(f.y-h));var p=t.bottomLeft();return p.x<g&&(o=(this.x-g)/(p.x-g)),p.y>h&&(c=(this.y+this.height-h)/(p.y-h)),{sx:P(i,n,r,o),sy:P(s,a,l,c)}},maxRectUniformScaleToFit:function(t,e){var i=this.maxRectScaleToFit(t,e);return P(i.sx,i.sy)},moveAndExpand:function(t){return this.x+=t.x||0,this.y+=t.y||0,this.width+=t.width||0,this.height+=t.height||0,this},normalize:function(){var t=this.x,e=this.y,i=this.width,n=this.height;return this.width<0&&(t=this.x+this.width,i=-this.width),this.height<0&&(e=this.y+this.height,n=-this.height),this.x=t,this.y=e,this.width=i,this.height=n,this},offset:function(t,e){return E.prototype.offset.call(this,t,e)},origin:function(){return new E(this.x,this.y)},pointNearestToPoint:function(t){if(t=new E(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new E(this.x+this.width,t.y);case"left":return new E(this.x,t.y);case"bottom":return new E(t.x,this.y+this.height);case"top":return new E(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new B(this.topRight(),this.bottomRight())},rightMiddle:function(){return new E(this.x+this.width,this.y+this.height/2)},round:function(t){var e=k(10,t||0);return this.x=a(this.x*e)/e,this.y=a(this.y*e)/e,this.width=a(this.width*e)/e,this.height=a(this.height*e)/e,this},scale:function(t,e,i){return i=this.origin().scale(t,e,i),this.x=i.x,this.y=i.y,this.width*=t,this.height*=e,this},sideNearestToPoint:function(t){var e=(t=new E(t)).x-this.x,i=this.x+this.width-t.x,n=t.y-this.y,r=e,o="left";return i<r&&(r=i,o="right"),n<r&&(r=n,o="top"),this.y+this.height-t.y<r&&(o="bottom"),o},snapToGrid:function(t,e){var i=this.origin().snapToGrid(t,e),n=this.corner().snapToGrid(t,e);return this.x=i.x,this.y=i.y,this.width=n.x-i.x,this.height=n.y-i.y,this},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},topLine:function(){return new B(this.topLeft(),this.topRight())},topMiddle:function(){return new E(this.x+this.width/2,this.y)},topRight:function(){return new E(this.x+this.width,this.y)},toString:function(){return this.origin().toString()+" "+this.corner().toString()},union:function(t){var e=new H(t),i=this.x,n=this.y,r=this.width,o=this.height,s=e.x,a=e.y,l=e.width,c=e.height,g=e.x=P(i,s),h=e.y=P(n,a);return e.width=G(i+r,s+l)-g,e.height=G(n+o,a+c)-h,e}},H.prototype.bottomRight=H.prototype.corner,H.prototype.topLeft=H.prototype.origin,H.prototype.translate=H.prototype.offset;var C=function(t){return t%360+(t<0?360:0)},I=function(t,e){return e*a(t/e)},A=function(t){return 180*t/f%360},y=function(t,e){return(t=(e=e||!1)?t:t%360)*f/180},m=function(t,e){if(void 0===e)e=void 0===t?1:t,t=0;else if(e<t){var i=t;t=e,e=i}return d(o.random()*(e-t+1)+t)},v=w,b=B,N=E,M=H;function x(t,e){return e.unshift(null),new(Function.prototype.bind.apply(t,e))}function z(t){var e,i,n=arguments,r=[];for(i=arguments.length,e=1;e<i;e++)r.push(n[e]);if(!t)throw new Error("Missing a parent object.");var o=Object.create(t);for(i=r.length,e=0;e<i;e++){var s,a,l=r[e];for(a in l)l.hasOwnProperty(a)&&(delete o[a],s=Object.getOwnPropertyDescriptor(l,a),Object.defineProperty(o,a,s))}return o}var j={bbox:function(){throw new Error("Declaration missing for virtual function.")},clone:function(){throw new Error("Declaration missing for virtual function.")},closestPoint:function(){throw new Error("Declaration missing for virtual function.")},closestPointLength:function(){throw new Error("Declaration missing for virtual function.")},closestPointNormalizedLength:function(){throw new Error("Declaration missing for virtual function.")},closestPointT:function(t){if(this.closestPointNormalizedLength)return this.closestPointNormalizedLength(t);throw new Error("Neither closestPointT() nor closestPointNormalizedLength() function is implemented.")},closestPointTangent:function(){throw new Error("Declaration missing for virtual functi