/*
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/mathUtils","../../../../../core/screenUtils","../../../../../core/accessorSupport/decorators/property","../../../../../core/arrayUtils","../../../../../core/has","../../../../../core/accessorSupport/ensureType","../../../../../core/accessorSupport/decorators/subclass","../../../../../chunks/vec2","../../../../../chunks/vec2f64","../../../../../chunks/vec3","../../../../../chunks/vec3f64","../../../../../geometry/support/plane","../../../camera/constraintUtils","../../../camera/constraintUtils/common","../InteractiveController","../../utils/navigationUtils","../../../webgl-engine/lib/verticalOffsetUtils"],(function(t,e,i,r,n,a,s,o,c,h,m,l,p,u,C,P,y,d,v,D){"use strict";t.ZoomController=function(t){function i(e){var i;return(i=t.call(this,e)||this).view=null,i.tmpP=u.create(),i.tmpDir=u.create(),i.tmpN=u.create(),i.tmpP0=l.create(),i.tmpPoi=u.create(),i.tmpRayDir=u.create(),i.dragBeginPoint=n.createScreenPointArray(),i.normalizedAnchorPoint=l.create(),i.constraintOptions={selection:y.ConstraintTypes.ALL,interactionType:y.InteractionType.ZOOM,interactionFactor:0,interactionStartCamera:null,interactionDirection:u.create(),tiltMode:y.TiltMode.TUMBLE},i.plane=C.create(),i}e._inheritsLoose(i,t);var a=i.prototype;return a.begin=function(t){if(!this.active)return;m.copy(this.dragBeginPoint,t),v.normalizeCoordinate(this.startCamera,t,this.normalizedAnchorPoint);const e=this.intersectionHelper.intersectScreenFreePointFallback(t,this.tmpP,0===this.view.map.ground.opacity?A:{});p.subtract(this.tmpDir,this.tmpP,this.startCamera.eye);const i=p.length(this.tmpDir);let n;p.normalize(this.tmpDir,this.tmpDir),this.view.camera.position.hasZ&&(n=Math.abs(this.view.camera.position.z));let a=r.clamp(v.PIVOT_DISTANCE_MODIFIER*n,v.DISTANCE_CLAMP_VALUES[0],v.DISTANCE_CLAMP_VALUES[1]);const s=this.view._stage.renderView.getMinimalDepthForArea(this.view.voxelWasm,t[0],t[1],this.view.state.camera,v.SCREEN_PIXEL_AREA);a=s?Math.min(a,s):a,a=e?Math.min(a,i):a,p.scale(this.tmpDir,this.tmpDir,a),p.add(this.tmpP,this.startCamera.eye,this.tmpDir),p.subtract(this.tmpN,this.startCamera.eye,this.startCamera.center),p.normalize(this.tmpN,this.tmpN),this.tmpN[1]<0&&p.negate(this.tmpN,this.tmpN),C.fromPositionAndNormal(this.tmpP,this.tmpN,this.plane),this.constraintOptions.interactionStartCamera=this.startCamera},a.update=function(t){if(!this.active)return;v.intersectPlaneFromScreenPoint(this.plane,this.currentCamera,this.dragBeginPoint,this.tmpPoi)||p.copy(this.tmpPoi,this.currentCamera.center),v.normalizeCoordinate(this.currentCamera,t,this.tmpP0);let e=4*(this.tmpP0[1]-this.normalizedAnchorPoint[1]);m.copy(this.normalizedAnchorPoint,this.tmpP0),p.subtract(this.tmpRayDir,this.tmpPoi,this.currentCamera.eye);const i=p.length(this.tmpRayDir);let r=i*(1-e);p.copy(this.constraintOptions.interactionDirection,this.tmpRayDir),p.scale(this.constraintOptions.interactionDirection,this.constraintOptions.interactionDirection,Math.sign(e)/i);const n=this.view.state.constraints.minimumPoiDistance;e>=0&&r<n&&(r=n,e=-(r-i)/i),Math.abs(i-r)<1e-6||(p.scale(this.tmpRayDir,this.tmpRayDir,e),this.currentCamera.eye=p.add(g,this.currentCamera.eye,this.tmpRayDir),p.lerp(g,this.currentCamera.center,this.tmpPoi,e),this.tmpPoi[2]>this.startCamera.center[2]?g[2]=Math.max(this.startCamera.center[2],g[2]):g[2]=Math.min(this.startCamera.center[2],g[2]),this.currentCamera.center=g,this.constraintOptions.interactionFactor=P.pixelDistanceToInteractionFactor(this.dragBeginPoint,t),P.applyAll(this.view,this.currentCamera,this.constraintOptions))},a.end=function(){this.active&&this.finishController()},e._createClass(i,[{key:"intersectionHelper",get:function(){return this.view.sceneIntersectionHelper}}]),i}(d.InteractiveController),i.__decorate([a.property({constructOnly:!0})],t.ZoomController.prototype,"view",void 0),t.ZoomController=i.__decorate([h.subclass("esri.views.3d.state.controllers.local.ZoomController")],t.ZoomController);const g=u.create(),A={exclude:new Set([D.TERRAIN_ID])};Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
