/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{sub as n,normalize as t,cross as r,dist as o,dot as c,len as u,scaleAndAdd as i}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";function e(n,t,r){const o=c(n,t)-r;return Math.abs(o)<=1e-5}function f(o,c,u){const i=s(),e=s();n(e,c,o);const f=s();return n(f,u,o),r(i,e,f),t(i,i),i}function a(r,o,u,a){const m=[o,u,a],h=f(o,u,a);if(!e(r,h,c(m[0],h)))return!1;for(let e=0;e<3;++e){const r=m[e],o=m[(e+1)%3],u=m[(e+2)%3],f=s();n(f,o,r),t(f,f);const a=s();n(a,u,r);const h=c(a,f),l=s();i(l,r,f,h);const M=s();n(M,u,l),t(M,M);const x=c(r,M);if(!(c(M,l)-x>=-1e-4))return!1}return!0}function m(o){const c=s();n(c,o[1],o[0]),t(c,c);const u=s();n(u,o[2],o[0]),t(u,u);const i=s();return r(i,c,u),t(i,i),i}function h(r,o,u){const e=s();n(e,u,o),t(e,e);const f=s();n(f,r,o);const a=c(f,e),m=s();return i(m,o,e,a),m}function l(n,t,r){const c=h(n,t,r);return o(c,n)}function M(r,e,f){const a=s();n(a,f,e);const m=u(a);t(a,a);const h=s();n(h,r,e);const l=c(h,a);if(l<0)return o(e,r);if(l>m)return o(f,r);const M=s();i(M,e,a,l);return o(M,r)}function x(n,t,r){return c(n,t)-r}function y(o,u,i){const e=s(),f=s();n(f,u,o);const a=s();n(a,i,o),r(e,f,a),t(e,e);return{normal:e,d:c(e,o)}}function A(n,t,r,o){const{normal:c,d:u}=y(t,r,o),e=x(n,c,u),f=s();return i(f,n,c,-e),a(f,t,r,o)?e:Math.min(M(n,t,r),M(n,r,o),M(n,o,t))}function b(t,r,o){const u=s();n(u,r,t);const e=m(o),f=c(e,o[0]),h=c(e,t)-f,l=c(e,r)-f;if(h*l>0)return 1/0;const M=s();return i(M,t,u,(0-h)/(l-h)),a(M,o[0],o[1],o[2])?0:A(M,o[0],o[1],o[2])}function g(n,t){const r=n.length;if(0===r)return 0;if(t<n[0])return-1;if(t>=n[r-1])return r;let o=0,c=r-1;for(;c-o>1;){const r=Math.floor(.5*(c+o));t>=n[r]?o=r:c=r}return o}function p(n,t,r,o,c,u,i){const s=u-i,e=t-n,f=new Float64Array(4*e);for(let a=0;a<e;++a){const t=3*(a+n),u=c*r[t+0],e=o[u+0],m=o[u+1],h=s/(o[u+2]-i),l=e*h,M=m*h,x=c*r[t+1],y=o[x+0],A=o[x+1],b=s/(o[x+2]-i),g=y*b,p=A*b,w=c*r[t+2],U=o[w+0],d=o[w+1],j=s/(o[w+2]-i),v=U*j,F=d*j,q=4*a;f[q+0]=Math.min(l,g,v),f[q+1]=Math.min(M,p,F),f[q+2]=Math.max(l,g,v),f[q+3]=Math.max(M,p,F)}return f}function w(n,t,r,o,c){const u=t-n,i=new Float64Array(4*u);for(let s=0;s<u;++s){const t=3*(s+n),u=c*r[t+0],e=o[u+0],f=o[u+1],a=c*r[t+1],m=o[a+0],h=o[a+1],l=c*r[t+2],M=o[l+0],x=o[l+1],y=4*s;i[y+0]=Math.min(e,m,M),i[y+1]=Math.min(f,h,x),i[y+2]=Math.max(e,m,M),i[y+3]=Math.max(f,h,x)}return i}function U(n,t){return new(d(n))(t)}function d(n){return n<128?Uint8Array:n<32768?Uint16Array:n<1<<31?Uint32Array:Array}function j(n,t){n[2]+=t}function v(n,t,r,o){const[c,u,i]=o??n,s=i-r,e=t/Math.sqrt(c*c+u*u+s*s);n[0]+=c*e,n[1]+=u*e,n[2]+=s*e}export{g as binarySearchSortedArray,m as calculateNormalFromVertices,U as createUintArray,l as distancePointLine,x as distancePointPlane,M as distancePointSegment,A as distancePointTriangle,v as elevationAlignVertexGlobal,j as elevationAlignVertexLocal,p as generateTriangleAabbsGlobal,w as generateTriangleAabbsLocal,d as getConstructorForValueCount,h as getNearestPointOnLine,b as getRayTriangleIntersectionDistance,f as getTriangleNormal,y as getTrianglePlane,e as isPointInPlane,a as isPointInTriangle};
