import Recognizer from './Recognizer' ; import { calculateAllKinematics , sign , subV } from '../utils/math' ; import { Vector2 , PartialGestureState , DistanceAngleKey , GestureState } from '../types' ; private export default abstract class DistanceAngleRecognizer < T extends DistanceAngleKey > extends Recognizer < T > { protected getInternalMovement ( values , state ) { const prev_a = state . values [ 1 ] ; let [ d , a = prev_a ] = values ; let delta_a = a - prev_a ; let next_turns = state . turns ; if ( Math . abs ( delta_a ) > 270 ) next_turns += sign ( delta_a ) ; return subV ( [ d , a - 360 * next_turns ] , state . initial ) ; } getKinematics ( values , event ) { const state = this . getMovement ( values ) ; const turns = ( values [ 1 ] - state . movement ! [ 1 ] - this . state . initial [ 1 ] ) / 360 ; const dt = event . timeStamp - this . state . timeStamp ! ; const kinematics = calculateAllKinematics ( state . movement ! , state . delta ! , dt ) ; return { turns , ... state , ... kinematics } ; } protected mapStateValues ( state ) { return { da : state . values , vdva : state . velocities } as Omit < PartialGestureState < T > , 'event' > ; } } param dangle export function fixContinuity ( dangle ) { dangle -= Math . round ( dangle / 360 ) * 360 ; if ( dangle > 270 ) return dangle - 360 ; if ( dangle < - 270 ) return dangle + 360 ; return dangle ; }