/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t}from"tslib";import{clamp as i}from"../../../../core/mathUtils.js";import{createScreenPointArray as r}from"../../../../core/screenUtils.js";import{subclass as s}from"../../../../core/accessorSupport/decorators.js";import{copy as e,distance as n}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{subtract as o,length as m,normalize as h,scale as c,add as p,negate as _,copy as l,lerp as P}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as u,fromValues as C}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as f,fromPositionAndNormal as g}from"../../../../geometry/support/plane.js";import{pixelDistanceToInteractionFactor as D,applyAll as v}from"../../camera/constraintUtils.js";import{ConstraintOptions as y}from"../../camera/constraintUtils/ConstraintOptions.js";import{getVoxelWasm as d}from"../../layers/VoxelWasm.js";import{InteractiveController as j}from"./InteractiveController.js";import{normalizeCoordinate as b,excludeTerrain as w,zoomPivotDistanceClamp as x,getTiltScaleFactor as N,maxZoomPivotDistanceModifier as O,pivotSearchAreaSize as M,intersectPlaneFromScreenPoint as R,distanceComparisonTolerance as z}from"../utils/navigationUtils.js";let A=class extends j{constructor(){super(...arguments),this._tmpP=u(),this._tmpDir=u(),this._tmpN=u(),this._tmpP0=a(),this._tmpPoi=u(),this._tmpRayDir=u(),this.dragBeginPoint=r(),this._normalizedAnchorPoint=a(),this._constraintOptions=new y(15,1,0,this.startCamera,u()),this._plane=f()}get _intersectionHelper(){return this.view.sceneIntersectionHelper}begin(t){if(!this.running)return;e(this.dragBeginPoint,t),b(this.startCamera,t,this._normalizedAnchorPoint);const r=this._intersectionHelper.intersectScreenFreePointFallback(t,this._tmpP,this.view.basemapTerrain.invisible?w:{});o(this._tmpDir,this._tmpP,this.startCamera.eye);const s=m(this._tmpDir);h(this._tmpDir,this._tmpDir);const n=Math.abs(this.view.camera.position.z),a=i(N(B,this._tmpDir,O)*n,x[0],x[1]),l=this.view.stage.renderView.getMinimalDepthForArea(d(this.view),t[0],t[1],this.view.state.camera,M);let P=null!=l?l:a;r&&(P=Math.min(P,s)),c(this._tmpDir,this._tmpDir,P),p(this._tmpP,this.startCamera.eye,this._tmpDir),o(this._tmpN,this.startCamera.eye,this.startCamera.center),h(this._tmpN,this._tmpN),this._tmpN[1]<0&&_(this._tmpN,this._tmpN),g(this._tmpP,this._tmpN,this._plane)}update(t){if(!this.running)return;R(this._plane,this.currentCamera,this.dragBeginPoint,this._tmpPoi)||l(this._tmpPoi,this.currentCamera.center),b(this.currentCamera,t,this._tmpP0);let i=4*(this._tmpP0[1]-this._normalizedAnchorPoint[1]);e(this._normalizedAnchorPoint,this._tmpP0),o(this._tmpRayDir,this._tmpPoi,this.currentCamera.eye);const r=m(this._tmpRayDir);let s=r*(1-i);this._constraintOptions.interactionDirection&&(l(this._constraintOptions.interactionDirection,this._tmpRayDir),c(this._constraintOptions.interactionDirection,this._constraintOptions.interactionDirection,Math.sign(i)/r));const a=this.view.state.constraints.minimumPoiDistance;i>=0&&s<a&&(s=a,i=-(s-r)/r),Math.abs(r-s)<z||(c(this._tmpRayDir,this._tmpRayDir,i),this.currentCamera.eye=p(U,this.currentCamera.eye,this._tmpRayDir),P(U,this.currentCamera.center,this._tmpPoi,i),this._tmpPoi[2]>this.startCamera.center[2]?U[2]=Math.max(this.startCamera.center[2],U[2]):U[2]=Math.min(this.startCamera.center[2],U[2]),this.currentCamera.center=U,this._constraintOptions.interactionFactor=D(n(this.dragBeginPoint,t)),v(this.view,this.currentCamera,this._constraintOptions),this.commitCamera())}finish(){this.running&&this.finishController()}};A=t([s("esri.views.3d.state.controllers.ZoomControllerLocal")],A);const U=u(),B=C(0,0,1);export{A as ZoomControllerLocal};
