text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).KldIntersections={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],i=!0,r=!1,a=void 0;try{for(var s,o=t[Symbol.iterator]();!(i=(s=o.next()).done)&&(n.push(s.value),!e||n.length!==e);i=!0);}catch(t){r=!0,a=t}finally{try{i||null==o.return||o.return()}finally{if(r)throw a}}return n}(t,e)||o(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||o(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return l(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(t,e):void 0}}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function u(t){if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=o(t))){var e=0,n=function(){};return{s:n,n:function(){return e>=t.length?{done:!0}:{done:!1,value:t[e++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,r,a=!0,s=!1;return{s:function(){i=t[Symbol.iterator]()},n:function(){var t=i.next();return a=t.done,t},e:function(t){s=!0,r=t},f:function(){try{a||null==i.return||i.return()}finally{if(s)throw r}}}}var h=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;n(this,t),this.x=e,this.y=i}return r(t,[{key:"clone",value:function(){return new this.constructor(this.x,this.y)}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,e){return Math.abs(this.x-t.x)<e&&Math.abs(this.y-t.y)<e}},{key:"lerp",value:function(t,e){var n=1-e;return new this.constructor(this.x*n+t.x*e,this.y*n+t.y*e)}},{key:"distanceFrom",value:function(t){var e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}},{key:"min",value:function(t){return new this.constructor(Math.min(this.x,t.x),Math.min(this.y,t.y))}},{key:"max",value:function(t){return new this.constructor(Math.max(this.x,t.x),Math.max(this.y,t.y))}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y+t.e,t.b*this.x+t.d*this.y+t.f)}},{key:"toString",value:function(){return"point(".concat(this.x,",").concat(this.y,")")}}]),t}(),y=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;n(this,t),this.x=e,this.y=i}return r(t,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"magnitude",value:function(){return this.x*this.x+this.y*this.y}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"cross",value:function(t){return this.x*t.y-this.y*t.x}},{key:"determinant",value:function(t){return this.x*t.y-this.y*t.x}},{key:"unit",value:function(){return this.divide(this.length())}},{key:"add",value:function(t){return new this.constructor(this.x+t.x,this.y+t.y)}},{key:"subtract",value:function(t){return new this.constructor(this.x-t.x,this.y-t.y)}},{key:"multiply",value:function(t){return new this.constructor(this.x*t,this.y*t)}},{key:"divide",value:function(t){return new this.constructor(this.x/t,this.y/t)}},{key:"angleBetween",value:function(t){var e=this.dot(t)/(this.length()*t.length());e=Math.max(-1,Math.min(e,1));var n=Math.acos(e);return this.cross(t)<0?-n:n}},{key:"perp",value:function(){return new this.constructor(-this.y,this.x)}},{key:"perpendicular",value:function(t){return this.subtract(this.project(t))}},{key:"project",value:function(t){var e=this.dot(t)/t.dot(t);return t.multiply(e)}},{key:"transform",value:function(t){return new this.constructor(t.a*this.x+t.c*this.y,t.b*this.x+t.d*this.y)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y}},{key:"precisionEquals",value:function(t,e){return Math.abs(this.x-t.x)<e&&Math.abs(this.y-t.y)<e}},{key:"toString",value:function(){return"vector(".concat(this.x,",").concat(this.y,")")}}],[{key:"fromPoints",value:function(e,n){return new t(n.x-e.x,n.y-e.y)}}]),t}(),c=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;n(this,t),this.a=e,this.b=i,this.c=r,this.d=a,this.e=s,this.f=o}return r(t,[{key:"multiply",value:function(t){return this.isIdentity()?t:t.isIdentity()?this:new this.constructor(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}},{key:"inverse",value:function(){if(this.isIdentity())return this;var t=this.a*this.d-this.b*this.c;if(0===t)throw new Error("Matrix is not invertible");var e=1/t,n=this.f*this.c-this.e*this.d,i=this.e*this.b-this.f*this.a;return new this.constructor(this.d*e,-this.b*e,-this.c*e,this.a*e,n*e,i*e)}},{key:"translate",value:function(t,e){return new this.constructor(this.a,this.b,this.c,this.d,this.a*t+this.c*e+this.e,this.b*t+this.d*e+this.f)}},{key:"scale",value:function(t){return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.e,this.f)}},{key:"scaleAt",value:function(t,e){var n=e.x-t*e.x,i=e.y-t*e.y;return new this.constructor(this.a*t,this.b*t,this.c*t,this.d*t,this.a*n+this.c*i+this.e,this.b*n+this.d*i+this.f)}},{key:"scaleNonUniform",value:function(t,e){return new this.constructor(this.a*t,this.b*t,this.c*e,this.d*e,this.e,this.f)}},{key:"scaleNonUniformAt",value:function(t,e,n){var i=n.x-t*n.x,r=n.y-e*n.y;return new this.constructor(this.a*t,this.b*t,this.c*e,this.d*e,this.a*i+this.c*r+this.e,this.b*i+this.d*r+this.f)}},{key:"rotate",value:function(t){var e=Math.cos(t),n=Math.sin(t);return new this.constructor(this.a*e+this.c*n,this.b*e+this.d*n,this.a*-n+this.c*e,this.b*-n+this.d*e,this.e,this.f)}},{key:"rotateAt",value:function(t,e){var n=Math.cos(t),i=Math.sin(t),r=e.x,a=e.y,s=this.a*n+this.c*i,o=this.b*n+this.d*i,l=this.c*n-this.a*i,u=this.d*n-this.b*i;return new this.constructor(s,o,l,u,(this.a-s)*r+(this.c-l)*a+this.e,(this.b-o)*r+(this.d-u)*a+this.f)}},{key:"rotateFromVector",value:function(t){var e=t.unit(),n=e.x,i=e.y;return new this.constructor(this.a*n+this.c*i,this.b*n+this.d*i,this.a*-i+this.c*n,this.b*-i+this.d*n,this.e,this.f)}},{key:"flipX",value:function(){return new this.constructor(-this.a,-this.b,this.c,this.d,this.e,this.f)}},{key:"flipY",value:function(){return new this.constructor(this.a,this.b,-this.c,-this.d,this.e,this.f)}},{key:"skewX",value:function(t){var e=Math.tan(t);return new this.constructor(this.a,this.b,this.c+this.a*e,this.d+this.b*e,this.e,this.f)}},{key:"skewY",value:function(t){var e=Math.tan(t);return new this.constructor(this.a+this.c*e,this.b+this.d*e,this.c,this.d,this.e,this.f)}},{key:"isIdentity",value:function(){return 1===this.a&&0===this.b&&0===this.c&&1===this.d&&0===this.e&&0===this.f}},{key:"isInvertible",value:function(){return this.a*this.d-this.b*this.c!=0}},{key:"getScale",value:function(){return{scaleX:Math.sqrt(this.a*this.a+this.c*this.c),scaleY:Math.sqrt(this.b*this.b+this.d*this.d)}}},{key:"getDecomposition",value:function(){var t=.5*(this.a+this.d),e=.5*(this.a-this.d),n=.5*(this.b+this.c),i=.5*(this.b-this.c),r=Math.sqrt(t*t+i*i),a=Math.sqrt(e*e+n*n),s=r+a,o=r-a,l=Math.atan2(n,e),u=Math.atan2(i,t),h=.5*(u-l),y=.5*(u+l);return{translation:this.constructor.translation(this.e,this.f),rotation:this.constructor.rotation(y),scale:this.constructor.nonUniformScaling(s,o),rotation0:this.constructor.rotation(h)}}},{key:"equals",value:function(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}},{key:"precisionEquals",value:function(t,e){return Math.abs(this.a-t.a)<e&&Math.abs(this.b-t.b)<e&&Math.abs(this.c-t.c)<e&&Math.abs(this.d-t.d)<e&&Math.abs(this.e-t.e)<e&&Math.abs(this.f-t.f)<e}},{key:"toString",value:function(){return"matrix(".concat(this.a,",").concat(this.b,",").concat(this.c,",").concat(this.d,",").concat(this.e,",").concat(this.f,")")}}],[{key:"translation",value:function(e,n){return new t(1,0,0,1,e,n)}},{key:"scaling",value:function(e){return new t(e,0,0,e,0,0)}},{key:"scalingAt",value:function(e,n){return new t(e,0,0,e,n.x-n.x*e,n.y-n.y*e)}},{key:"nonUniformScaling",value:function(e,n){return new t(e,0,0,n,0,0)}},{key:"nonUniformScalingAt",value:function(e,n,i){return new t(e,0,0,n,i.x-i.x*e,i.y-i.y*n)}},{key:"rotation",value:function(e){var n=Math.cos(e),i=Math.sin(e);return new t(n,i,-i,n,0,0)}},{key:"rotationAt",value:function(e,n){var i=Math.cos(e),r=Math.sin(e);return new t(i,r,-r,i,n.x-n.x*i+n.y*r,n.y-n.y*i-n.x*r)}},{key:"rotationFromVector",value:function(e){var n=e.unit(),i=n.x,r=n.y;return new t(i,r,-r,i,0,0)}},{key:"xFlip",value:function(){return new t(-1,0,0,1,0,0)}},{key:"yFlip",value:function(){return new t(1,0,0,-1,0,0)}},{key:"xSkew",value:function(e){return new t(1,0,Math.tan(e),1,0,0)}},{key:"ySkew",value:function(e){return new t(1,Math.tan(e),0,1,0,0)}}]),t}();function f(t){return"number"==typeof t?t?t<0?-1:1:t==t?t:NaN:NaN}c.IDENTITY=new c,c.IDENTITY.isIdentity=function(){return!0};var p=function(){function t(){n(this,t),this.coefs=[];for(var e=arguments.length-1;e>=0;e--)this.coefs.push(e<0||arguments.length<=e?void 0:arguments[e]);this._variable="t",this._s=0}return r(t,[{key:"clone",value:function(){var e=new t;return e.coefs=this.coefs.slice(),e}},{key:"eval",value:function(t){if(isNaN(t))throw new TypeError("Parameter must be a number. Found '".concat(t,"'"));for(var e=0,n=this.coefs.length-1;n>=0;n--)e=e*t+this.coefs[n];return e}},{key:"add",value:function(e){for(var n=new t,i=this.getDegree(),r=e.getDegree(),a=Math.max(i,r),s=0;s<=a;s++){var o=s<=i?this.coefs[s]:0,l=s<=r?e.coefs[s]:0;n.coefs[s]=o+l}return n}},{key:"multiply",value:function(e){for(var n=new t,i=0;i<=this.getDegree()+e.getDegree();i++)n.coefs.push(0);for(var r=0;r<=this.getDegree();r++)for(var a=0;a<=e.getDegree();a++)n.coefs[r+a]+=this.coefs[r]*e.coefs[a];return n}},{key:"divideEqualsScalar",value:function(t){for(var e=0;e<this.coefs.length;e++)this.coefs[e]/=t}},{key:"simplifyEquals",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e-12,e=this.getDegree();e>=0&&Math.abs(this.coefs[e])<=t;e--)this.coefs.pop()}},{key:"removeZerosEquals",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e-15,e=this.coefs,n=10*t*Math.abs(e.reduce(function(t,e){return Math.abs(e)>Math.abs(t)?e:t})),i=0;i<e.length-1;i++)Math.abs(e[i])<n&&(e[i]=0);return this}},{key:"monicEquals",value:function(){var t=this.coefs;return 1!==t[t.length-1]&&this.divideEqualsScalar(t[t.length-1]),this}},{key:"toString",value:function(){for(var t=[],e=[],n=this.coefs.length-1;n>=0;n--){var i=Math.round(1e3*this.coefs[n])/1e3;if(0!==i){var r=i<0?" - ":" + ";i=Math.abs(i),n>0&&(1===i?i=this._variable:i+=this._variable),n>1&&(i+="^"+n),e.push(r),t.push(i)}}e[0]=" + "===e[0]?"":"-";for(var a="",s=0;s<t.length;s++)a+=e[s]+t[s];return a}},{key:"bisection",value:function(t,e){var n,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-6,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:15,a=this.eval(t),s=this.eval(e);if(Math.abs(a)<=i)n=t;else if(Math.abs(s)<=i)n=e;else if(a*s<=0)for(var o=Math.log(e-t),l=Math.LN10*r,u=Math.ceil((o+l)/Math.LN2),h=0;h<u;h++){n=.5*(t+e);var y=this.eval(n);if(Math.abs(y)<=i)break;y*a<0?(e=n,s=y):(t=n,a=y)}return n}},{key:"trapezoid",value:function(t,e,n){if(isNaN(t)||isNaN(e)||isNaN(n))throw new TypeError("Parameters must be numbers");var i=e-t;if(1===n){var r=this.eval(t),a=this.eval(e);this._s=.5*i*(r+a)}else{for(var s=1<<n-2,o=i/s,l=t+.5*o,u=0,h=0;h<s;h++)u+=this.eval(l),l+=o;this._s=.5*(this._s+i*u/s)}if(isNaN(this._s))throw new TypeError("this._s is NaN");return this._s}},{key:"simpson",value:function(t,e){if(isNaN(t)||isNaN(e))throw new TypeError("Parameters must be numbers");for(var n=e-t,i=.5*n*(this.eval(t)+this.eval(e)),r=i,a=4*i/3,s=a,o=i,l=1,u=2;u<=20;u++){for(var h=n/l,y=t+.5*h,c=0,f=1;f<=l;f++)c+=this.eval(y),y+=h;if(a=(4*(i=r=.5*(r+n*c/l))-o)/3,Math.abs(a-s)<1e-7*Math.abs(s))break;s=a,o=i,l<<=1}return a}},{key:"romberg",value:function(e,n){if(isNaN(e)||isNaN(n))throw new TypeError("Parameters must be numbers");var i=new Array(21),r=new Array(21),a={y:0,dy:0};r[0]=1;for(var s=1;s<=20&&(i[s-1]=this.trapezoid(e,n,s),!(s>=3&&(a=t.interpolate(r,i,3,s-3,0),Math.abs(a.dy)<=1e-6*a.y)));s++)i[s]=i[s-1],r[s]=.25*r[s-1];return a.y}},{key:"zeroErrorEstimate",value:function(t){if(void 0===t){var e=this.bounds();t=Math.max(Math.abs(e.minX),Math.abs(e.maxX))}if(t<.001)return 2*Math.abs(this.eval(1e-15));var n=this.coefs.length-1,i=this.coefs[n];return 10*1e-15*this.coefs.reduce(function(e,n,r){var a=n/i*Math.pow(t,r);return a>e?a:e},0)}},{key:"boundsUpperRealFujiwara",value:function(){var t=this.coefs,e=t.length-1,n=t[e];1!==n&&(t=this.coefs.map(function(t){return t/n}));var i,r=t.map(function(t,n){return n<e?Math.pow(Math.abs(0===n?t/2:t),1/(e-n)):t}),a=function(t,e,n){return i(n)&&(t.max<e?(t.nearmax=t.max,t.max=e):t.nearmax<e&&(t.nearmax=e)),t};i=function(n){return n<e&&t[n]<0};var s=r.reduce(a,{max:0,nearmax:0});return i=function(n){return n<e&&(e%2==n%2?t[n]<0:t[n]>0)},{negX:-2*r.reduce(a,{max:0,nearmax:0}).max,posX:2*s.max}}},{key:"boundsLowerRealFujiwara",value:function(){var e=new t;e.coefs=this.coefs.slice().reverse();var n=e.boundsUpperRealFujiwara();return n.negX=1/n.negX,n.posX=1/n.posX,n}},{key:"bounds",value:function(){var t=this.boundsUpperRealFujiwara(),e={minX:t.negX,maxX:t.posX};return 0===t.negX&&0===t.posX?e:(0===t.negX?e.minX=this.boundsLowerRealFujiwara().posX:0===t.posX&&(e.maxX=this.boundsLowerRealFujiwara().negX),e.minX>e.maxX&&(e.minX=e.maxX=0),e)}},{key:"boundUpperAbsRouche",value:function(){var t=this.coefs,e=t.length-1;return 1+t.reduce(function(t,n,i){return i!==e&&t<(n=Math.abs(n))?n:t},0)/Math.abs(t[e])}},{key:"boundLowerAbsRouche",value:function(){var t=this.coefs,e=t.reduce(function(t,e,n){return 0!==n&&t<(e=Math.abs(e))?e:t},0);return Math.abs(t[0])/(Math.abs(t[0])+e)}},{key:"boundsRealLaguerre",value:function(){var t=this.coefs,e=t.length-1,n=-t[e-1]/(e*t[e]),i=t[e-1]*t[e-1]-2*e/(e-1)*t[e]*t[e-2],r=(e-1)/(e*t[e])*Math.sqrt(i);return r<0&&(r=-r),{minX:n-r,maxX:n+r}}},{key:"countRootsDescartes",value:function(){var t=this.coefs,e=t.length-1,n=t.reduce(function(t,e,n){return 0!==t.prev_a&&0!==e&&(t.prev_a<0==e>0&&t.pos++,n%2==0!=t.prev_a<0==(n%2==1!=e>0)&&t.neg++),t.prev_a=e,t},{pos:0,neg:0,prev_a:0});return{maxRealPos:n.pos,maxRealNeg:n.neg,minComplex:e-(n.pos+n.neg)}}},{key:"getDegree",value:function(){return this.coefs.length-1}},{key:"getDerivative",value:function(){for(var e=new t,n=1;n<this.coefs.length;n++)e.coefs.push(n*this.coefs[n]);return e}},{key:"getRoots",value:function(){var t;switch(this.simplifyEquals(),this.getDegree()){case 0:t=[];break;case 1:t=this.getLinearRoot();break;case 2:t=this.getQuadraticRoots();break;case 3:t=this.getCubicRoots();break;case 4:t=this.getQuarticRoots();break;default:t=[]}return t}},{key:"getRootsInInterval",value:function(t,e){var n=[];function i(t){"number"==typeof t&&n.push(t)}if(0===this.getDegree())throw new RangeError("Unexpected empty polynomial");if(1===this.getDegree())i(this.bisection(t,e));else{var r=this.getDerivative().getRootsInInterval(t,e);if(r.length>0){i(this.bisection(t,r[0]));for(var a=0;a<=r.length-2;a++)i(this.bisection(r[a],r[a+1]));i(this.bisection(r[r.length-1],e))}else i(this.bisection(t,e))}return n}},{key:"getLinearRoot",value:function(){var t=[],e=this.coefs[1];return 0!==e&&t.push(-this.coefs[0]/e),t}},{key:"getQuadraticRoots",value:function(){var t=[];if(2===this.getDegree()){var e=this.coefs[2],n=this.coefs[1]/e,i=n*n-4*(this.coefs[0]/e);if(i>0){var r=Math.sqrt(i);t.push(.5*(-n+r)),t.push(.5*(-n-r))}else 0===i&&t.push(.5*-n)}return t}},{key:"getCubicRoots",value:function(){var t=[];if(3===this.getDegree()){var e=this.coefs[3],n=this.coefs[2]/e,i=this.coefs[1]/e,r=(3*i-n*n)/3,a=(2*n*n*n-9*i*n+27*(this.coefs[0]/e))/27,s=n/3,o=a*a/4+r*r*r/27,l=a/2,u=this.zeroErrorEstimate();if(Math.abs(o)<=u&&(o=0),o>0){var h,y=Math.sqrt(o),c=-l+y;h=c>=0?Math.pow(c,1/3):-Math.pow(-c,1/3),(c=-l-y)>=0?h+=Math.pow(c,1/3):h-=Math.pow(-c,1/3),t.push(h-s)}else if(o<0){var f=Math.sqrt(-r/3),p=Math.atan2(Math.sqrt(-o),-l)/3,v=Math.cos(p),x=Math.sin(p),d=Math.sqrt(3);t.push(2*f*v-s),t.push(-f*(v+d*x)-s),t.push(-f*(v-d*x)-s)}else{var m;m=l>=0?-Math.pow(l,1/3):Math.pow(-l,1/3),t.push(2*m-s),t.push(-m-s)}}return t}},{key:"getQuarticRoots",value:function(){var e=[],n=this.getDegree();if(4===n){var i=new t;i.coefs=this.coefs.slice(),i.divideEqualsScalar(i.coefs[n]);Math.abs(i.coefs[0])<10*1e-15*Math.abs(i.coefs[3])&&(i.coefs[0]=0);for(var r=i.getDerivative(),a=r.getRoots().sort(function(t,e){return t-e}),s=[],o=a.length-1,l=this.bounds(),u=Math.max(Math.abs(l.minX),Math.abs(l.maxX)),h=this.zeroErrorEstimate(u),y=0;y<=o;y++)s.push(i.eval(a[y]));for(var c=0;c<=o;c++)Math.abs(s[c])<h&&(s[c]=0);var p=0,v=Math.max(.1*(l.maxX-l.minX)/n,1e-15),x=[],d=[];if(o>-1){for(0!==s[0]?f(s[0])!==f(i.eval(a[0]-v)-s[0])&&(x.push(a[0]-v),d.push([l.minX,a[0]])):(e.push(a[0],a[0]),p++);p<o;p++)0===s[p+1]?(e.push(a[p+1],a[p+1]),p++):f(s[p])!==f(s[p+1])&&(x.push((a[p]+a[p+1])/2),d.push([a[p],a[p+1]]));0!==s[o]&&f(s[o])!==f(i.eval(a[o]+v)-s[o])&&(x.push(a[o]+v),d.push([a[o],l.maxX]))}var m=function(t){return i.eval(t)},w=function(t){return r.eval(t)};if(x.length>0)for(p=0;p<x.length;p++)x[p]=t.newtonSecantBisection(x[p],m,w,32,d[p][0],d[p][1]);e=e.concat(x)}return e}}],[{key:"interpolate",value:function(t,e,n,i,r){if(t.constructor!==Array||e.constructor!==Array)throw new TypeError("xs and ys must be arrays");if(isNaN(n)||isNaN(i)||isNaN(r))throw new TypeError("n, offset, and x must be numbers");var a,s,o=0,l=new Array(n),u=new Array(n),h=0,y=Math.abs(r-t[i]);for(a=0;a<n;a++){var c=Math.abs(r-t[i+a]);c<y&&(h=a,y=c),l[a]=u[a]=e[i+a]}s=e[i+h],h--;for(var f=1;f<n;f++){for(a=0;a<n-f;a++){var p=t[i+a]-r,v=t[i+a+f]-r,x=l[a+1]-u[a],d=p-v;if(0===d)throw new RangeError("Unable to interpolate polynomial. Two numbers in n were identical (to within roundoff)");d=x/d,u[a]=v*d,l[a]=p*d}s+=o=2*(h+1)<n-f?l[h+1]:u[h--]}return{y:s,dy:o}}},{key:"newtonSecantBisection",value:function(t,e,n,i,r,a){var s,o,l,u,h,y,c,p=0,v=0;s=t;var x=Math.pow(10,-14),d="number"==typeof r&&"number"==typeof a;if(d){if(r>a)throw new RangeError("Min must be greater than max");if(y=e(r),c=e(a),f(y)===f(c))throw new RangeError("Y values of bounds must be of opposite sign")}for(var m=function(){return Math.abs(l)<=x*Math.abs(s)||v===s-l-s},w=0;w<i;w++){if(0===(o=n(s))){if(0===p)throw new RangeError("df(x) is zero");o=p}if(p=o,h=e(s),u=s-(l=h/o),m())break;if(d){if(f(h)===f(c))a=s,c=h;else{if(f(h)!==f(y)){s=u;break}r=s,y=h}if(u<r||u>a){if(f(y)===f(c))break;var b=c-y,g=a-r;if(l=0===b?s-(r+.5*g):Math.abs(b/Math.min(y,c))>50?s-(r+g*(.5+(Math.abs(y)<Math.abs(c)?-.25:.25))):s-(r-y/b*g),u=s-l,m())break}}v=s-u,s=u}return s}}]),t}(),v=function(){function t(e,i){n(this,t),this.type=e,this.text=i}return r(t,[{key:"typeis",value:function(t){return this.type===t}}]),t}();v.UNDEFINED=0,v.COMMAND=1,v.NUMBER=2,v.EOD=3;var x=function(){function t(e){n(this,t),null==e&&(e=""),this.setPathData(e)}return r(t,[{key:"setPathData",value:function(t){if("string"!=typeof t)throw new TypeError("The first parameter must be a string");this._pathData=t}},{key:"getNextToken",value:function(){for(var t=null,e=this._pathData;null===t;)if(null===e||""===e)t=new v(v.EOD,"");else if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([AaCcHhLlMmQqSsTtVvZz])/))t=new v(v.COMMAND,RegExp.$1),e=e.substr(RegExp.$1.length);else{if(!e.match(/^(([-+]?\d+(\.\d*)?|[-+]?\.\d+)([eE][-+]?\d+)?)/))throw new SyntaxError("Unrecognized path data: ".concat(e));t=new v(v.NUMBER,RegExp.$1),e=e.substr(RegExp.$1.length)}return this._pathData=e,t}}]),t}(),d=function(){function t(){n(this,t),this._lexer=new x,this._handler=null}return r(t,[{key:"parseData",value:function(e){if("string"!=typeof e)throw new TypeError("The first parameter must be a string: ".concat(e));null!==this._handler&&"function"==typeof this._handler.beginParse&&this._handler.beginParse();var n=this._lexer;n.setPathData(e);for(var i="BOP",r=null,a=n.getNextToken();!1===a.typeis(v.EOD);){var s=void 0,o=[];switch(a.type){case v.COMMAND:if("BOP"===i&&"M"!==a.text&&"m"!==a.text)throw new SyntaxError("New paths must begin with a moveto command. Found '".concat(a.text,"'"));i=a.text,s=t.PARAMCOUNT[a.text.toUpperCase()],a=n.getNextToken();break;case v.NUMBER:if("BOP"===i)throw new SyntaxError("New paths must begin with a moveto command. Found '".concat(a.text,"'"));s=t.PARAMCOUNT[i.toUpperCase()];break;default:throw new SyntaxError("Unrecognized command type: ".concat(a.type))}for(var l=0;l<s;l++){switch(a.type){case v.COMMAND:throw new SyntaxError("Parameter must be a number. Found '".concat(a.text,"'"));case v.NUMBER:o[l]=parseFloat(a.text);break;case v.EOD:throw new SyntaxError("Unexpected end of string");default:throw new SyntaxError("Unrecognized parameter type. Found type '".concat(a.type,"'"))}a=n.getNextToken()}if(null!==this._handler){var u=this._handler,h=t.METHODNAME[i];"a"!==i&&"A"!==i||(o[3]=0!==o[3],o[4]=0!==o[4]),null!==u&&"function"==typeof u[h]&&u[h].apply(u,o)}switch(i){case"M":i="L";break;case"m":i="l";break;case"Z":case"z":i="BOP"}if(a===r)throw new SyntaxError("Parser stalled on '".concat(a.text,"'"));r=a}null!==this._handler&&"function"==typeof this._handler.endParse&&this._handler.endParse()}},{key:"setHandler",value:function(t){this._handler=t}}]),t}();d.PARAMCOUNT={A:7,C:6,H:1,L:2,M:2,Q:4,S:4,T:2,V:1,Z:0},d.METHODNAME={A:"arcAbs",a:"arcRel",C:"curvetoCubicAbs",c:"curvetoCubicRel",H:"linetoHorizontalAbs",h:"linetoHorizontalRel",L:"linetoAbs",l:"linetoRel",M:"movetoAbs",m:"movetoRel",Q:"curvetoQuadraticAbs",q:"curvetoQuadraticRel",S:"curvetoCubicSmoothAbs",s:"curvetoCubicSmoothRel",T:"curvetoQuadraticSmoothAbs",t:"curvetoQuadraticSmoothRel",V:"linetoVerticalAbs",v:"linetoVerticalRel",Z:"closePath",z:"closePath"};var m=2*Math.PI;function w(t,e,n,i,r,a,s){r=r*Math.PI/180;var o=Math.cos(r),l=Math.sin(r),u=t.subtract(e).multiply(.5),h=u.x*o+u.y*l,c=u.x*-l+u.y*o,f=h*h,p=c*c,v=f/((n=Math.abs(n))*n)+p/((i=Math.abs(i))*i);if(v>1){var x=Math.sqrt(v);n*=x,i*=x}var d=n*n,w=i*i,b=d*p,g=w*f,k=(d*w-b-g)/(b+g);Math.abs(k)<1e-6&&(k=0);var P=Math.sqrt(k);a===s&&(P=-P);var E=t.add(e).multiply(.5),M=P*n*c/i,I=P*-i*h/n,C=(h-M)/n,R=(h+M)/n,X=(c-I)/i,S=(c+I)/i,N=new y(1,0).angleBetween(new y(C,X)),A=new y(C,X).angleBetween(new y(-R,-S));return!1===s&&(A-=m),[M*o-I*l+E.x,M*l+I*o+E.y,n,i,N,N+A]}var b=function(){function t(e){n(this,t),this.shapeCreator=e,this.shapes=[],this.firstX=null,this.firstY=null,this.lastX=null,this.lastY=null,this.lastCommand=null}return r(t,[{key:"beginParse",value:function(){this.shapes=[],this.firstX=null,this.firstY=null,this.lastX=null,this.lastY=null,this.lastCommand=null}},{key:"addShape",value:function(t){this.shapes.push(t)}},{key:"arcAbs",value:function(t,e,n,i,r,a,o){if(0===t||0===e)this.addShape(this.shapeCreator.line(this.lastX,this.lastY,a,o));else{var l,u=w(new h(this.lastX,this.lastY),new h(a,o),t,e,n,i,r);this.addShape((l=this.shapeCreator).arc.apply(l,s(u)))}this.lastCommand="A",this.lastX=a,this.lastY=o}},{key:"arcRel",value:function(t,e,n,i,r,a,o){if(0===t||0===e)this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+a,this.lastY+o));else{var l,u=w(new h(this.lastX,this.lastY),new h(this.lastX+a,this.lastY+o),t,e,n,i,r);this.addShape((l=this.shapeCreator).arc.apply(l,s(u)))}this.lastCommand="a",this.lastX+=a,this.lastY+=o}},{key:"curvetoCubicAbs",value:function(t,e,n,i,r,a){this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,t,e,n,i,r,a)),this.lastX=r,this.lastY=a,this.lastCommand="C"}},{key:"curvetoCubicRel",value:function(t,e,n,i,r,a){this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+i,this.lastX+r,this.lastY+a)),this.lastX+=r,this.lastY+=a,this.lastCommand="c"}},{key:"linetoHorizontalAbs",value:function(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,t,this.lastY)),this.lastX=t,this.lastCommand="H"}},{key:"linetoHorizontalRel",value:function(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+t,this.lastY)),this.lastX+=t,this.lastCommand="h"}},{key:"linetoAbs",value:function(t,e){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,t,e)),this.lastX=t,this.lastY=e,this.lastCommand="L"}},{key:"linetoRel",value:function(t,e){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX+t,this.lastY+e)),this.lastX+=t,this.lastY+=e,this.lastCommand="l"}},{key:"movetoAbs",value:function(t,e){this.firstX=t,this.firstY=e,this.lastX=t,this.lastY=e,this.lastCommand="M"}},{key:"movetoRel",value:function(t,e){this.firstX+=t,this.firstY+=e,this.lastX+=t,this.lastY+=e,this.lastCommand="m"}},{key:"curvetoQuadraticAbs",value:function(t,e,n,i){this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,t,e,n,i)),this.lastX=n,this.lastY=i,this.lastCommand="Q"}},{key:"curvetoQuadraticRel",value:function(t,e,n,i){this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+i)),this.lastX+=n,this.lastY+=i,this.lastCommand="q"}},{key:"curvetoCubicSmoothAbs",value:function(t,e,n,i){var r,a;if(this.lastCommand.match(/^[SsCc]$/)){var s=this.shapes[this.shapes.length-1].args[2];r=2*this.lastX-s.x,a=2*this.lastY-s.y}else r=this.lastX,a=this.lastY;this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,r,a,t,e,n,i)),this.lastX=n,this.lastY=i,this.lastCommand="S"}},{key:"curvetoCubicSmoothRel",value:function(t,e,n,i){var r,a;if(this.lastCommand.match(/^[SsCc]$/)){var s=this.shapes[this.shapes.length-1].args[2];r=2*this.lastX-s.x,a=2*this.lastY-s.y}else r=this.lastX,a=this.lastY;this.addShape(this.shapeCreator.cubicBezier(this.lastX,this.lastY,r,a,this.lastX+t,this.lastY+e,this.lastX+n,this.lastY+i)),this.lastX+=n,this.lastY+=i,this.lastCommand="s"}},{key:"curvetoQuadraticSmoothAbs",value:function(t,e){var n,i;if(this.lastCommand.match(/^[QqTt]$/)){var r=this.shapes[this.shapes.length-1].args[1];n=2*this.lastX-r.x,i=2*this.lastY-r.y}else n=this.lastX,i=this.lastY;this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,n,i,t,e)),this.lastX=t,this.lastY=e,this.lastCommand="T"}},{key:"curvetoQuadraticSmoothRel",value:function(t,e){var n,i;if(this.lastCommand.match(/^[QqTt]$/)){var r=this.shapes[this.shapes.length-1].args[1];n=2*this.lastX-r.x,i=2*this.lastY-r.y}else n=this.lastX,i=this.lastY;this.addShape(this.shapeCreator.quadraticBezier(this.lastX,this.lastY,n,i,this.lastX+t,this.lastY+e)),this.lastX+=t,this.lastY+=e,this.lastCommand="t"}},{key:"linetoVerticalAbs",value:function(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX,t)),this.lastY=t,this.lastCommand="V"}},{key:"linetoVerticalRel",value:function(t){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.lastX,this.lastY+t)),this.lastY+=t,this.lastCommand="v"}},{key:"closePath",value:function(){this.addShape(this.shapeCreator.line(this.lastX,this.lastY,this.firstX,this.firstY)),this.lastX=this.firstX,this.lastY=this.firstY,this.lastCommand="z"}}]),t}(),g=.5*Math.PI,k=new d;function P(t,e){var n,i=[],r=u(t);try{for(r.s();!(n=r.n()).done;){var s=a(n.value,2),o=s[0],l=s[1],h=null;if("Point2D"===l)h=M(o,e);else if("Number"===l)h=E(o,e);else if("Array<Point2D>"===l||"Point2D[]"===l){for(var y=[];e.length>0;)y.push(M(o,e));y.length>0&&(h=y)}else{if("Optional<Number>"!==l&&"Number?"!==l)throw new TypeError("Unrecognized value type: ".concat(l));null===(h=E(o,e))&&(h=void 0)}if(null===h)throw new TypeError("Unable to extract value for ".concat(o));i.push(h)}}catch(t){r.e(t)}finally{r.f()}return i}function E(t,n){var i=null;if(n.length>0){var r=n[0],a=e(r);if("number"===a)return n.shift();if("object"===a){var s,o=u(t);try{for(o.s();!(s=o.n()).done;){var l=s.value;if(l in r&&"number"==typeof r[l]){i=r[l];break}}}catch(t){o.e(t)}finally{o.f()}}}return i}function M(t,n){var i=null;return n.length>0&&function(){var r=n[0],s=e(r);if("number"===s){if(n.length>1){var o=n.shift(),l=n.shift();i=new h(o,l)}}else if(Array.isArray(r)&&r.length>1){if(2!==r.length)throw new TypeError("Unhandled array of length ".concat(r.length));var y=a(n.shift(),2),c=y[0],f=y[1];i=new h(c,f)}else if("object"===s)if("x"in r&&"y"in r)i=new h(r.x,r.y),2===Object.keys(r).length&&n.shift();else{var p,v=u(t);try{for(v.s();!(p=v.n()).done;){var x=p.value;if(Array.isArray(x)){if(x.every(function(t){return t in r})){i=new h(r[x[0]],r[x[1]]);break}}else if(x in r){i=M([],[r[x]]);break}}}catch(t){v.e(t)}finally{v.f()}}}(),i}var I=function(){function t(e,i){n(this,t),this.name=e,this.args=i}return r(t,null,[{key:"arc",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radiusX","rx"],"Number"],[["radiusY","ry"],"Number"],[["startRadians"],"Number"],[["endRadians"],"Number"]],n);return new t(t.ARC,r)}},{key:"quadraticBezier",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["p1",["p1x","p1y"]],"Point2D"],[["p2",["p2x","p2y"]],"Point2D"],[["p3",["p3x","p3y"]],"Point2D"]],n);return new t(t.QUADRATIC_BEZIER,r)}},{key:"cubicBezier",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["p1",["p1x","p1y"]],"Point2D"],[["p2",["p2x","p2y"]],"Point2D"],[["p3",["p3x","p3y"]],"Point2D"],[["p4",["p4x","p4y"]],"Point2D"]],n);return new t(t.CUBIC_BEZIER,r)}},{key:"circle",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radius","r"],"Number"]],n);return new t(t.CIRCLE,r)}},{key:"ellipse",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["center",["centerX","centerY"],["cx","cy"]],"Point2D"],[["radiusX","rx"],"Number"],[["radiusY","ry"],"Number"]],n);return new t(t.ELLIPSE,r)}},{key:"line",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["p1",["p1x","p1y"],["x1","y1"]],"Point2D"],[["p2",["p2x","p2y"],["x2","y2"]],"Point2D"]],n);return new t(t.LINE,r)}},{key:"path",value:function(){return k.parseData(arguments.length<=0?void 0:arguments[0]),new t(t.PATH,C.shapes)}},{key:"polygon",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[[],"Array<Point2D>"]],1===n.length&&Array.isArray(n[0])?n[0]:n);return new t(t.POLYGON,r)}},{key:"polyline",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[[],"Array<Point2D>"]],1===n.length&&Array.isArray(n[0])?n[0]:n);return new t(t.POLYLINE,r)}},{key:"rectangle",value:function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=P([[["topLeft",["x","y"],["left","top"]],"Point2D"],[["size",["width","height"],["w","h"]],"Point2D"],[["radiusX","rx"],"Optional<Number>"],[["radiusY","ry"],"Optional<Number>"]],n),a=r[0],s=r[1];r[1]=new h(a.x+s.x,a.y+s.y);var o=new t(t.RECTANGLE,r),l=o.args.pop(),u=o.args.pop();if(l=void 0===l?0:l,0===(u=void 0===u?0:u)&&0===l)return o;var y=o.args[0],c=y.x,f=y.y,p=o.args[1],v=p.x,x=p.y,d=v-c,m=x-f;0===u&&(u=l),0===l&&(l=u),u>.5*d&&(u=.5*d),l>.5*m&&(l=.5*m);var w=c,b=f,k=c+u,E=f+l,M=v-u,I=x-l,C=v,R=x,X=[t.arc(k,E,u,l,2*g,3*g),t.line(k,b,M,b),t.arc(M,E,u,l,3*g,4*g),t.line(C,E,C,I),t.arc(M,I,u,l,0,g),t.line(M,R,k,R),t.arc(k,I,u,l,g,2*g),t.line(w,I,w,E)];return new t(t.PATH,X)}}]),t}();I.ARC="Arc",I.QUADRATIC_BEZIER="Bezier2",I.CUBIC_BEZIER="Bezier3",I.CIRCLE="Circle",I.ELLIPSE="Ellipse",I.LINE="Line",I.PATH="Path",I.POLYGON="Polygon",I.POLYLINE="Polyline",I.RECTANGLE="Rectangle";var C=new b(I);k.setHandler(C);var R=2*Math.PI,X=new y(1,0);function S(t){return null==t}function N(t,e,n,i,r,a){if(0===t.points.length)return t;var s=new L("No Intersection");if(a<r){var o=[a,r];r=o[0],a=o[1]}(r<0||a<0)&&(r+=R,a+=R);var l,h,c,f=u(t.points);try{for(f.s();!(l=f.n()).done;){var p=l.value,v=(h=X.angleBetween(y.fromPoints(e,p)),c=void 0,(c=h%R)<0?c+R:c);v<r&&(v+=R),r<=v&&v<=a&&s.appendPoint(p)}}catch(t){f.e(t)}finally{f.f()}return s.points.length>0&&(s.status="Intersection"),s}function A(t){var e=t.slice();return e.push(t[0]),e}var L=function(){function t(e){n(this,t),this.init(e)}return r(t,[{key:"init",value:function(t){this.status=t,this.points=[]}},{key:"appendPoint",value:function(t){this.points.push(t)}},{key:"appendPoints",value:function(t){this.points=this.points.concat(t)}}],[{key:"intersect",value:function(e,n){var i;if(S(e)||S(n))i=new t("No Intersection");else if("Path"===e.name)i=t.intersectPathShape(e,n);else if("Path"===n.name)i=t.intersectPathShape(n,e);else if("Arc"===e.name)i=t.intersectArcShape(e,n);else if("Arc"===n.name)i=t.intersectArcShape(n,e);else{var r,a;if(e.name<n.name?(r="intersect"+e.name+n.name,a=e.args.concat(n.args)):(r="intersect"+n.name+e.name,a=n.args.concat(e.args)),!(r in t))throw new TypeError("Intersection not available: "+r);i=t[r].apply(null,a)}return i}},{key:"intersectPathShape",value:function(e,n){var i,r=new t("No Intersection"),a=u(e.args);try{for(a.s();!(i=a.n()).done;){var s=i.value,o=t.intersect(s,n);r.appendPoints(o.points)}}catch(t){a.e(t)}finally{a.f()}return r.points.length>0&&(r.status="Intersection"),r}},{key:"intersectArcShape",value:function(e,n){var i=a(e.args,5),r=i[0],s=i[1],o=i[2],l=i[3],u=i[4],h=new I(I.ELLIPSE,[r,s,o]);return N(t.intersect(h,n),r,0,0,l,u)}},{key:"intersectBezier2Bezier2",value:function(e,n,i,r,a,s){var o,l,y=new t("No Intersection");o=n.multiply(-2);var c=e.add(o.add(i));o=e.multiply(-2),l=n.multiply(2);var f=o.add(l),v=new h(e.x,e.y);o=a.multiply(-2);var x=r.add(o.add(s));o=r.multiply(-2),l=a.multiply(2);var d=o.add(l),m=new h(r.x,r.y);o=c.x*f.y-f.x*c.y,l=x.x*f.y-f.x*x.y;var w,b=d.x*f.y-f.x*d.y,g=f.x*(v.y-m.y)+f.y*(-v.x+m.x),k=x.x*c.y-c.x*x.y,P=d.x*c.y-c.x*d.y,E=c.x*(v.y-m.y)+c.y*(-v.x+m.x),M=u(new p(-k*k,-2*k*P,o*l-P*P-2*k*E,o*b-2*P*E,o*g-E*E).getRoots());try{for(M.s();!(w=M.n()).done;){var I=w.value;if(0<=I&&I<=1){var C=new p(c.x,f.x,v.x-m.x-I*d.x-I*I*x.x);C.simplifyEquals();var R=C.getRoots(),X=new p(c.y,f.y,v.y-m.y-I*d.y-I*I*x.y);X.simplifyEquals();var S=X.getRoots();if(R.length>0&&S.length>0){var N,A=u(R);try{t:for(A.s();!(N=A.n()).done;){var L=N.value;if(0<=L&&L<=1)for(var Y=0;Y<S.length;Y++)if(Math.abs(L-S[Y])<1e-4){y.points.push(x.multiply(I*I).add(d.multiply(I).add(m)));break t}}}catch(t){A.e(t)}finally{A.f()}}}}}catch(t){M.e(t)}finally{M.f()}return y.points.length>0&&(y.status="Intersection"),y}},{key:"intersectBezier2Bezier3",value:function(e,n,i,r,a,s,o){var l,y,c,f,v=new t("No Intersection");l=n.multiply(-2);var x=e.add(l.add(i));l=e.multiply(-2),y=n.multiply(2);var d=l.add(y),m=new h(e.x,e.y);l=r.multiply(-1),y=a.multiply(3),c=s.multiply(-3),f=l.add(y.add(c.add(o)));var w=new h(f.x,f.y);l=r.multiply(3),y=a.multiply(-6),c=s.multiply(3),f=l.add(y.add(c));var b=new h(f.x,f.y);l=r.multiply(-3),y=a.multiply(3),c=l.add(y);var g,k=new h(c.x,c.y),P=new h(r.x,r.y),E=m.x*m.x,M=m.y*m.y,I=d.x*d.x,C=d.y*d.y,R=x.x*x.x,X=x.y*x.y,S=P.x*P.x,N=P.y*P.y,A=k.x*k.x,L=k.y*k.y,Y=b.x*b.x,z=b.y*b.y,B=w.x*w.x,D=w.y*w.y,T=u(new p(-2*x.x*x.y*w.x*w.y+R*D+X*B,-2*x.x*x.y*b.x*w.y-2*x.x*x.y*b.y*w.x+2*X*b.x*w.x+2*R*b.y*w.y,-2*x.x*k.x*x.y*w.y-2*x.x*x.y*k.y*w.x-2*x.x*x.y*b.x*b.y+2*k.x*X*w.x+X*Y+R*(2*k.y*w.y+z),2*m.x*x.x*x.y*w.y+2*m.y*x.x*x.y*w.x+d.x*d.y*x.x*w.y+d.x*d.y*x.y*w.x-2*P.x*x.x*x.y*w.y-2*x.x*P.y*x.y*w.x-2*x.x*k.x*x.y*b.y-2*x.x*x.y*k.y*b.x-2*m.x*X*w.x-2*m.y*R*w.y+2*P.x*X*w.x+2*k.x*X*b.x-C*x.x*w.x-I*x.y*w.y+R*(2*P.y*w.y+2*k.y*b.y),2*m.x*x.x*x.y*b.y+2*m.y*x.x*x.y*b.x+d.x*d.y*x.x*b.y+d.x*d.y*x.y*b.x-2*P.x*x.x*x.y*b.y-2*x.x*P.y*x.y*b.x-2*x.x*k.x*x.y*k.y-2*m.x*X*b.x-2*m.y*R*b.y+2*P.x*X*b.x-C*x.x*b.x-I*x.y*b.y+A*X+R*(2*P.y*b.y+L),2*m.x*x.x*x.y*k.y+2*m.y*x.x*k.x*x.y+d.x*d.y*x.x*k.y+d.x*d.y*k.x*x.y-2*P.x*x.x*x.y*k.y-2*x.x*P.y*k.x*x.y-2*m.x*k.x*X-2*m.y*R*k.y+2*P.x*k.x*X-C*x.x*k.x-I*x.y*k.y+2*R*P.y*k.y,-2*m.x*m.y*x.x*x.y-m.x*d.x*d.y*x.y-m.y*d.x*d.y*x.x+2*m.x*x.x*P.y*x.y+2*m.y*P.x*x.x*x.y+d.x*P.x*d.y*x.y+d.x*d.y*x.x*P.y-2*P.x*x.x*P.y*x.y-2*m.x*P.x*X+m.x*C*x.x+m.y*I*x.y-2*m.y*R*P.y-P.x*C*x.x-I*P.y*x.y+E*X+M*R+S*X+R*N).getRootsInInterval(0,1));try{for(T.s();!(g=T.n()).done;){var q=g.value,V=new p(x.x,d.x,m.x-P.x-q*k.x-q*q*b.x-q*q*q*w.x).getRoots(),O=new p(x.y,d.y,m.y-P.y-q*k.y-q*q*b.y-q*q*q*w.y).getRoots();if(V.length>0&&O.length>0){var _,U=u(V);try{t:for(U.s();!(_=U.n()).done;){var j=_.value;if(0<=j&&j<=1)for(var Q=0;Q<O.length;Q++)if(Math.abs(j-O[Q])<1e-4){v.points.push(w.multiply(q*q*q).add(b.multiply(q*q).add(k.multiply(q).add(P))));break t}}}catch(t){U.e(t)}finally{U.f()}}}}catch(t){T.e(t)}finally{T.f()}return v.points.length>0&&(v.status="Intersection"),v}},{key:"intersectBezier2Circle",value:function(e,n,i,r,a){return t.intersectBezier2Ellipse(e,n,i,r,a,a)}},{key:"intersectBezier2Ellipse",value:function(e,n,i,r,a,s){var o,l=new t("No Intersection");o=n.multiply(-2);var y=e.add(o.add(i));o=e.multiply(-2);var c,f=n.multiply(2),v=o.add(f),x=new h(e.x,e.y),d=a*a,m=s*s,w=u(new p(m*y.x*y.x+d*y.y*y.y,2*(m*y.x*v.x+d*y.y*v.y),m*(2*y.x*x.x+v.x*v.x)+d*(2*y.y*x.y+v.y*v.y)-2*(m*r.x*y.x+d*r.y*y.y),2*(m*v.x*(x.x-r.x)+d*v.y*(x.y-r.y)),m*(x.x*x.x+r.x*r.x)+d*(x.y*x.y+r.y*r.y)-2*(m*r.x*x.x+d*r.y*x.y)-d*m).getRoots());try{for(w.s();!(c=w.n()).done;){var b=c.value;0<=b&&b<=1&&l.points.push(y.multiply(b*b).add(v.multiply(b).add(x)))}}catch(t){w.e(t)}finally{w.f()}return l.points.length>0&&(l.status="Intersection"),l}},{key:"intersectBezier2Line",value:function(e,n,i,r,a){var s,o=r.min(a),l=r.max(a),c=new t("No Intersection");s=n.multiply(-2);var f=e.add(s.add(i));s=e.multiply(-2);var v,x=n.multiply(2),d=s.add(x),m=new h(e.x,e.y),w=new y(r.y-a.y,a.x-r.x),b=r.x*a.y-a.x*r.y,g=u(new p(w.dot(f),w.dot(d),w.dot(m)+b).getRoots());try{for(g.s();!(v=g.n()).done;){var k=v.value;if(0<=k&&k<=1){var P=e.lerp(n,k),E=n.lerp(i,k),M=P.lerp(E,k);r.x===a.x?o.y<=M.y&&M.y<=l.y&&(c.status="Intersection",c.appendPoint(M)):r.y===a.y?o.x<=M.x&&M.x<=l.x&&(c.status="Intersection",c.appendPoint(M)):o.x<=M.x&&M.x<=l.x&&o.y<=M.y&&M.y<=l.y&&(c.status="Intersection",c.appendPoint(M))}}}catch(t){g.e(t)}finally{g.f()}return c}},{key:"intersectBezier2Polygon",value:function(e,n,i,r){return t.intersectBezier2Polyline(e,n,i,A(r))}},{key:"intersectBezier2Polyline",value:function(e,n,i,r){for(var a=new t("No Intersection"),s=r.length,o=0;o<s-1;o++){var l=r[o],u=r[o+1],h=t.intersectBezier2Line(e,n,i,l,u);a.appendPoints(h.points)}return a.points.length>0&&(a.status="Intersection"),a}},{key:"intersectBezier2Rectangle",value:function(e,n,i,r,a){var s=r.min(a),o=r.max(a),l=new h(o.x,s.y),u=new h(s.x,o.y),y=t.intersectBezier2Line(e,n,i,s,l),c=t.intersectBezier2Line(e,n,i,l,o),f=t.intersectBezier2Line(e,n,i,o,u),p=t.intersectBezier2Line(e,n,i,u,s),v=new t("No Intersection");return v.appendPoints(y.points),v.appendPoints(c.points),v.appendPoints(f.points),v.appendPoints(p.points),v.points.length>0&&(v.status="Intersection"),v}},{key:"intersectBezier3Bezier3",value:function(e,n,i,r,a,s,o,l){var y,c,f,v,x=new t("No Intersection");y=e.multiply(-1),c=n.multiply(3),f=i.multiply(-3),v=y.add(c.add(f.add(r)));var d=new h(v.x,v.y);y=e.multiply(3),c=n.multiply(-6),f=i.multiply(3),v=y.add(c.add(f));var m=new h(v.x,v.y);y=e.multiply(-3),c=n.multiply(3),f=y.add(c);var w=new h(f.x,f.y),b=new h(e.x,e.y);y=a.multiply(-1),c=s.multiply(3),f=o.multiply(-3),v=y.add(c.add(f.add(l)));var g=new h(v.x,v.y);y=a.multiply(3),c=s.multiply(-6),f=o.multiply(3),v=y.add(c.add(f));var k=new h(v.x,v.y);y=a.multiply(-3),c=s.multiply(3),f=y.add(c);var P=new h(f.x,f.y),E=new h(a.x,a.y);y=d.x*m.y-m.x*d.y,c=d.x*w.y-w.x*d.y;var M=d.x*b.y-b.x*d.y+E.x*d.y-d.x*E.y,I=P.x*d.y-d.x*P.y,C=k.x*d.y-d.x*k.y,R=g.x*d.y-d.x*g.y;v=d.x*w.y-w.x*d.y;var X=d.x*b.y+m.x*w.y-w.x*m.y-b.x*d.y+E.x*d.y-d.x*E.y,S=P.x*d.y-d.x*P.y,N=k.x*d.y-d.x*k.y,A=g.x*d.y-d.x*g.y,L=m.x*b.y-b.x*m.y+E.x*m.y-m.x*E.y,Y=P.x*m.y-m.x*P.y,z=k.x*m.y-m.x*k.y,B=g.x*m.y-m.x*g.y,D=d.x*b.y-b.x*d.y+E.x*d.y-d.x*E.y,T=P.x*d.y-d.x*P.y,q=k.x*d.y-d.x*k.y,V=g.x*d.y-d.x*g.y,O=m.x*b.y-b.x*m.y+E.x*m.y-m.x*E.y,_=P.x*m.y-m.x*P.y,U=k.x*m.y-m.x*k.y,j=g.x*m.y-m.x*g.y,Q=w.x*b.y-b.x*w.y+E.x*w.y-w.x*E.y,G=P.x*w.y-w.x*P.y,F=k.x*w.y-w.x*k.y,H=g.x*w.y-w.x*g.y,$=new p(-R*A*V,-R*A*q-R*N*V-C*A*V,-R*A*T-R*N*q-C*A*q-R*S*V-C*N*V-I*A*V,-R*A*D-R*N*T-C*A*T-R*S*q-C*N*q-I*A*q-R*X*V-C*S*V-I*N*V-M*A*V+c*B*V+R*v*j-y*B*j+y*A*H,-R*N*D-C*A*D-R*S*T-C*N*T-I*A*T-R*X*q-C*S*q-I*N*q-M*A*q+c*B*q-C*X*V-I*S*V-M*N*V+c*z*V+R*v*U-y*B*U+C*v*j-y*z*j+y*A*F+y*N*H,-R*S*D-C*N*D-I*A*D-R*X*T-C*S*T-I*N*T-M*A*T+c*B*T-C*X*q-I*S*q-M*N*q+c*z*q-I*X*V-M*S*V+c*Y*V+R*v*_-y*B*_+C*v*U-y*z*U+I*v*j-y*Y*j+y*A*G+y*N*F+y*S*H,-R*X*D-C*S*D-I*N*D-M*A*D+c*B*D-C*X*T-I*S*T-M*N*T+c*z*T-I*X*q-M*S*q+c*Y*q-M*X*V+c*L*V+R*v*O-y*B*O+C*v*_-y*z*_+I*v*U-y*Y*U+M*v*j-y*L*j+y*A*Q+y*N*G+y*S*F-c*v*H+y*X*H,-C*X*D-I*S*D-M*N*D+c*z*D-I*X*T-M*S*T+c*Y*T-M*X*q+c*L*q+C*v*O-y*z*O+I*v*_-y*Y*_+M*v*U-y*L*U+y*N*Q+y*S*G-c*v*F+y*X*F,-I*X*D-M*S*D+c*Y*D-M*X*T+c*L*T+I*v*O-y*Y*O+M*v*_-y*L*_+y*S*Q-c*v*G+y*X*G,-M*X*D+c*L*D+M*v*O-y*L*O-c*v*Q+y*X*Q);$.simplifyEquals();var Z,K=u($.getRootsInInterval(0,1));try{for(K.s();!(Z=K.n()).done;){var J=Z.value,W=new p(d.x,m.x,w.x,b.x-E.x-J*P.x-J*J*k.x-J*J*J*g.x);W.simplifyEquals();var tt=W.getRoots(),et=new p(d.y,m.y,w.y,b.y-E.y-J*P.y-J*J*k.y-J*J*J*g.y);et.simplifyEquals();var nt=et.getRoots();if(tt.length>0&&nt.length>0){var it,rt=u(tt);try{t:for(rt.s();!(it=rt.n()).done;){var at=it.value;if(0<=at&&at<=1)for(var st=0;st<nt.length;st++)if(Math.abs(at-nt[st])<1e-4){x.points.push(g.multiply(J*J*J).add(k.multiply(J*J).add(P.multiply(J).add(E))));break t}}}catch(t){rt.e(t)}finally{rt.f()}}}}catch(t){K.e(t)}finally{K.f()}return x.points.length>0&&(x.status="Intersection"),x}},{key:"intersectBezier3Circle",value:function(e,n,i,r,a,s){return t.intersectBezier3Ellipse(e,n,i,r,a,s,s)}},{key:"intersectBezier3Ellipse",value:function(e,n,i,r,a,s,o){var l,y,c,f,v=new t("No Intersection");l=e.multiply(-1),y=n.multiply(3),c=i.multiply(-3),f=l.add(y.add(c.add(r)));var x=new h(f.x,f.y);l=e.multiply(3),y=n.multiply(-6),c=i.multiply(3),f=l.add(y.add(c));var d=new h(f.x,f.y);l=e.multiply(-3),y=n.multiply(3),c=l.add(y);var m,w=new h(c.x,c.y),b=new h(e.x,e.y),g=s*s,k=o*o,P=u(new p(x.x*x.x*k+x.y*x.y*g,2*(x.x*d.x*k+x.y*d.y*g),2*(x.x*w.x*k+x.y*w.y*g)+d.x*d.x*k+d.y*d.y*g,2*x.x*k*(b.x-a.x)+2*x.y*g*(b.y-a.y)+2*(d.x*w.x*k+d.y*w.y*g),2*d.x*k*(b.x-a.x)+2*d.y*g*(b.y-a.y)+w.x*w.x*k+w.y*w.y*g,2*w.x*k*(b.x-a.x)+2*w.y*g*(b.y-a.y),b.x*b.x*k-2*b.y*a.y*g-2*b.x*a.x*k+b.y*b.y*g+a.x*a.x*k+a.y*a.y*g-g*k).getRootsInInterval(0,1));try{for(P.s();!(m=P.n()).done;){var E=m.value;v.points.push(x.multiply(E*E*E).add(d.multiply(E*E).add(w.multiply(E).add(b))))}}catch(t){P.e(t)}finally{P.f()}return v.points.length>0&&(v.status="Intersection"),v}},{key:"intersectBezier3Line",value:function(e,n,i,r,a,s){var o,l,h,c,f=a.min(s),v=a.max(s),x=new t("No Intersection");o=e.multiply(-1),l=n.multiply(3),h=i.multiply(-3),c=o.add(l.add(h.add(r)));var d=new y(c.x,c.y);o=e.multiply(3),l=n.multiply(-6),h=i.multiply(3),c=o.add(l.add(h));var m=new y(c.x,c.y);o=e.multiply(-3),l=n.multiply(3),h=o.add(l);var w,b=new y(h.x,h.y),g=new y(e.x,e.y),k=new y(a.y-s.y,s.x-a.x),P=a.x*s.y-s.x*a.y,E=u(new p(k.dot(d),k.dot(m),k.dot(b),k.dot(g)+P).getRoots());try{for(E.s();!(w=E.n()).done;){var M=w.value;if(0<=M&&M<=1){var I=e.lerp(n,M),C=n.lerp(i,M),R=i.lerp(r,M),X=I.lerp(C,M),S=C.lerp(R,M),N=X.lerp(S,M);a.x===s.x?f.y<=N.y&&N.y<=v.y&&(x.status="Intersection",x.appendPoint(N)):a.y===s.y?f.x<=N.x&&N.x<=v.x&&(x.status="Intersection",x.appendPoint(N)):f.x<=N.x&&N.x<=v.x&&f.y<=N.y&&N.y<=v.y&&(x.status="Intersection",x.appendPoint(N))}}}catch(t){E.e(t)}finally{E.f()}return x}},{key:"intersectBezier3Polygon",value:function(e,n,i,r,a){return t.intersectBezier3Polyline(e,n,i,r,A(a))}},{key:"intersectBezier3Polyline",value:function(e,n,i,r,a){for(var s=new t("No Intersection"),o=a.length,l=0;l<o-1;l++){var u=a[l],h=a[l+1],y=t.intersectBezier3Line(e,n,i,r,u,h);s.appendPoints(y.points)}return s.points.length>0&&(s.status="Intersection"),s}},{key:"intersectBezier3Rectangle",value:function(e,n,i,r,a,s){var o=a.min(s),l=a.max(s),u=new h(l.x,o.y),y=new h(o.x,l.y),c=t.intersectBezier3Line(e,n,i,r,o,u),f=t.intersectBezier3Line(e,n,i,r,u,l),p=t.intersectBezier3Line(e,n,i,r,l,y),v=t.intersectBezier3Line(e,n,i,r,y,o),x=new t("No Intersection");return x.appendPoints(c.points),x.appendPoints(f.points),x.appendPoints(p.points),x.appendPoints(v.points),x.points.length>0&&(x.status="Intersection"),x}},{key:"intersectCircleCircle",value:function(e,n,i,r){var a,s=n+r,o=Math.abs(n-r),l=e.distanceFrom(i);if(l>s)a=new t("Outside");else if(l<o)a=new t("Inside");else{a=new t("Intersection");var u=(n*n-r*r+l*l)/(2*l),y=Math.sqrt(n*n-u*u),c=e.lerp(i,u/l),f=y/l;a.points.push(new h(c.x-f*(i.y-e.y),c.y+f*(i.x-e.x))),a.points.push(new h(c.x+f*(i.y-e.y),c.y-f*(i.x-e.x)))}return a}},{key:"intersectCircleEllipse",value:function(e,n,i,r,a){return t.intersectEllipseEllipse(e,n,n,i,r,a)}},{key:"intersectCircleLine",value:function(e,n,i,r){var a,s=(r.x-i.x)*(r.x-i.x)+(r.y-i.y)*(r.y-i.y),o=2*((r.x-i.x)*(i.x-e.x)+(r.y-i.y)*(i.y-e.y)),l=o*o-4*s*(e.x*e.x+e.y*e.y+i.x*i.x+i.y*i.y-2*(e.x*i.x+e.y*i.y)-n*n);if(l<0)a=new t("Outside");else if(0===l)a=new t("Tangent");else{var u=Math.sqrt(l),h=(-o+u)/(2*s),y=(-o-u)/(2*s);(h<0||h>1)&&(y<0||y>1)?a=new t(h<0&&y<0||h>1&&y>1?"Outside":"Inside"):(a=new t("Intersection"),0<=h&&h<=1&&a.points.push(i.lerp(r,h)),0<=y&&y<=1&&a.points.push(i.lerp(r,y)))}return a}},{key:"intersectCirclePolygon",value:function(e,n,i){return t.intersectCirclePolyline(e,n,A(i))}},{key:"intersectCirclePolyline",value:function(e,n,i){for(var r,a=new t("No Intersection"),s=i.length,o=0;o<s-1;o++){var l=i[o],u=i[o+1];r=t.intersectCircleLine(e,n,l,u),a.appendPoints(r.points)}return a.points.length>0?a.status="Intersection":a.status=r.status,a}},{key:"intersectCircleRectangle",value:function(e,n,i,r){var a=i.min(r),s=i.max(r),o=new h(s.x,a.y),l=new h(a.x,s.y),u=t.intersectCircleLine(e,n,a,o),y=t.intersectCircleLine(e,n,o,s),c=t.intersectCircleLine(e,n,s,l),f=t.intersectCircleLine(e,n,l,a),p=new t("No Intersection");return p.appendPoints(u.points),p.appendPoints(y.points),p.appendPoints(c.points),p.appendPoints(f.points),p.points.length>0?p.status="Intersection":p.status=u.status,p}},{key:"intersectEllipseEllipse",value:function(e,n,i,r,a,s){for(var o,l,u,y,c,f,v,x,d,m,w,b,g,k,P,E=[i*i,0,n*n,-2*i*i*e.x,-2*n*n*e.y,i*i*e.x*e.x+n*n*e.y*e.y-n*n*i*i],M=[s*s,0,a*a,-2*s*s*r.x,-2*a*a*r.y,s*s*r.x*r.x+a*a*r.y*r.y-a*a*s*s],I=(l=M,u=(o=E)[0]*l[1]-l[0]*o[1],y=o[0]*l[2]-l[0]*o[2],c=o[0]*l[3]-l[0]*o[3],f=o[0]*l[4]-l[0]*o[4],v=o[0]*l[5]-l[0]*o[5],x=o[1]*l[2]-l[1]*o[2],d=o[1]*l[4]-l[1]*o[4],m=o[1]*l[5]-l[1]*o[5],w=o[2]*l[3]-l[2]*o[3],b=o[3]*l[4]-l[3]*o[4],g=o[3]*l[5]-l[3]*o[5],new p(u*x-y*y,u*(P=d-w)+c*x-2*y*f,u*(k=m+b)+c*P-f*f-2*y*v,u*g+c*k-2*f*v,c*g-v*v)).getRoots(),C=.001*(E[0]*E[0]+2*E[1]*E[1]+E[2]*E[2]),R=.001*(M[0]*M[0]+2*M[1]*M[1]+M[2]*M[2]),X=new t("No Intersection"),S=0;S<I.length;S++)for(var N=new p(E[0],E[3]+I[S]*E[1],E[5]+I[S]*(E[4]+I[S]*E[2])).getRoots(),A=0;A<N.length;A++){var L=(E[0]*N[A]+E[1]*I[S]+E[3])*N[A]+(E[2]*I[S]+E[4])*I[S]+E[5];Math.abs(L)<C&&(L=(M[0]*N[A]+M[1]*I[S]+M[3])*N[A]+(M[2]*I[S]+M[4])*I[S]+M[5],Math.abs(L)<R&&X.appendPoint(new h(N[A],I[S])))}return X.points.length>0&&(X.status="Intersection"),X}},{key:"intersectEllipseLine",value:function(e,n,i,r,a){var s,o=new y(r.x,r.y),l=y.fromPoints(r,a),u=new y(e.x,e.y),h=o.subtract(u),c=new y(l.x/(n*n),l.y/(i*i)),f=new y(h.x/(n*n),h.y/(i*i)),p=l.dot(c),v=l.dot(f),x=v*v-p*(e=h.dot(f)-1);if(x<0)s=new t("Outside");else if(x>0){var d=Math.sqrt(x),m=(-v-d)/p,w=(-v+d)/p;(m<0||1<m)&&(w<0||1<w)?s=new t(m<0&&w<0||m>1&&w>1?"Outside":"Inside"):(s=new t("Intersection"),0<=m&&m<=1&&s.appendPoint(r.lerp(a,m)),0<=w&&w<=1&&s.appendPoint(r.lerp(a,w)))}else{var b=-v/p;0<=b&&b<=1?(s=new t("Intersection")).appendPoint(r.lerp(a,b)):s=new t("Outside")}return s}},{key:"intersectEllipsePolygon",value:function(e,n,i,r){return t.intersectEllipsePolyline(e,n,i,A(r))}},{key:"intersectEllipsePolyline",value:function(e,n,i,r){for(var a=new t("No Intersection"),s=r.length,o=0;o<s-1;o++){var l=r[o],u=r[o+1],h=t.intersectEllipseLine(e,n,i,l,u);a.appendPoints(h.points)}return a.points.length>0&&(a.status="Intersection"),a}},{key:"intersectEllipseRectangle",value:function(e,n,i,r,a){var s=r.min(a),o=r.max(a),l=new h(o.x,s.y),u=new h(s.x,o.y),y=t.intersectEllipseLine(e,n,i,s,l),c=t.intersectEllipseLine(e,n,i,l,o),f=t.intersectEllipseLine(e,n,i,o,u),p=t.intersectEllipseLine(e,n,i,u,s),v=new t("No Intersection");return v.appendPoints(y.points),v.appendPoints(c.points),v.appendPoints(f.points),v.appendPoints(p.points),v.points.length>0&&(v.status="Intersection"),v}},{key:"intersectLineLine",value:function(e,n,i,r){var a,s=(r.x-i.x)*(e.y-i.y)-(r.y-i.y)*(e.x-i.x),o=(n.x-e.x)*(e.y-i.y)-(n.y-e.y)*(e.x-i.x),l=(r.y-i.y)*(n.x-e.x)-(r.x-i.x)*(n.y-e.y);if(0!==l){var u=s/l,y=o/l;0<=u&&u<=1&&0<=y&&y<=1?(a=new t("Intersection")).points.push(new h(e.x+u*(n.x-e.x),e.y+u*(n.y-e.y))):a=new t("No Intersection")}else a=new t(0===s||0===o?"Coincident":"Parallel");return a}},{key:"intersectLinePolygon",value:function(e,n,i){return t.intersectLinePolyline(e,n,A(i))}},{key:"intersectLinePolyline",value:function(e,n,i){for(var r=new t("No Intersection"),a=i.length,s=0;s<a-1;s++){var o=i[s],l=i[s+1],u=t.intersectLineLine(e,n,o,l);r.appendPoints(u.points)}return r.points.length>0&&(r.status="Intersection"),r}},{key:"intersectLineRectangle",value:function(e,n,i,r){var a=i.min(r),s=i.max(r),o=new h(s.x,a.y),l=new h(a.x,s.y),u=t.intersectLineLine(a,o,e,n),y=t.intersectLineLine(o,s,e,n),c=t.intersectLineLine(s,l,e,n),f=t.intersectLineLine(l,a,e,n),p=new t("No Intersection");return p.appendPoints(u.points),p.appendPoints(y.points),p.appendPoints(c.points),p.appendPoints(f.points),p.points.length>0&&(p.status="Intersection"),p}},{key:"intersectPolygonPolygon",value:function(e,n){return t.intersectPolylinePolyline(A(e),A(n))}},{key:"intersectPolygonPolyline",value:function(e,n){return t.intersectPolylinePolyline(A(e),n)}},{key:"intersectPolygonRectangle",value:function(e,n,i){return t.intersectPolylineRectangle(A(e),n,i)}},{key:"intersectPolylinePolyline",value:function(e,n){for(var i=new t("No Intersection"),r=e.length,a=0;a<r-1;a++){var s=e[a],o=e[a+1],l=t.intersectLinePolyline(s,o,n);i.appendPoints(l.points)}return i.points.length>0&&(i.status="Intersection"),i}},{key:"intersectPolylineRectangle",value:function(e,n,i){var r=n.min(i),a=n.max(i),s=new h(a.x,r.y),o=new h(r.x,a.y),l=t.intersectLinePolyline(r,s,e),u=t.intersectLinePolyline(s,a,e),y=t.intersectLinePolyline(a,o,e),c=t.intersectLinePolyline(o,r,e),f=new t("No Intersection");return f.appendPoints(l.points),f.appendPoints(u.points),f.appendPoints(y.points),f.appendPoints(c.points),f.points.length>0&&(f.status="Intersection"),f}},{key:"intersectRectangleRectangle",value:function(e,n,i,r){var a=e.min(n),s=e.max(n),o=new h(s.x,a.y),l=new h(a.x,s.y),u=t.intersectLineRectangle(a,o,i,r),y=t.intersectLineRectangle(o,s,i,r),c=t.intersectLineRectangle(s,l,i,r),f=t.intersectLineRectangle(l,a,i,r),p=new t("No Intersection");return p.appendPoints(u.points),p.appendPoints(y.points),p.appendPoints(c.points),p.appendPoints(f.points),p.points.length>0&&(p.status="Intersection"),p}},{key:"intersectRayRay",value:function(e,n,i,r){var a,s=(r.x-i.x)*(e.y-i.y)-(r.y-i.y)*(e.x-i.x),o=(n.x-e.x)*(e.y-i.y)-(n.y-e.y)*(e.x-i.x),l=(r.y-i.y)*(n.x-e.x)-(r.x-i.x)*(n.y-e.y);if(0!==l){var u=s/l;(a=new t("Intersection")).points.push(new h(e.x+u*(n.x-e.x),e.y+u*(n.y-e.y)))}else a=new t(0===s||0===o?"Coincident":"Parallel");return a}}]),t}(),Y=function(){function t(){n(this,t)}return r(t,null,[{key:"arc",value:function(t,e,n,i,r,a){return I.arc.apply(I,arguments)}},{key:"quadraticBezier",value:function(t,e,n,i,r,a){return I.quadraticBezier.apply(I,arguments)}},{key:"cubicBezier",value:function(t,e,n,i,r,a,s,o){return I.cubicBezier.apply(I,arguments)}},{key:"circle",value:function(t,e,n){return I.circle.apply(I,arguments)}},{key:"ellipse",value:function(t,e,n,i){return I.ellipse.apply(I,arguments)}},{key:"line",value:function(t,e,n,i){return I.line.apply(I,arguments)}},{key:"path",value:function(t){return I.path.apply(I,arguments)}},{key:"polygon",value:function(t){return I.polygon.apply(I,arguments)}},{key:"polyline",value:function(t){return I.polyline.apply(I,arguments)}},{key:"rectangle",value:function(t,e,n,i){return I.rectangle.apply(I,arguments)}}]),t}(),z=function(){function t(){n(this,t)}return r(t,null,[{key:"arc",value:function(t,e,n,i,r){return I.arc.apply(I,arguments)}},{key:"quadraticBezier",value:function(t,e,n){return I.quadraticBezier.apply(I,arguments)}},{key:"cubicBezier",value:function(t,e,n,i){return I.cubicBezier.apply(I,arguments)}},{key:"circle",value:function(t,e){return I.circle.apply(I,arguments)}},{key:"ellipse",value:function(t,e,n){return I.ellipse.apply(I,arguments)}},{key:"line",value:function(t,e){return I.line.apply(I,arguments)}},{key:"path",value:function(t){return I.path.apply(I,arguments)}},{key:"polygon",value:function(t){return I.polygon.apply(I,arguments)}},{key:"polyline",value:function(t){return I.polyline.apply(I,arguments)}},{key:"rectangle",value:function(t,e){return I.rectangle.apply(I,arguments)}}]),t}(),B=function(){function t(){n(this,t)}return r(t,null,[{key:"circle",value:function(t){if(t instanceof SVGCircleElement==!1)throw new TypeError("Expected SVGCircleElement, but found ".concat(t));var e=new h(t.cx.baseVal.value,t.cy.baseVal.value),n=t.r.baseVal.value;return I.circle(e,n)}},{key:"ellipse",value:function(t){if(t instanceof SVGEllipseElement==!1)throw new TypeError("Expected SVGEllipseElement, but found ".concat(t));var e=new h(t.cx.baseVal.value,t.cy.baseVal.value),n=t.rx.baseVal.value,i=t.ry.baseVal.value;return I.ellipse(e,n,i)}},{key:"line",value:function(t){if(t instanceof SVGLineElement==!1)throw new TypeError("Expected SVGLineElement, but found ".concat(t));var e=new h(t.x1.baseVal.value,t.y1.baseVal.value),n=new h(t.x2.baseVal.value,t.y2.baseVal.value);return I.line(e,n)}},{key:"path",value:function(t){if(t instanceof SVGPathElement==!1)throw new TypeError("Expected SVGPathElement, but found ".concat(t));var e=t.getAttributeNS(null,"d");return I.path(e)}},{key:"polygon",value:function(t){if(t instanceof SVGPolygonElement==!1)throw new TypeError("Expected SVGPolygonElement, but found ".concat(t));for(var e=[],n=0;n<t.points.numberOfItems;n++){var i=t.points.getItem(n);e.push(new h(i.x,i.y))}return I.polygon(e)}},{key:"polyline",value:function(t){if(t instanceof SVGPolylineElement==!1)throw new TypeError("Expected SVGPolylineElement, but found ".concat(t));for(var e=[],n=0;n<t.points.numberOfItems;n++){var i=t.points.getItem(n);e.push(new h(i.x,i.y))}return I.polyline(e)}},{key:"rect",value:function(t){if(t instanceof SVGRectElement==!1)throw new TypeError("Expected SVGRectElement, but found ".concat(t));return I.rectangle(t.x.baseVal.value,t.y.baseVal.value,t.width.baseVal.value,t.height.baseVal.value,t.rx.baseVal.value,t.ry.baseVal.value)}},{key:"element",value:function(e){if(e instanceof SVGElement==!1)throw new TypeError("Expected SVGElement, but found ".concat(e));var n=e.tagName;switch(n){case"circle":return t.circle(e);case"ellipse":return t.ellipse(e);case"line":return t.line(e);case"path":return t.path(e);case"polygon":return t.polygon(e);case"polyline":return t.polyline(e);case"rect":return t.rect(e);default:throw new TypeError("Unrecognized element type: '".concat(n,"'"))}}}]),t}(),D={pointInCircle:function(t,e,n){return y.fromPoints(e,t).length()<=n},pointInEllipse:function(t,e,n,i){var r=t.subtract(e);return r.x*r.x/(n*n)+r.y*r.y/(i*i)<=1},pointInPolyline:function(t,e){for(var n,i=e.length,r=0,a=e[0],s=1;s<=i;s++){var o=e[s%i],l=Math.min(a.y,o.y),u=Math.max(a.y,o.y),h=Math.max(a.x,o.x);a.y!==o.y&&l<t.y&&t.y<=u&&t.x<=h&&(n=(t.y-a.y)*(o.x-a.x)/(o.y-a.y)+a.x,(a.x===o.x||t.x<=n)&&r++),a=o}return r%2==1}};D.pointInPolygon=D.pointInPolyline,D.pointInRectangle=function(t,e,n){return e.x<=t.x&&t.x<n.x&&e.y<=t.y&&t.y<n.y},t.AffineShapes=z,t.Intersection=L,t.IntersectionArgs=I,t.IntersectionQuery=D,t.Matrix2D=c,t.Point2D=h,t.ShapeInfo=I,t.Shapes=Y,t.SvgShapes=B,t.Vector2D=y,Object.defineProperty(t,"__esModule",{value:!0})});
  //# sourceMappingURL=index-umd.min.js.map
  