/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{deg2rad as a,lerp as r,clamp as s}from"../../../core/mathUtils.js";import{watch as i,syncAndInitial as l}from"../../../core/reactiveUtils.js";import{property as n,subclass as c}from"../../../core/accessorSupport/decorators.js";import{j as o}from"../../../chunks/boundedPlane.js";import{Sphere as u}from"../../../geometry/support/sphere.js";import{ScreenSizePerspectiveParameters as m}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";let f=class extends t{get parameters(){return this._parameters}get labelParameters(){return this._labelParameters}get _calculations(){return this.view.state.isGlobal?new d(this.view.renderCoordsHelper?.referenceEllipsoid.radius??0):new p}constructor(e){super(e),this._parameters=new m,this._labelParameters=new m}initialize(){this.addHandles([i(()=>({distance:this.view.pointsOfInterest?.centerOnSurfaceInfrequent?.distance??0,fovY:this.view.state.camera.fovY}),e=>this._update(e),l)])}_update(e){const t=this._updateParameters(this._parameters,h,e),a=this._updateParameters(this._labelParameters,F,e);return t||a}_updateParameters(e,t,a){if(e&&e.camera.fovY===a.fovY&&e.camera.distance===a.distance)return!1;const{scaleStart:r,scaleFallOffRange:s}=t,{fovY:i,distance:l}=a;this._calculations.calculateCurvatureDependentParameters(g,t,a);const n=this._calculations.surfaceCoverageCompensation(a,g),{tiltAngle:c,scaleFallOffFactor:o}=g,u=Math.sin(c)*l,m=.5*Math.PI-c-i*(.5-r*n),f=u/Math.cos(m),p=m+i*s*n,d=(f-o*(u/Math.cos(p)))/(1-o);return e.camera.fovY=a.fovY,e.camera.distance=a.distance,e.offset=d,e.divisor=f-d,e.minPixelSize=t.minPixelSize,!0}};e([n({constructOnly:!0})],f.prototype,"view",void 0),e([n()],f.prototype,"_calculations",null),f=e([c("esri.views.3d.state.ScreenSizePerspective")],f);class p{surfaceCoverageCompensation(e,t){return o(t.tiltAngle,e.fovY)}calculateCurvatureDependentParameters(e,t){e.tiltAngle=t.curvatureDependent.min.tiltAngle,e.scaleFallOffFactor=t.curvatureDependent.min.scaleFallOffFactor}}class d{constructor(e){this._ellipsoidRadius=e}surfaceCoverageCompensation(e,t){return P.radius=this._ellipsoidRadius,P.frustumCoverage(t.tiltAngle,e.distance,e.fovY)}calculateCurvatureDependentParameters(e,t,a){const i=t.curvatureDependent,l=1+a.distance/this._ellipsoidRadius,n=Math.sqrt(l*l-1),[c,o]=[i.min.curvature,i.max.curvature],u=s((n-c)/(o-c),0,1),[m,f]=[i.min,i.max];e.tiltAngle=r(m.tiltAngle,f.tiltAngle,u),e.scaleFallOffFactor=r(m.scaleFallOffFactor,f.scaleFallOffFactor,u)}}class v{constructor(){this.tiltAngle=0,this.scaleFallOffFactor=0}}const h={curvatureDependent:{min:{curvature:a(10),tiltAngle:a(12),scaleFallOffFactor:.5},max:{curvature:a(70),tiltAngle:a(40),scaleFallOffFactor:.8}},scaleStart:.3,scaleFallOffRange:.65,minPixelSize:0},F={...h,curvatureDependent:{min:{...h.curvatureDependent.min,scaleFallOffFactor:.7},max:{...h.curvatureDependent.max,scaleFallOffFactor:.95}},minPixelSize:14},g=new v,P=new u;export{f as ScreenSizePerspective};
