/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{set as e,length as t,scale as i}from"../../core/libs/gl-matrix-2/math/vec3.js";import{create as s}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{FilteredFiniteDifference as r}from"./FilteredFiniteDifference.js";import{Momentum as n}from"./Momentum.js";class l extends n{constructor(e,t,i,s,r){super(e,t,i),this._sceneVelocity=s,this.direction=r}value(e){return super.valueFromInitialVelocity(this._sceneVelocity,e)}}class c{constructor(e=300,t=12,i=.84){this._minimumInitialVelocity=e,this._stopVelocity=t,this._friction=i,this.enabled=!0,this._time=new r(.6),this._screen=[new r(.4),new r(.4)],this._scene=[new r(.6),new r(.6),new r(.6)],this._tmpDirection=s()}add(e,t,i){if(this.enabled){if(this._time.hasLastValue()){if(this._time.computeDelta(i)<.015)return}this._screen[0].update(e[0]),this._screen[1].update(e[1]),this._scene[0].update(t[0]),this._scene[1].update(t[1]),this._scene[2].update(t[2]),this._time.update(i)}}reset(){this._screen[0].reset(),this._screen[1].reset(),this._scene[0].reset(),this._scene[1].reset(),this._scene[2].reset(),this._time.reset()}evaluateMomentum(){if(!this.enabled||!this._screen[0].hasFilteredDelta()||!this._time.hasFilteredDelta())return null;const e=this._screen[0].filteredDelta,t=this._screen[1].filteredDelta,i=null==e||null==t?0:Math.sqrt(e*e+t*t),s=this._time.filteredDelta,r=null==s||null==i?0:i/s;return Math.abs(r)<this._minimumInitialVelocity?null:this.createMomentum(r,this._stopVelocity,this._friction)}createMomentum(s,r,n){e(this._tmpDirection,this._scene[0].filteredDelta??0,this._scene[1].filteredDelta??0,this._scene[2].filteredDelta??0);const c=t(this._tmpDirection);c>0&&i(this._tmpDirection,this._tmpDirection,1/c);const h=this._time.filteredDelta;return new l(s,r,n,null==h?0:c/h,this._tmpDirection)}}export{l as PanPlanarMomentum,c as PanPlanarMomentumEstimator};
