/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{neverReached as t}from"../../../core/compilerUtils.js";import{clamp as a}from"../../../core/mathUtils.js";import{signal as e}from"../../../core/signal.js";import{rotate as s}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as i,create as r}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{D as h,n as o,j as n,d as c,b as d,e as l}from"../../../chunks/vec32.js";import{create as _,fromValues as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as f,fromPoints as p,axis as m}from"../../../geometry/support/axisAngleDegrees.js";import{earth as F}from"../../../geometry/support/Ellipsoid.js";import{ensureClouds as P}from"./Clouds.js";import{heightLimit as x}from"./weather.js";class v{constructor(){this.startTime=0,this._data=e(null),this.coverage=0,this.absorption=0,this._readChannels=0,this.parallax=new g,this.parallaxNew=new g,this._anchorPoint=_(),this._fadeState=e(0),this._fadeFactor=e(1)}get data(){return this._data.value}set data(t){this._data.value=t}get readChannels(){return this._readChannels}get fadeState(){return this._fadeState.value}get fadeFactor(){return this._fadeFactor.value}get opacity(){switch(this.fadeState){case 0:return 0;case 4:return 1-this.fadeFactor;case 1:return this.fadeFactor;case 2:case 3:return 1}}fade(t,e,s){this.isFading&&this.fadeFactor<1&&(this._fadeFactor.value=s?a((e-this.startTime)/(C*s),0,1):1,1===this.fadeFactor&&this._endFade()),this._evaluateState(t,e),this._updateParallax(t)}_evaluateState(t,a){const e=t.relativeElevation,s=this._updateAnchorPoint(t);(Math.abs(e)>1.7*x||s>k)&&this.opacity>0?this._startFade(0,a):this.isFading||(Math.abs(e)>x||s>j*k?this.opacity>0&&this._startFade(4,a):P(this.data)&&(0===this.opacity?this._startFade(1,a):2===this.data.state&&(2===this.fadeState?this._startFade(3,a):this._startFade(2,a))))}_updateParallax(t){const a=h(t.eye);this.parallax.radiusCurvatureCorrection=.84*Math.sqrt(Math.max(a-F.radius*F.radius,0))/Math.sqrt(a),p(w,this.parallax.anchorPoint,S),s(this.parallax.transform,i,S[3],m(S)),p(w,this.parallaxNew.anchorPoint,S),s(this.parallaxNew.transform,i,S[3],m(S))}_updateAnchorPoint(t){return o(this._anchorPoint,t.eye),n(this._anchorPoint,this._anchorPoint,F.radius),0===this.fadeState&&2===this.data?.state?(c(this.parallax.anchorPoint,this._anchorPoint),0):d(l(b,this.parallax.anchorPoint,this._anchorPoint))}requestFade(){this._fadeFactor.value=0}_startFade(t,a){switch(this._fadeState.value=t,this.startTime=a,t){case 3:this.requestFade(),this._switchReadChannels(),c(this.parallaxNew.anchorPoint,this._anchorPoint);break;case 1:this.requestFade(),this._switchReadChannels(),c(this.parallax.anchorPoint,this._anchorPoint),c(this.parallaxNew.anchorPoint,this._anchorPoint);break;case 4:this.requestFade();break;case 2:this._switchReadChannels(),c(this.parallax.anchorPoint,this._anchorPoint),c(this.parallaxNew.anchorPoint,this._anchorPoint),this._endFade();break;case 0:this._endFade()}}_endFade(){switch(this._fadeFactor.value=1,this.data&&2!==this.data.state&&(this.data.state=0),this.fadeState){case 3:c(this.parallax.anchorPoint,this.parallaxNew.anchorPoint),this._fadeState.value=2;break;case 1:this._fadeState.value=2;break;case 4:this._fadeState.value=0;break;case 2:case 0:break;default:t(this.fadeState)}}_switchReadChannels(){2===this.data?.state&&(this._readChannels=1-this._readChannels,this.data.state=3)}get isFading(){return 4===this.fadeState||1===this.fadeState||3===this.fadeState}}class g{constructor(){this.anchorPoint=_(),this.radiusCurvatureCorrection=0,this.transform=r()}}const w=u(0,0,1),S=f(),b=_(),C=1.25,j=.5,k=2e5;export{v as CloudsParameters};
