/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as t}from"tslib";import{clamp as i}from"../../../../core/mathUtils.js";import{Milliseconds as e}from"../../../../core/time.js";import{subclass as r}from"../../../../core/accessorSupport/decorators.js";import{d as s,n as o,j as a,b as n,e as m,i as h,s as p}from"../../../../chunks/vec32.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as _}from"../../../../geometry/support/ray.js";import{Sphere as l}from"../../../../geometry/support/sphere.js";import{applyAll as y}from"../../camera/constraintUtils.js";import{ConstraintOptions as d}from"../../camera/constraintUtils/ConstraintOptions.js";import{applySurfaceCollisionConstraint as w}from"../../camera/constraintUtils/surfaceCollision.js";import{PointToPointAnimationController as g}from"./PointToPointAnimationController.js";import{excludeTerrain as f,inferNavigationMode as u,zoomStepDistanceClamp as D,getTiltScaleFactor as C,distanceComparisonTolerance as v,panToPosition as R,maxZoomStepDistanceModifier as j}from"../utils/navigationUtils.js";import{fromScreenAtEye as b}from"../../support/geometryUtils/ray.js";import{intersectScreen as M}from"../../support/geometryUtils/sphere.js";import O from"../../webgl/RenderCamera.js";import{Intersector as V}from"../../webgl-engine/lib/Intersector.js";import{outExpo as z}from"../../../animation/easing.js";const S=.6,U=4,L=60;let x=class extends g{constructor(){super(...arguments),this._zoomLocation=c(),this._tmpCamera=new O,this._tmpViewDir=c(),this._tmpRayDir=_(),this._targetOnSphere=c(),this._tmpCenter=c(),this._beginCamera=new O,this._constraintOptions=new d(7,1,null,this._beginCamera),this._sphere=new l}initialize(){this._intersector=new V(this.view.state.viewingMode)}step(t,i){if(!this.running)return;const e=this.view.state;this.animation.finished?this._beginCamera.copyFrom(e.camera):this.animation.cameraAt(1,this._beginCamera);let r=!1,o=!1;this._intersectionHelper.intersectScreen(i,this._zoomLocation,0===this.view.map.ground.opacity?f:{})&&(r=t>0,o=!0),this._tmpCamera.copyFrom(e.camera),r?this._intersectionHelper.intersectRay(this._tmpCamera.ray,this._intersector,this._tmpCenter)&&(this._tmpCamera.center=this._tmpCenter):this._intersectionHelper.intersectRay(this._tmpCamera.ray,this._intersector,this._zoomLocation)?this._tmpCamera.center=this._zoomLocation:s(this._zoomLocation,this._tmpCamera.center),this._updateCamera(this._tmpCamera,t,i,o),this.begin(this._tmpCamera)}animationSettings(){return{duration:e(600),easing:z}}_updateCamera(t,e,r,s){const c=u(t,r,this.view.renderCoordsHelper,this.view.viewingMode),_=Math.abs(this.view.camera.position.z),l=this._zoomLocation;o(H,t.eye),a(H,H,-1),b(t,r,this._tmpRayDir),o(this._tmpRayDir.direction,this._tmpRayDir.direction);const d=i(C(H,this._tmpRayDir.direction,j)*_,D[0],D[1]);if(1===c){let i=S**e;this._sphere.radius=n(l),m(this._tmpViewDir,t.center,t.eye);const s=Math.min(n(this._tmpViewDir),d);let o=s*i;if(i<=1&&o<U&&(o=U,i=o/s),Math.abs(s-o)<v)return;const c=n(t.center);if(this._sphere.radius!==c){const e=this._sphere.radius+i*(c-this._sphere.radius);t.center=a(F,t.center,e/c)}a(this._tmpViewDir,this._tmpViewDir,-i),t.eye=h(F,t.center,this._tmpViewDir),y(this.view,t,this._constraintOptions),p(l,t.center)>1e-12&&M(this._sphere,t,r,this._targetOnSphere)&&R(this._sphere,t,l,this._targetOnSphere,this.view.camera.heading,this.view.camera.tilt,!0)}else{let i=S**Math.abs(e);const p=e>0?1:-1;m(this._tmpViewDir,l,t.eye);const c=n(this._tmpViewDir),_=this.view.stage.renderView.getMinimalDepthForArea(null,r[0],r[1],this.view.state.camera,L);let w=null!=_?_:d;s&&e>0&&(w=Math.min(w,c)),a(this._tmpRayDir.direction,this._tmpRayDir.direction,w),h(l,this._tmpRayDir.origin,this._tmpRayDir.direction);let g=w*i;const f=Math.max(U,1.01*t.nearFar[0]);if(e>0&&g<f&&(g=f,i=g/w),Math.abs(w-g)<v)return;a(this._tmpRayDir.direction,this._tmpRayDir.direction,p*(1-i)),t.eye=h(F,t.eye,this._tmpRayDir.direction),t.center=h(F,t.center,this._tmpRayDir.direction),o(this._tmpRayDir.direction,this._tmpRayDir.direction),this._constraintOptions.interactionDirection=this._tmpRayDir.direction,y(this.view,t,this._constraintOptions),this._constraintOptions.interactionDirection=null}w(this.view,t)}};x=t([r("esri.views.3d.state.controllers.ZoomStepControllerGlobal")],x);const F=c(),H=c();export{x as ZoomStepControllerGlobal};
