/*
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/maybe","../../../../../core/PooledArray","../../../../../chunks/mat3","../../../../../chunks/mat3f64","../../../../../chunks/quat","../../../../../chunks/quatf64","../../../../../chunks/vec3","../../../../../chunks/vec3f64","../../../../../geometry/support/plane","../../../support/orientedBoundingBox","../../lib/depthRange"],(function(e,t,n,o,r,a,c,s,u,i,l,f){"use strict";function h(e,n){const o=f.empty(),{eye:r,frustum:a,viewForward:c}=e;n.forAll((e=>{const n=t.isSome(e.offsetObb)?e.offsetObb:e.obb,u=s.dot(s.sub(A,n.center,r),c),i=l.projectedRadius(n,c);if(f.within(o,u-i)&&f.within(o,u+i))return;const h=O(n,a);if(-1===h)return;if(0===h)return b.far=u+i,b.near=u-i,void f.union(o,b);const p=d.pushNew();p.near=u-i,p.far=u+i,p.mask=h,p.object=e}));for(let u=0;u<d.length;u++){const e=d.data[u];if(f.within(o,e.near)&&f.within(o,e.far))continue;b.far=e.far,b.near=1/0;const n=y(t.isSome(e.object.offsetObb)?e.object.offsetObb:e.object.obb,r,m,(t=>{let n=w;for(let o=0;o<v&&t.length>0;o++){if(0==(e.mask&1<<o))continue;S(a[o],t,n);const r=t;t=n,n=r}for(let e=0;e<t.length;e+=3){s.set(p,t.data[e+0],t.data[e+1],t.data[e+2]);const n=s.dot(s.sub(p,p,r),c);b.near=Math.min(b.near,n)}}));0===n&&(b.near=0),f.union(o,b)}return d.length=0,o}const d=new n({allocator:e=>e||{near:1/0,far:-1/0,mask:0,object:null},deallocator:e=>(e.object=null,e)}),b=f.empty(),p=u.create(),g=u.create(),m=new n({deallocator:null}),w=new n({deallocator:null});function S(e,t,n){n.length=0;const o=t.length-3;j(p,t,o);const r=i.signedDistance(e,p);r<=0&&(n.push(p[0]),n.push(p[1]),n.push(p[2]));let a=0,c=r;for(;a<o;a+=3){j(g,t,a);const o=i.signedDistance(e,g);if(c*o<0){const e=o/(o-c);s.lerp(p,g,p,e),k(n,p)}o<=0&&k(n,g),c=o,s.copy(p,g)}if(c*r<0){j(g,t,o);const e=r/(r-c);s.lerp(p,g,p,e),k(n,p)}}function j(e,t,n){return s.set(e,t.data[n+0],t.data[n+1],t.data[n+2])}function k(e,t){e.push(t[0]),e.push(t[1]),e.push(t[2])}function y(e,t,n,r){a.conjugate(M,e.quaternion),s.sub(A,t,e.center),s.transformQuat(A,A,M);const c=8*((A[0]<-e.halfSize[0]?-1:A[0]>e.halfSize[0]?1:0)+3*(A[1]<-e.halfSize[1]?-1:A[1]>e.halfSize[1]?1:0)+9*(A[2]<-e.halfSize[2]?-1:A[2]>e.halfSize[2]?1:0)+13),u=z[c];if(0===u)return u;o.fromQuat(q,e.quaternion),o.scale(q,q,e.halfSize);const i=(t,n)=>{const o=z[c+n+1];return s.set(t,((1&o)<<1)-1,(2&o)-1,((4&o)>>1)-1),s.transformMat3(t,t,q),s.add(t,e.center,t)};return n.length=0,k(n,i(D,0)),k(n,i(P,1)),k(n,i(A,2)),k(n,i(R,3)),r(n),1===u?u:(n.length=0,k(n,D),k(n,R),k(n,i(A,4)),k(n,i(x,5)),r(n),2===u||(n.length=0,k(n,D),k(n,x),k(n,i(A,6)),k(n,P),r(n)),u)}const z=(()=>{const e=new Int8Array(216);let t=0;const n=n=>{for(let o=0;o<n.length;o++)e[t+o]=n[o];t+=8};return n([3,0,6,2,3,1,5,4]),n([2,0,2,3,1,5,4,0]),n([3,1,0,2,3,7,5,4]),n([2,0,1,3,2,6,4,0]),n([1,0,1,3,2,0,0,0]),n([2,1,5,7,3,2,0,0]),n([3,2,0,1,3,7,6,4]),n([2,2,0,1,3,7,6,0]),n([3,3,0,1,5,7,6,2]),n([2,0,1,5,4,6,2,0]),n([1,0,1,5,4,0,0,0]),n([2,1,3,7,5,4,0,0]),n([1,0,2,6,4,0,0,0]),n([0,0,0,0,0,0,0,0]),n([1,1,3,7,5,0,0,0]),n([2,2,3,7,6,4,0,0]),n([1,2,3,7,6,0,0,0]),n([2,3,1,5,7,6,2,0]),n([3,4,0,1,5,7,6,2]),n([2,5,7,6,4,0,1,0]),n([3,5,0,1,3,7,6,4]),n([2,4,5,7,6,2,0,0]),n([1,4,5,7,6,0,0,0]),n([2,5,1,3,7,6,4,0]),n([3,6,0,2,3,7,5,4]),n([2,6,2,3,7,5,4,0]),n([3,7,6,2,3,1,5,4]),e})(),v=4;function O(e,t){let n=0;for(let o=0;o<v;o++){const r=l.intersectPlane(e,t[o]);if(r>0)return-1;0===r&&(n|=1<<o)}return n}const q=r.create(),M=c.create(),A=u.create(),D=u.create(),P=u.create(),R=u.create(),x=u.create();e.computeDepthRange=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
