/*
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/compilerUtils","../../../core/mathUtils","../../../chunks/mat4","../../../chunks/mat4f64","../../../chunks/vec3","../../../chunks/vec3f64","../../../geometry/projection","../../../geometry/projectionEllipsoid","../../../geometry/support/aaBoundingBox","../../../geometry/support/aaBoundingRect","../../../geometry/support/frustum","../../../geometry/support/lineSegment","../../../geometry/support/plane","../../../geometry/support/ray","../../ViewingMode","./intersectionUtils"],(function(e,t,n,i,r,o,s,a,c,l,d,p,h,g,u,x,f){"use strict";const m=.5*Math.PI,R=m/Math.PI*180;let y=function(){function e(e){this.renderCoordsHelper=e.renderCoordsHelper,this.extent=new Array(4),this.planes=new Array(6),this.maxSpan=0,this.center={origin:s.create(),direction:s.create()};for(let t=0;t<4;t++)this.extent[t]={origin:s.create(),direction:s.create(),cap:{next:null,direction:s.create()}},this.planes[t]=g.create();this.planes[p.PlaneIndex.NEAR]=g.create(),this.planes[p.PlaneIndex.FAR]=g.create(),this.planesWithoutFar=this.planes.slice(0,5)}var r=e.prototype;return r.update=function(e,t,n,i=!0){const r=this.extent;this._toRenderBoundingExtent(e,t,n),o.add(this.center.origin,r[0].origin,r[2].origin),o.scale(this.center.origin,this.center.origin,.5),this.renderCoordsHelper.worldUpAtPosition(this.center.origin,this.center.direction),i||o.scale(this.center.direction,this.center.direction,-1);for(let s=0;s<4;s++){const e=r[s];this.renderCoordsHelper.worldUpAtPosition(e.origin,e.direction);const t=r[3===s?0:s+1];e.cap.next=t.origin,o.direction(e.cap.direction,e.origin,t.origin),g.fromVectorsAndPoint(e.direction,e.cap.direction,e.origin,this.planes[s]),i||o.scale(e.direction,e.direction,-1)}g.fromVectorsAndPoint(r[0].cap.direction,r[1].cap.direction,r[0].origin,this.planes[p.PlaneIndex.NEAR]),i?g.negate(this.planes[p.PlaneIndex.NEAR],this.planes[p.PlaneIndex.FAR]):(g.copy(this.planes[p.PlaneIndex.FAR],this.planes[p.PlaneIndex.NEAR]),g.negate(this.planes[p.PlaneIndex.NEAR],this.planes[p.PlaneIndex.NEAR])),this.maxSpan=Math.max(Math.abs(e[0]-e[2]),Math.abs(e[1]-e[3])),this.maxSpanSpatialReference=t,this.minGlobalAltitude=.9*c.getReferenceEllipsoid(this.maxSpanSpatialReference).radius},r.isVisibleInFrustum=function(e,t,n=!1){if(null==e)return!1;if(this.renderCoordsHelper.viewingMode===x.ViewingMode.Global){const n=this.maxSpanSpatialReference.isGeographic?R:m*t;if(this.maxSpan>n)return!0;if(e.altitude>=this.minGlobalAltitude)return this._isVisibleInFrustumGlobal(e)}if(0===this.maxSpan){const t=this.extent[0];return!(n||!e.intersectsRay(u.wrap(t.origin,t.direction)))}for(let r=0;r<this.extent.length;r++){const t=this.extent[r];if(!n&&e.intersectsRay(u.wrap(t.origin,t.direction)))return!0;if(e.intersectsLineSegment(h.fromPoints(t.origin,t.cap.next,S),t.cap.direction))return!0}const i=n?this.planes:this.planesWithoutFar;for(let r=0;r<e.lines.length;r++){const t=e.lines[r];if(f.frustumLineSegment(i,t.origin,t.endpoint,t.direction))return!0}return!1},r._toRenderBoundingExtentGlobal=function(e,t,r){const s=5;d.center(e,P),P[2]=r,a.computeTranslationToOriginAndRotation(t,P,b,this.renderCoordsHelper.spatialReference),i.invert(E,b),l.empty(I);for(const{x0:i,x1:c,y0:d,y1:p}of A)for(let h=0;h<s;h++){const g=h/(s-1);P[0]=n.lerp(e[i],e[c],g),P[1]=n.lerp(e[d],e[p],g),P[2]=r,a.projectVectorToVector(P,t,P,this.renderCoordsHelper.spatialReference),o.transformMat4(P,P,E),l.expandWithVec3(I,P)}o.set(this.extent[0].origin,I[0],I[1],I[2]),o.set(this.extent[1].origin,I[3],I[1],I[2]),o.set(this.extent[2].origin,I[3],I[4],I[2]),o.set(this.extent[3].origin,I[0],I[4],I[2]);for(let n=0;n<4;++n)o.transformMat4(this.extent[n].origin,this.extent[n].origin,b)},r._toRenderBoundingExtentLocal=function(e,t,n){a.projectBoundingRect(e,t,M,this.renderCoordsHelper.spatialReference),o.set(this.extent[0].origin,M[0],M[1],n),o.set(this.extent[1].origin,M[2],M[1],n),o.set(this.extent[2].origin,M[2],M[3],n),o.set(this.extent[3].origin,M[0],M[3],n)},r._toRenderBoundingExtent=function(e,n,i){switch(this.renderCoordsHelper.viewingMode){case x.ViewingMode.Global:this._toRenderBoundingExtentGlobal(e,n,i);break;case x.ViewingMode.Local:this._toRenderBoundingExtentLocal(e,n,i);break;default:t.neverReached(this.renderCoordsHelper.viewingMode)}},r._isVisibleInFrustumGlobal=function(e){if(g.signedDistance(e.planes[p.PlaneIndex.NEAR],this.center.origin)<0&&o.dot(this.center.direction,e.direction)<0)return!0;for(let t=0;t<4;t++){const n=this.extent[t];if(g.signedDistance(e.planes[p.PlaneIndex.NEAR],n.origin)<0&&o.dot(n.direction,e.direction)<0)return!0}return!1},e}();const A=[{x0:0,y0:1,x1:2,y1:1},{x0:0,y0:3,x1:2,y1:3},{x0:0,y0:1,x1:0,y1:3},{x0:2,y0:1,x1:2,y1:3}],P=s.create(),b=r.create(),E=r.create(),I=l.create(),M=d.create(),S=h.create();e.FrustumExtentIntersection=y,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
