@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.15 kB
JavaScript
import{e as n}from"../../chunks/earcut.js";import{isClockwise as t}from"./coordsUtils.js";import{deduplicate as e}from"./meshUtils/deduplicate.js";import{doubleSubArray as o,newDoubleArray as r}from"../../views/3d/webgl-engine/lib/DoubleArray.js";function i(t){const r=l(t.rings,t.hasZ,f.CCW_IS_HOLE),i=new Array;let c=0,h=0;for(const e of r.polygons){const t=e.count,s=e.index,l=o(r.position,3*s,3*t),f=e.holeIndices.map((n=>n-s)),g=new Uint32Array(n(l,f,3));i.push({position:l,faces:g}),c+=l.length,h+=g.length}const g=s(i,c,h),a=Array.isArray(g.position)?e(g.position,3,{originalIndices:g.faces}):e(g.position.buffer,6,{originalIndices:g.faces});return g.position=new Float64Array(a.buffer),g.faces=a.indices,g}function s(n,t,e){if(1===n.length)return n[0];const o=r(t),i=new Uint32Array(e);let s=0,l=0,c=0;for(const r of n){for(let n=0;n<r.position.length;n++)o[s++]=r.position[n];for(let n=0;n<r.faces.length;n++)i[l++]=r.faces[n]+c;c=s/3}return{position:o,faces:i}}function l(n,t,e){const o=n.length,i=new Array(o),s=new Array(o),l=new Array(o);let g=0,a=0,u=0,p=0;for(let r=0;r<o;++r)p+=n[r].length;const d=r(3*p);let y=0;for(let r=o-1;r>=0;r--){const p=n[r],A=e===f.CCW_IS_HOLE&&h(p);if(A&&1!==o)i[g++]=p;else{let n=p.length;for(let t=0;t<g;++t)n+=i[t].length;const e={index:y,pathLengths:new Array(g+1),count:n,holeIndices:new Array(g)};e.pathLengths[0]=p.length,p.length>0&&(l[u++]={index:y,count:p.length}),y=A?c(p,p.length-1,-1,d,y,p.length,t):c(p,0,1,d,y,p.length,t);for(let o=0;o<g;++o){const n=i[o];e.holeIndices[o]=y,e.pathLengths[o+1]=n.length,n.length>0&&(l[u++]={index:y,count:n.length}),y=c(n,0,1,d,y,n.length,t)}g=0,e.count>0&&(s[a++]=e)}}for(let r=0;r<g;++r){const n=i[r];n.length>0&&(l[u++]={index:y,count:n.length}),y=c(n,0,1,d,y,n.length,t)}return s.length=a,l.length=u,{position:d,polygons:s,outlines:l}}function c(n,t,e,o,r,i,s){r*=3;for(let l=0;l<i;++l){const i=n[t];o[r++]=i[0],o[r++]=i[1],o[r++]=s?i[2]:0,t+=e}return r/3}function h(n){return!t(n,!1,!1)}var f;!function(n){n[n.NONE=0]="NONE",n[n.CCW_IS_HOLE=1]="CCW_IS_HOLE"}(f||(f={}));export{f as CounterClockwiseMode,l as pathsToTriangulationInfo,i as triangulate};