/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{dot as n,sub as t,cross as r,normalize as o,scaleAndAdd as c,dist as u,len 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(t,r,o){const c=n(t,r)-o;return Math.abs(c)<=1e-5}function f(n,c,u){const i=s(),e=s();t(e,c,n);const f=s();return t(f,u,n),r(i,e,f),o(i,i),i}function a(r,u,i,a){const m=[u,i,a],h=f(u,i,a);if(!e(r,h,n(m[0],h)))return!1;for(let e=0;e<3;++e){const r=m[e],u=m[(e+1)%3],i=m[(e+2)%3],f=s();t(f,u,r),o(f,f);const a=s();t(a,i,r);const h=n(a,f),l=s();c(l,r,f,h);const M=s();t(M,i,l),o(M,M);const x=n(r,M);if(!(n(M,l)-x>=-1e-4))return!1}return!0}function m(n){const c=s();t(c,n[1],n[0]),o(c,c);const u=s();t(u,n[2],n[0]),o(u,u);const i=s();return r(i,c,u),o(i,i),i}function h(r,u,i){const e=s();t(e,i,u),o(e,e);const f=s();t(f,r,u);const a=n(f,e),m=s();return c(m,u,e,a),m}function l(n,t,r){const o=h(n,t,r);return u(o,n)}function M(r,e,f){const a=s();t(a,f,e);const m=i(a);o(a,a);const h=s();t(h,r,e);const l=n(h,a);if(l<0)return u(e,r);if(l>m)return u(f,r);const M=s();c(M,e,a,l);return u(M,r)}function x(t,r,o){return n(t,r)-o}function y(c,u,i){const e=s(),f=s();t(f,u,c);const a=s();t(a,i,c),r(e,f,a),o(e,e);return{normal:e,d:n(e,c)}}function A(n,t,r,o){const{normal:u,d:i}=y(t,r,o),e=x(n,u,i),f=s();return c(f,n,u,-e),a(f,t,r,o)?e:Math.min(M(n,t,r),M(n,r,o),M(n,o,t))}function b(r,o,u){const i=s();t(i,o,r);const e=m(u),f=n(e,u[0]),h=n(e,r)-f,l=n(e,o)-f;if(h*l>0)return 1/0;const M=s();return c(M,r,i,(0-h)/(l-h)),a(M,u[0],u[1],u[2])?0:A(M,u[0],u[1],u[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};
