/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../core/arrayUtils","../../../../../core/mathUtils","../../../../../core/typedArrayUtil","../../../../../chunks/vec3","../../../../../chunks/vec3f64"],(function(e,t,n,o,c,r){"use strict";const a=-1;var s;function i(e,r,s,i=v){const h=e.vertices.position,m=e.vertices.componentIndex,y=n.deg2rad(i.anglePlanar),A=n.deg2rad(i.angleSignificantEdge),w=Math.cos(A),E=Math.cos(y),I=p.edge,S=I.position0,V=I.position1,x=I.faceNormal0,N=I.faceNormal1,T=u(e),b=f(e),D=b.length/4,F=r.allocate(D);let M=0;const C=D,L=s.allocate(C);let O=0,P=0,U=0;const k=t.range(0,D),H=new Float32Array(D);o.forEach(H,((e,t,n)=>{h.getVec(b[4*t+0],S),h.getVec(b[4*t+1],V),n[t]=c.distance(S,V)})),k.sort(((e,t)=>H[t]-H[e]));const K=new Array,_=new Array;for(let t=0;t<D;t++){const e=k[t],n=H[e],o=b[4*e+0],i=b[4*e+1],f=b[4*e+2],u=b[4*e+3],p=u===a;if(h.getVec(o,S),h.getVec(i,V),p)c.set(x,T[3*f+0],T[3*f+1],T[3*f+2]),c.copy(N,x),I.componentIndex=m.get(o),I.cosAngle=c.dot(x,N);else{if(c.set(x,T[3*f+0],T[3*f+1],T[3*f+2]),c.set(N,T[3*u+0],T[3*u+1],T[3*u+2]),I.componentIndex=m.get(o),I.cosAngle=c.dot(x,N),g(I,E))continue;I.cosAngle<-.9999&&c.copy(N,x)}P+=n,U++,p||l(I,w)?(r.write(F,M++,I),K.push(n)):d(I,y)&&(s.write(L,O++,I),_.push(n))}const j=new Float32Array(K.reverse()),z=new Float32Array(_.reverse());return{regular:{instancesData:r.trim(F,M),lodInfo:{lengths:j}},silhouette:{instancesData:s.trim(L,O),lodInfo:{lengths:z}},averageEdgeLength:P/U}}function l(e,t){return e.cosAngle<t}function g(e,t){return e.cosAngle>t}function d(e,t){const o=n.acosClamped(e.cosAngle),r=p.fwd,a=p.ortho;c.direction(r,e.position1,e.position0);return o*(c.dot(c.cross(a,e.faceNormal0,e.faceNormal1),r)>0?-1:1)>t}function f(e){const t=e.faces.length/3,n=e.faces,o=e.neighbors;let c=0;for(let i=0;i<t;i++){const e=o[3*i+0],t=o[3*i+1],r=o[3*i+2],s=n[3*i+0],l=n[3*i+1],g=n[3*i+2];c+=e===a||s<l?1:0,c+=t===a||l<g?1:0,c+=r===a||g<s?1:0}const r=new Int32Array(4*c);let s=0;for(let i=0;i<t;i++){const e=o[3*i+0],t=o[3*i+1],c=o[3*i+2],l=n[3*i+0],g=n[3*i+1],d=n[3*i+2];(e===a||l<g)&&(r[s++]=l,r[s++]=g,r[s++]=i,r[s++]=e),(t===a||g<d)&&(r[s++]=g,r[s++]=d,r[s++]=i,r[s++]=t),(c===a||d<l)&&(r[s++]=d,r[s++]=l,r[s++]=i,r[s++]=c)}return r}function u(e){const t=e.faces.length/3,n=e.vertices.position,o=e.faces,r=h.v0,a=h.v1,s=h.v2,i=new Float32Array(3*t);for(let l=0;l<t;l++){const e=o[3*l+0],t=o[3*l+1],g=o[3*l+2];n.getVec(e,r),n.getVec(t,a),n.getVec(g,s),c.subtract(a,a,r),c.subtract(s,s,r),c.cross(r,a,s),c.normalize(r,r),i[3*l+0]=r[0],i[3*l+1]=r[1],i[3*l+2]=r[2]}return i}e.EdgeType=void 0,(s=e.EdgeType||(e.EdgeType={}))[s.SOLID=0]="SOLID",s[s.SKETCH=1]="SKETCH";const p={edge:{position0:r.create(),position1:r.create(),faceNormal0:r.create(),faceNormal1:r.create(),componentIndex:0,cosAngle:0},ortho:r.create(),fwd:r.create()},h={v0:r.create(),v1:r.create(),v2:r.create()},v={anglePlanar:4,angleSignificantEdge:35};e.extractEdges=i,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
