/*
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/mathUtils","../../../core/maybe","../../../core/unitUtils","../../../chunks/vec3","../../../chunks/vec3f64","../../../geometry/Extent","../../../geometry/projectionEllipsoid","../../ViewingMode"],(function(e,t,n,i,r,a,s,o,l){"use strict";function m(e,t,n){return e===l.ViewingMode.Global?new u(n):new c(t,n)}let c=function(){function e(e,t){this.elevationProvider=e,this._referenceEllipsoid=o.getReferenceEllipsoid(t),this.unitInMeters=i.getMetersPerUnitForSR(t,this._referenceEllipsoid.metersPerDegree)}return e.prototype.compute=function(e,i,a,o,l){l||(l={near:0,far:0});let m=e[2]*this.unitInMeters;const c=m,u=m-o,M=this.elevationProvider?this.elevationProvider.elevationBounds:null;M&&(m=u>=0?c-this.unitInMeters*M.min:this.unitInMeters*M.max-c);const g={x:(a=n.isSome(a)?a:new s({xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0})).xmax-a.xmin,y:a.ymax-a.ymin,z:4*Math.max(a.xmax-a.xmin,a.ymax-a.ymin)},v=Math.max(g.x,g.y,g.z);r.subtract(y,i,e),p[0]=y[0]>0?a.xmax:a.xmin,p[1]=y[1]>0?a.ymax:a.ymin,p[2]=y[2]>0?v/2:-v/2,r.subtract(p,p,e),r.normalize(y,y);const E=1.1*r.dot(p,y)*this.unitInMeters,b=Math.sqrt(m*(m+2*this._referenceEllipsoid.radius)),I=Math.max(a.xmax-a.xmin,a.ymax-a.ymin),_=I*f*this.unitInMeters,P=I*d*this.unitInMeters;let w=t.clamp((m-P)/(_-P),0,1);w*=w*w;let z=t.lerp(b,E,w);return z*=Math.max(Math.log(Math.abs(u)),1),z=Math.min(z,Math.max(34064e4,v)),z/=this.unitInMeters,h(z,x,this.unitInMeters,l)},e}(),u=function(){function e(e){this._referenceEllipsoid=o.getReferenceEllipsoid(e)}return e.prototype.compute=function(e,n,i,a,s){s||(s={near:0,far:0});const o=r.length(e)-this._referenceEllipsoid.radius,l=this._referenceEllipsoid.radius+Math.min(0,a),m=Math.abs(o-a),c=Math.max(m,Math.abs(o));return h(1.2*Math.sqrt(c*(c+2*l)),t.clamp(2e4-(Math.log(c)-7.983)/9.011*19e3,1e3,2e4),1,s)},e}();function h(e,t,n,i){const r=M/n;return e/t>r?(i.far=e,i.near=i.far/t):(i.near=r,i.far=i.near*t),i}const x=2e4,M=2,f=.001,d=1e-4,p=a.create(),y=a.create();e.createNearFarHeuristic=m,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
