UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 2.3 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{e as n}from"../../chunks/earcut.js";import{isClockwise as t}from"./coordsUtils.js";import{doubleSubArray as e,doubleArrayFrom as o,newDoubleArray as r}from"./DoubleArray.js";import{compactMeshIndices as s}from"./Indices.js";import{leastSignificantAxis as i}from"./polygonUtils.js";import{deduplicate as l}from"./meshUtils/deduplicate.js";function c(t){const r=f(t.rings,t.hasZ,1,t.spatialReference),i=new Array;let c=0,a=0;for(const o of r.polygons){const t=o.count,l=o.index,h=e(r.position,3*l,3*t),f=o.holeIndices.map(n=>n-l),g=s(n(h,f,3));i.push({position:h,faces:g}),c+=h.length,a+=g.length}const g=h(i,c,a),u=Array.isArray(g.position)?l(g.position,3,{originalIndices:g.faces}):l(g.position.buffer,6,{originalIndices:g.faces});return g.position=o(new Float64Array(u.buffer)),g.faces=u.indices,g}function h(n,t,e){if(1===n.length)return n[0];const o=r(t),i=new Array(e);let l=0,c=0,h=0;for(const r of n){for(let n=0;n<r.position.length;n++)o[l++]=r.position[n];for(const n of r.faces)i[c++]=n+h;h=l/3}return{position:o,faces:s(i)}}function f(n,t,e,o){const s=n.length,i=new Array(s),l=new Array(s),c=new Array(s),h=n.reduce((n,t)=>n+t.length,0);let f=0,u=0,p=0;const d=r(3*h);let m=0;for(let r=s-1;r>=0;r--){const h=n[r],y=1===e&&g(h,t,o);if(y&&1!==s)i[f++]=h;else{let n=h.length;for(let t=0;t<f;++t)n+=i[t].length;const e={index:m,pathLengths:new Array(f+1),count:n,holeIndices:new Array(f)};e.pathLengths[0]=h.length,h.length>0&&(c[p++]={index:m,count:h.length}),m=y?a(h,h.length-1,-1,d,m,h.length,t):a(h,0,1,d,m,h.length,t);for(let o=0;o<f;++o){const n=i[o];e.holeIndices[o]=m,e.pathLengths[o+1]=n.length,n.length>0&&(c[p++]={index:m,count:n.length}),m=a(n,0,1,d,m,n.length,t)}f=0,e.count>0&&(l[u++]=e)}}for(let r=0;r<f;++r){const n=i[r];n.length>0&&(c[p++]={index:m,count:n.length}),m=a(n,0,1,d,m,n.length,t)}return l.length=u,c.length=p,{position:d,polygons:l,outlines:c}}function a(n,t,e,o,r,s,i){r*=3;for(let l=0;l<s;++l){const s=n[t];o[r++]=s[0],o[r++]=s[1],o[r++]=i&&s[2]?s[2]:0,t+=e}return r/3}function g(n,e,o){if(!e)return!t(n);const r=n.length-1;switch(i(n,r,o)){case 0:return!t(n,1,2);case 1:return!t(n,0,2);case 2:return!t(n,0,1)}}export{g as isCounterClockwise,f as ringsToTriangulationInfo,c as triangulate};