/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../chunks/_rollupPluginBabelHelpers","../../../../../chunks/tslib.es6","../../../../../core/time","../../../../../core/Logger","../../../../../core/accessorSupport/ensureType","../../../../../core/arrayUtils","../../../../../core/has","../../../../../core/accessorSupport/set","../../../../../core/accessorSupport/decorators/subclass","../../../../../chunks/vec3","../../../../../chunks/vec3f64","../../../../../geometry/projectionEllipsoid","../../../../../chunks/sphere","../../../camera/constraintUtils","../../../camera/constraintUtils/common","../PointToPointAnimationController","../../utils/navigationUtils","../../../support/geometryUtils/ray","../../../support/geometryUtils/sphere","../../../webgl-engine/lib/Camera","../../../webgl-engine/lib/Intersector","../../../webgl-engine/lib/verticalOffsetUtils","../../../../animation/easing","../../../camera/constraintUtils/surfaceCollision"],(function(t,e,i,r,n,a,o,s,c,h,l,p,m,u,d,y,g,C,w,v,D,f,M,S,b){"use strict";const R=.6,L=4,z=12,O=60,T=200;t.ZoomStepController=function(t){function i(){var e;return(e=t.apply(this,arguments)||this).zoomLocation=p.create(),e.tmpCamera=new D.Camera,e.tmpViewDir=p.create(),e.tmpRayDir={origin:p.create(),direction:p.create()},e.targetOnSphere=p.create(),e.tmpCenter=p.create(),e.constraintOptions={selection:y.ConstraintTypes.ALL_EXCEPT_COLLISION,interactionType:y.InteractionType.ZOOM,interactionFactor:null,interactionStartCamera:new D.Camera,interactionDirection:null,tiltMode:y.TiltMode.TUMBLE},e.sphere=u.create(),e}e._inheritsLoose(i,t);var n=i.prototype;return n.initialize=function(){this.intersector=f.newIntersector(this.view.state.viewingMode)},n.zoomStep=function(t,e){if(!this.active)return;const i=this.view.state,{interactionStartCamera:r}=this.constraintOptions;this.animation.finished?r.copyFrom(i.camera):this.animation.cameraAt(1,r);let n=!1,a=!1;this.intersectionHelper.intersectScreen(e,this.zoomLocation,0===this.view.map.ground.opacity?V:{})&&(n=t>0,a=!0),this.tmpCamera.copyFrom(i.camera),n?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:l.copy(this.zoomLocation,this.tmpCamera.center),this._updateCamera(this.tmpCamera,t,this.zoomLocation,e,a),this.begin(this.tmpCamera)},n.animationSettings=function(){return{apex:null,duration:r.Milliseconds(600),easing:S.outExpo}},n._updateCamera=function(t,e,i,r,n){const a=m.getReferenceEllipsoid(this.view.spatialReference),o=C.decideNavigationMode(t,r,n,a);let s;this.view.camera.position.hasZ&&(s=Math.abs(this.view.camera.position.z)),l.normalize(U,t.eye),l.scale(U,U,-1),w.fromScreenAtEye(t,r,this.tmpRayDir),l.normalize(this.tmpRayDir.direction,this.tmpRayDir.direction);const c=Math.max(Math.min(z,1/Math.abs(l.dot(U,this.tmpRayDir.direction)))*s,T);if(o===C.NavigationMode.Horizontal){let n=R**e;this.sphere[3]=l.length(i),l.subtract(this.tmpViewDir,t.center,t.eye);const a=Math.min(l.length(this.tmpViewDir),c);let o=a*n;if(n<=1&&o<L&&(o=L,n=o/a),Math.abs(a-o)<1e-6)return;const s=l.length(t.center);if(this.sphere[3]!==s){const e=this.sphere[3]+n*(s-this.sphere[3]);t.center=l.scale(_,t.center,e/s)}l.scale(this.tmpViewDir,this.tmpViewDir,-n),t.eye=l.add(_,t.center,this.tmpViewDir),d.applyAll(this.view,t,this.constraintOptions),l.squaredDistance(i,t.center)>1e-12&&v.intersectScreen(this.sphere,t,r,this.targetOnSphere)&&C.panToPosition(this.sphere,t,i,this.targetOnSphere,this.view.camera.heading,this.view.camera.tilt,!0)}else{let a=R**Math.abs(e);const o=e>0?1:-1;l.subtract(this.tmpViewDir,i,t.eye);const s=l.length(this.tmpViewDir),h=this.view._stage.renderView.getMinimalDepthForArea(null,r[0],r[1],this.view.state.camera,O);let p=h?Math.min(c,h):c;p=n?Math.min(p,s):p,l.scale(this.tmpRayDir.direction,this.tmpRayDir.direction,p),l.add(i,this.tmpRayDir.origin,this.tmpRayDir.direction);let m=p*a;const u=Math.max(L,1.01*t.nearFar[0]);if(e>0&&m<u&&(m=u,a=m/p),Math.abs(p-m)<1e-6)return;l.scale(this.tmpRayDir.direction,this.tmpRayDir.direction,o*(1-a)),t.eye=l.add(_,t.eye,this.tmpRayDir.direction),t.center=l.add(_,t.center,this.tmpRayDir.direction)}b.applySurfaceCollisionConstraint(this.view,t)},i}(g.PointToPointAnimationController),t.ZoomStepController=i.__decorate([h.subclass("esri.views.3d.state.controllers.global.ZoomStepController")],t.ZoomStepController);const _=p.create(),U=p.create(),V={exclude:new Set([M.TERRAIN_ID])};Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
