// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/core/libs/earcut/earcut",[],function(){function y(a,b,c){c=c||2;w=a.length/c+(b?2*b.length:0);z=!1;var d=b&&b.length,f=d?b[0]*c:a.length,k=I(a,0,f,c,!0),l=[];if(!k)return l;var m,g,t,h;if(d)a:{var e=c,d=[],p,n,u;h=0;for(p=b.length;h<p;h++)n=b[h]*e,u=h<p-1?b[h+1]*e:a.length,n=I(a,n,u,e,!1),n===n.next&&(n.steiner=!0),d.push(M(n));d.sort(N);for(h=0;h<d.length;h++){if(!k){k=null;break a}b=d[h];e=k;if(e=O(b,e))b=J(e,b),A(b,b.next);k=A(k,k.next)}}if(z)return l;if(a.length>
80*c){m=t=a[0];g=d=a[1];for(e=c;e<f;e+=c)h=a[e],b=a[e+1],h<m&&(m=h),b<g&&(g=b),h>t&&(t=h),b>d&&(d=b);t=Math.max(t-m,d-g)}B(k,l,c,m,g,t);return l}function I(a,b,c,d,f){var k;if(f===0<C(a,b,c,d))for(f=b;f<c;f+=d)k=K(f,a[f],a[f+1],k);else for(f=c-d;f>=b;f-=d)k=K(f,a[f],a[f+1],k);k&&x(k,k.next)&&(D(k),k=k.next);return k}function A(a,b){if(!a)return a;b||(b=a);var c=a,d,f=0,k=w*w/2;do{d=!1;if(c.steiner||!x(c,c.next)&&0!==u(c.prev,c,c.next))c=c.next;else{D(c);c=b=c.prev;if(c===c.next)return null;d=!0}if(f++>
k)return z=!0,null}while(d||c!==b);return b}function B(a,b,c,d,f,k,l){if(a){if(!l&&k){var m=a,g=m;do null===g.z&&(g.z=G(g.x,g.y,d,f,k)),g.prevZ=g.prev,g=g.nextZ=g.next;while(g!==m);g.prevZ.nextZ=null;g.prevZ=null;var m=g,t,h,e,p,n,v,r=1;do{g=m;e=m=null;for(p=0;g;){p++;h=g;for(t=n=0;t<r&&(n++,h=h.nextZ,h);t++);for(v=r;0<n||0<v&&h;)0===n?(t=h,h=h.nextZ,v--):0!==v&&h?g.z<=h.z?(t=g,g=g.nextZ,n--):(t=h,h=h.nextZ,v--):(t=g,g=g.nextZ,n--),e?e.nextZ=t:m=t,t.prevZ=e,e=t;g=h}e.nextZ=null;r*=2}while(1<p)}for(m=
a;a.prev!==a.next;){g=a.prev;h=a.next;if(k)a:{e=a;v=d;var q=f,w=k;p=e.prev;n=e;r=e.next;if(0<=u(p,n,r))e=!1;else{var y=p.x>n.x?p.x>r.x?p.x:r.x:n.x>r.x?n.x:r.x,C=p.y>n.y?p.y>r.y?p.y:r.y:n.y>r.y?n.y:r.y;t=G(p.x<n.x?p.x<r.x?p.x:r.x:n.x<r.x?n.x:r.x,p.y<n.y?p.y<r.y?p.y:r.y:n.y<r.y?n.y:r.y,v,q,w);v=G(y,C,v,q,w);for(q=e.nextZ;q&&q.z<=v;){if(q!==e.prev&&q!==e.next&&F(p.x,p.y,n.x,n.y,r.x,r.y,q.x,q.y)&&0<=u(q.prev,q,q.next)){e=!1;break a}q=q.nextZ}for(q=e.prevZ;q&&q.z>=t;){if(q!==e.prev&&q!==e.next&&F(p.x,
p.y,n.x,n.y,r.x,r.y,q.x,q.y)&&0<=u(q.prev,q,q.next)){e=!1;break a}q=q.prevZ}e=!0}}else e=P(a);if(e)b.push(g.i/c),b.push(a.i/c),b.push(h.i/c),D(a),m=a=h.next;else{if(z)break;a=h;if(a===m){if(!l)B(A(a),b,c,d,f,k,1);else if(1===l){l=b;m=c;g=a;do h=g.prev,e=g.next.next,!x(h,e)&&L(h,g,g.next,e)&&E(h,e)&&E(e,h)&&(l.push(h.i/m),l.push(g.i/m),l.push(e.i/m),D(g),D(g.next),g=a=e),g=g.next;while(g!==a);a=g;B(a,b,c,d,f,k,2)}else if(2===l)a:{l=a;do{for(m=l.next.next;m!==l.prev;){if(g=l.i!==m.i){g=l;h=m;e=void 0;
if(e=g.next.i!==h.i&&g.prev.i!==h.i){e=void 0;b:{e=g;do{if(e.i!==g.i&&e.next.i!==g.i&&e.i!==h.i&&e.next.i!==h.i&&L(e,e.next,g,h)){e=!0;break b}e=e.next}while(e!==g);e=!1}e=!e}p=void 0;if(p=e&&E(g,h)&&E(h,g)){e=g;p=!1;n=(g.x+h.x)/2;h=(g.y+h.y)/2;do e.y>h!==e.next.y>h&&n<(e.next.x-e.x)*(h-e.y)/(e.next.y-e.y)+e.x&&(p=!p),e=e.next;while(e!==g)}g=p}if(g){a=J(l,m);l=A(l,l.next);a=A(a,a.next);B(l,b,c,d,f,k);B(a,b,c,d,f,k);break a}m=m.next}l=l.next}while(l!==a)}break}}}}}function P(a){var b=a.prev,c=a.next;
if(0<=u(b,a,c))return!1;for(var d=a.next.next,f=0;d!==a.prev;){if(F(b.x,b.y,a.x,a.y,c.x,c.y,d.x,d.y)&&0<=u(d.prev,d,d.next))return!1;d=d.next;if(f++>w)return z=!0,!1}return!0}function N(a,b){return a.x-b.x}function O(a,b){var c=b,d=a.x,f=a.y,k=-Infinity,l;do{if(!c)return null;if(f<=c.y&&f>=c.next.y){var m=c.x+(f-c.y)*(c.next.x-c.x)/(c.next.y-c.y);if(m<=d&&m>k){k=m;if(m===d){if(f===c.y)return c;if(f===c.next.y)return c.next}l=c.x<c.next.x?c:c.next}}c=c.next}while(c!==b);if(!l)return null;if(d===k)return l.prev;
for(var m=l,g=l.x,t=l.y,h=Infinity,e,c=l.next;c!==m;)d>=c.x&&c.x>=g&&F(f<t?d:k,f,g,t,f<t?k:d,f,c.x,c.y)&&(e=Math.abs(f-c.y)/(d-c.x),(e<h||e===h&&c.x>l.x)&&E(c,a)&&(l=c,h=e)),c=c.next;return l}function G(a,b,c,d,f){a=32767*(a-c)/f;b=32767*(b-d)/f;a=(a|a<<8)&16711935;a=(a|a<<4)&252645135;a=(a|a<<2)&858993459;b=(b|b<<8)&16711935;b=(b|b<<4)&252645135;b=(b|b<<2)&858993459;return(a|a<<1)&1431655765|((b|b<<1)&1431655765)<<1}function M(a){var b=a,c=a;do b.x<c.x&&(c=b),b=b.next;while(b!==a);return c}function F(a,
b,c,d,f,k,l,m){return 0<=(f-l)*(b-m)-(a-l)*(k-m)&&0<=(a-l)*(d-m)-(c-l)*(b-m)&&0<=(c-l)*(k-m)-(f-l)*(d-m)}function u(a,b,c){return(b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y)}function x(a,b){return a.x===b.x&&a.y===b.y}function L(a,b,c,d){return x(a,b)&&x(c,d)||x(a,d)&&x(c,b)?!0:0<u(a,b,c)!==0<u(a,b,d)&&0<u(c,d,a)!==0<u(c,d,b)}function E(a,b){return 0>u(a.prev,a,a.next)?0<=u(a,b,a.next)&&0<=u(a,a.prev,b):0>u(a,b,a.prev)||0>u(a,a.next,b)}function J(a,b){var c=new H(a.i,a.x,a.y),d=new H(b.i,b.x,b.y),f=a.next,
k=b.prev;a.next=b;b.prev=a;c.next=f;f.prev=c;d.next=c;c.prev=d;k.next=d;d.prev=k;return d}function K(a,b,c,d){a=new H(a,b,c);d?(a.next=d.next,a.prev=d,d.next.prev=a,d.next=a):(a.prev=a,a.next=a);return a}function D(a){a.next.prev=a.prev;a.prev.next=a.next;a.prevZ&&(a.prevZ.nextZ=a.nextZ);a.nextZ&&(a.nextZ.prevZ=a.prevZ)}function H(a,b,c){this.i=a;this.x=b;this.y=c;this.nextZ=this.prevZ=this.z=this.next=this.prev=null;this.steiner=!1}function C(a,b,c,d){for(var f=0,k=c-d;b<c;b+=d)f+=(a[k]-a[b])*(a[b+
1]+a[k+1]),k=b;return f}var w,z;y.deviation=function(a,b,c,d){var f=b&&b.length,k=Math.abs(C(a,0,f?b[0]*c:a.length,c));if(f)for(var f=0,l=b.length;f<l;f++)k-=Math.abs(C(a,b[f]*c,f<l-1?b[f+1]*c:a.length,c));for(f=b=0;f<d.length;f+=3){var l=d[f]*c,m=d[f+1]*c,g=d[f+2]*c;b+=Math.abs((a[l]-a[g])*(a[m+1]-a[l+1])-(a[l]-a[m])*(a[g+1]-a[l+1]))}return 0===k&&0===b?0:Math.abs((b-k)/k)};y.flatten=function(a){for(var b=a[0][0].length,c={vertices:[],holes:[],dimensions:b},d=0,f=0;f<a.length;f++){for(var k=0;k<
a[f].length;k++)for(var l=0;l<b;l++)c.vertices.push(a[f][k][l]);0<f&&(d+=a[f-1].length,c.holes.push(d))}return c};return y});