!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).earcut=e()}}(function(){return function e(n,t,r){function x(u,f){if(!t[u]){if(!n[u]){var o="function"==typeof require&&require;if(!f&&o)return o(u,!0);if(i)return i(u,!0);var v=new Error("Cannot find module '"+u+"'");throw v.code="MODULE_NOT_FOUND",v}var y=t[u]={exports:{}};n[u][0].call(y.exports,function(e){var t=n[u][1][e];return x(t||e)},y,y.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u80*t){y=s=e[0],a=c=e[1];for(var w=t;ws&&(s=d),Z>c&&(c=Z);g=0!==(g=Math.max(s-y,c-a))?1/g:0}return u(o,v,t,y,a,g),v}function x(e,n,t,r,x){var i,u;if(x===m(e,n,t,r)>0)for(i=n;i=n;i-=r)u=b(i,e[i],e[i+1],u);return u&&d(u,u.next)&&(z(u),u=u.next),u}function i(e,n){if(!e)return e;n||(n=e);var t,r=e;do{if(t=!1,r.steiner||!d(r,r.next)&&0!==c(r.prev,r,r.next))r=r.next;else{if(z(r),(r=n=r.prev)===r.next)break;t=!0}}while(t||r!==n);return n}function u(e,n,t,r,x,p,l){if(e){!l&&p&&function(e,n,t,r){var x=e;do{null===x.z&&(x.z=a(x.x,x.y,n,t,r)),x.prevZ=x.prev,x.nextZ=x.next,x=x.next}while(x!==e);x.prevZ.nextZ=null,x.prevZ=null,function(e){var n,t,r,x,i,u,f,o,v=1;do{for(t=e,e=null,i=null,u=0;t;){for(u++,r=t,f=0,n=0;n0||o>0&&r;)0!==f&&(0===o||!r||t.z<=r.z)?(x=t,t=t.nextZ,f--):(x=r,r=r.nextZ,o--),i?i.nextZ=x:e=x,x.prevZ=i,i=x;t=r}i.nextZ=null,v*=2}while(u>1)}(x)}(e,r,x,p);for(var h,s,c=e;e.prev!==e.next;)if(h=e.prev,s=e.next,p?o(e,r,x,p):f(e))n.push(h.i/t),n.push(e.i/t),n.push(s.i/t),z(e),e=s.next,c=s.next;else if((e=s)===c){l?1===l?u(e=v(e,n,t),n,t,r,x,p,2):2===l&&y(e,n,t,r,x,p):u(i(e),n,t,r,x,p,1);break}}}function f(e){var n=e.prev,t=e,r=e.next;if(c(n,t,r)>=0)return!1;for(var x=e.next.next;x!==e.prev;){if(s(n.x,n.y,t.x,t.y,r.x,r.y,x.x,x.y)&&c(x.prev,x,x.next)>=0)return!1;x=x.next}return!0}function o(e,n,t,r){var x=e.prev,i=e,u=e.next;if(c(x,i,u)>=0)return!1;for(var f=x.xi.x?x.x>u.x?x.x:u.x:i.x>u.x?i.x:u.x,y=x.y>i.y?x.y>u.y?x.y:u.y:i.y>u.y?i.y:u.y,p=a(f,o,n,t,r),l=a(v,y,n,t,r),h=e.prevZ,d=e.nextZ;h&&h.z>=p&&d&&d.z<=l;){if(h!==e.prev&&h!==e.next&&s(x.x,x.y,i.x,i.y,u.x,u.y,h.x,h.y)&&c(h.prev,h,h.next)>=0)return!1;if(h=h.prevZ,d!==e.prev&&d!==e.next&&s(x.x,x.y,i.x,i.y,u.x,u.y,d.x,d.y)&&c(d.prev,d,d.next)>=0)return!1;d=d.nextZ}for(;h&&h.z>=p;){if(h!==e.prev&&h!==e.next&&s(x.x,x.y,i.x,i.y,u.x,u.y,h.x,h.y)&&c(h.prev,h,h.next)>=0)return!1;h=h.prevZ}for(;d&&d.z<=l;){if(d!==e.prev&&d!==e.next&&s(x.x,x.y,i.x,i.y,u.x,u.y,d.x,d.y)&&c(d.prev,d,d.next)>=0)return!1;d=d.nextZ}return!0}function v(e,n,t){var r=e;do{var x=r.prev,i=r.next.next;!d(x,i)&&Z(x,r,r.next,i)&&g(x,i)&&g(i,x)&&(n.push(x.i/t),n.push(r.i/t),n.push(i.i/t),z(r),z(r.next),r=e=i),r=r.next}while(r!==e);return r}function y(e,n,t,r,x,f){var o=e;do{for(var v=o.next.next;v!==o.prev;){if(o.i!==v.i&&(p=o,l=v,p.next.i!==l.i&&p.prev.i!==l.i&&!function(e,n){var t=e;do{if(t.i!==e.i&&t.next.i!==e.i&&t.i!==n.i&&t.next.i!==n.i&&Z(t,t.next,e,n))return!0;t=t.next}while(t!==e);return!1}(p,l)&&g(p,l)&&g(l,p)&&function(e,n){var t=e,r=!1,x=(e.x+n.x)/2,i=(e.y+n.y)/2;do{t.y>i!=t.next.y>i&&t.next.y!==t.y&&x<(t.next.x-t.x)*(i-t.y)/(t.next.y-t.y)+t.x&&(r=!r),t=t.next}while(t!==e);return r}(p,l))){var y=w(o,v);return o=i(o,o.next),y=i(y,y.next),u(o,n,t,r,x,f),void u(y,n,t,r,x,f)}v=v.next}o=o.next}while(o!==e);var p,l}function p(e,n){return e.x-n.x}function l(e,n){if(n=function(e,n){var t,r=n,x=e.x,i=e.y,u=-1/0;do{if(i<=r.y&&i>=r.next.y&&r.next.y!==r.y){var f=r.x+(i-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(f<=x&&f>u){if(u=f,f===x){if(i===r.y)return r;if(i===r.next.y)return r.next}t=r.x=r.x&&r.x>=y&&x!==r.x&&s(it.x)&&g(r,e)&&(t=r,l=o),r=r.next;return t}(e,n)){var t=w(n,e);i(t,t.next)}}function a(e,n,t,r,x){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-t)*x)|e<<8))|e<<4))|e<<2))|e<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=32767*(n-r)*x)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function h(e){var n=e,t=e;do{n.x=0&&(e-u)*(r-f)-(t-u)*(n-f)>=0&&(t-u)*(i-f)-(x-u)*(r-f)>=0}function c(e,n,t){return(n.y-e.y)*(t.x-n.x)-(n.x-e.x)*(t.y-n.y)}function d(e,n){return e.x===n.x&&e.y===n.y}function Z(e,n,t,r){return!!(d(e,n)&&d(t,r)||d(e,r)&&d(t,n))||c(e,n,t)>0!=c(e,n,r)>0&&c(t,r,e)>0!=c(t,r,n)>0}function g(e,n){return c(e.prev,e,e.next)<0?c(e,n,e.next)>=0&&c(e,e.prev,n)>=0:c(e,n,e.prev)<0||c(e,e.next,n)<0}function w(e,n){var t=new M(e.i,e.x,e.y),r=new M(n.i,n.x,n.y),x=e.next,i=n.prev;return e.next=n,n.prev=e,t.next=x,x.prev=t,r.next=t,t.prev=r,i.next=r,r.prev=i,r}function b(e,n,t,r){var x=new M(e,n,t);return r?(x.next=r.next,x.prev=r,r.next.prev=x,r.next=x):(x.prev=x,x.next=x),x}function z(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function M(e,n,t){this.i=e,this.x=n,this.y=t,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}r.deviation=function(e,n,t,r){var x=n&&n.length,i=x?n[0]*t:e.length,u=Math.abs(m(e,0,i,t));if(x)for(var f=0,o=n.length;f0&&(r+=e[x-1].length,t.holes.push(r))}return t}},{}]},{},[1])(1)});