/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{create as t}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{squaredLength as e,normalize as i,copy as s}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as l}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{rotationAngleAndAxisDirectRotation as a,rotationAnglesAndAxesHeadingPreserving as n}from"../3d/state/utils/navigationUtils.js";import{FilteredFiniteDifference as r}from"./FilteredFiniteDifference.js";import{FilteredValue as h}from"./FilteredValue.js";import{Momentum as _}from"./Momentum.js";const m=1e-5;class u extends _{constructor(t,e,i,s,l,a=0,n){super(t,e,i),this._angularVelocity1=s,this.axis1=l,this.angularVelocity2=a,this.axis2=n}value1(t){return super.valueFromInitialVelocity(this._angularVelocity1,t)}value2(t){return super.valueFromInitialVelocity(this.angularVelocity2,t)}}class o{constructor(e=300,i=12,s=.84){this._minimumInitialVelocity=e,this._stopVelocity=i,this._friction=s,this.enabled=!0,this._tmpAxis1=l(),this._tmpAxis2=l(),this._tmpAngles=t(),this._time=new r(.3),this._screen=[new r(.4),new r(.4)],this._angle1=new h(.6),this._angle2=new h(.6),this._axis1=l(),this._axis2=l(),this._lastScene=l()}addMomentumDirectRotation(t,l,n,r,h,_){if(this.enabled){if(this._time.hasLastValue()){if(this._time.computeDelta(n)<.01)return;let t=a(this._lastScene,l,this._tmpAxis2,r,h,_);this._angle2.update(0),e(this._tmpAxis2)<m?t=0:i(this._axis1,this._tmpAxis2),this._angle1.update(t),s(this._lastScene,l)}this._screen[0].update(t[0]),this._screen[1].update(t[1]),this._time.update(n)}}addMomentumPreserveHeading(t,l,a,r,h,_,u){if(this.enabled){if(this._time.hasLastValue()){if(this._time.computeDelta(a)<.01)return;n(this._lastScene,l,this._tmpAxis2,this._tmpAxis1,this._tmpAngles,r,h,_,u,!1),e(this._tmpAxis2)<m?(this._angle1.update(0),this._angle2.update(0)):(this._angle1.update(this._tmpAngles[1]),this._angle2.update(this._tmpAngles[0]),i(this._axis1,this._tmpAxis1),i(this._axis2,this._tmpAxis2)),s(this._lastScene,l)}this._screen[0].update(t[0]),this._screen[1].update(t[1]),this._time.update(a)}}reset(){this._screen[0].reset(),this._screen[1].reset(),this._angle1.reset(),this._angle2.reset(),this._time.reset()}evaluateMomentum(){if(!this.enabled||!this._screen[0].hasFilteredDelta())return null;const t=this._screen[0].filteredDelta,e=this._screen[1].filteredDelta,i=null==t||null==e?null:Math.sqrt(t*t+e*e),s=this._time.filteredDelta,l=null==i||null==s?0:i/s;return Math.abs(l)<this._minimumInitialVelocity?null:this.createMomentum(l,this._stopVelocity,this._friction)}createMomentum(t,e,i){const s=this._time.filteredDelta,l=this._angle1.filteredValue,a=this._angle2.filteredValue,n=null==s||null==a?0:a/s;return new u(t,e,i,null==s||null==l?0:l/s,this._axis1,n,this._axis2)}}export{u as PanSphericalMomentum,o as PanSphericalMomentumEstimator};
