/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/earcut","./coordsUtils","./meshUtils/deduplicate"],(function(e,n,t,o){"use strict";function l(t){const l=i(t.rings,t.hasZ,e.CounterClockwiseMode.CCW_IS_HOLE),s=[];let c=0,a=0;for(const e of l.polygons){const t=e.count,o=e.index,r=new Float64Array(l.position.buffer,3*o*l.position.BYTES_PER_ELEMENT,3*t),i=e.holeIndices.map((e=>e-o)),u=new Uint32Array(n.earcut(r,i,3));s.push({position:r,faces:u}),c+=r.length,a+=u.length}const u=r(s,c,a),h=o.deduplicate(u.position.buffer,6,{originalIndices:u.faces});return u.position=new Float64Array(h.buffer),u.faces=h.indices,u}function r(e,n,t){if(1===e.length)return e[0];const o=new Float64Array(n),l=new Uint32Array(t);let r=0,i=0,s=0;for(const c of e){for(let e=0;e<c.position.length;e++)o[r++]=c.position[e];for(let e=0;e<c.faces.length;e++)l[i++]=c.faces[e]+s;s=r/3}return{position:o,faces:l}}function i(n,t,o){const l=n.length,r=new Array(l),i=new Array(l),a=new Array(l);let u=0,h=0,f=0,g=0;for(let e=0;e<l;++e)g+=n[e].length;const d=new Float64Array(3*g);let p=0;for(let C=l-1;C>=0;C--){const g=n[C],w=o===e.CounterClockwiseMode.CCW_IS_HOLE&&c(g);if(w&&1!==l)r[u++]=g;else{let e=g.length;for(let t=0;t<u;++t)e+=r[t].length;const n={index:p,pathLengths:new Array(u+1),count:e,holeIndices:new Array(u)};n.pathLengths[0]=g.length,g.length>0&&(a[f++]={index:p,count:g.length}),p=w?s(g,g.length-1,-1,d,p,g.length,t):s(g,0,1,d,p,g.length,t);for(let o=0;o<u;++o){const e=r[o];n.holeIndices[o]=p,n.pathLengths[o+1]=e.length,e.length>0&&(a[f++]={index:p,count:e.length}),p=s(e,0,1,d,p,e.length,t)}u=0,n.count>0&&(i[h++]=n)}}for(let e=0;e<u;++e){const n=r[e];n.length>0&&(a[f++]={index:p,count:n.length}),p=s(n,0,1,d,p,n.length,t)}return h<l&&(i.length=h),f<l&&(a.length=f),{position:d,polygons:i,outlines:a}}function s(e,n,t,o,l,r,i){l*=3;for(let s=0;s<r;++s){const r=e[n];o[l++]=r[0],o[l++]=r[1],o[l++]=i?r[2]:0,n+=t}return l/3}function c(e){return!t.isClockwise(e,!1,!1)}var a;e.CounterClockwiseMode=void 0,(a=e.CounterClockwiseMode||(e.CounterClockwiseMode={}))[a.NONE=0]="NONE",a[a.CCW_IS_HOLE=1]="CCW_IS_HOLE",e.pathsToTriangulationInfo=i,e.triangulate=l,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
