-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add MovementEvent type and movement computation function
Introduced the MovementEvent type to encapsulate all relevant data for a movement event, including direction, velocity, and distance in the swiperia-core package. Implemented a function to compute these properties based on start and end points and duration, enabling detailed tracking of movement characteristics in swipe gestures.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/swiperia-core/src/lib/movement/MovementEvent.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Direction } from '../direction/Direction.type'; | ||
import type { Point } from '../point/Point.type'; | ||
import type { Velocity } from '../velocity/Velocity.type'; | ||
|
||
export interface MovementEvent { | ||
/** | ||
* | ||
*/ | ||
direction: Direction | null; | ||
source: Point; | ||
target: Point; | ||
deltaX: number; | ||
deltaY: number; | ||
/** | ||
* absolute deltaX | ||
*/ | ||
absX: number; | ||
/** | ||
* absolute deltaY | ||
*/ | ||
absY: number; | ||
/** | ||
* √(absX^2 + absY^2) / time - "absolute velocity" (speed) | ||
*/ | ||
velocity: number; | ||
/** | ||
* deltaX/time, deltaY/time] - velocity per axis | ||
*/ | ||
vxvy: Velocity; | ||
/** | ||
* distance traveled | ||
*/ | ||
distance: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { movement } from './movement'; | ||
export type { MovementEvent } from './MovementEvent.type'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { MovementEvent } from './MovementEvent.type'; | ||
import type { Point } from '../point/Point.type'; | ||
|
||
import { direction } from '../direction/direction'; | ||
import { distance } from '../point/distance'; | ||
import { velocity, vxvy } from '../velocity/velocity'; | ||
|
||
export const movement = ( | ||
source: Point, | ||
target: Point, | ||
duration: number | ||
): MovementEvent => { | ||
const deltaX = target[0] - source[0]; | ||
const deltaY = target[1] - source[1]; | ||
const absX = Math.abs(deltaX); | ||
const absY = Math.abs(deltaY); | ||
return { | ||
source, | ||
target, | ||
deltaX, | ||
deltaY, | ||
absX, | ||
absY, | ||
direction: direction(source, target), | ||
velocity: velocity(source, target, duration), | ||
vxvy: vxvy(source, target, duration), | ||
distance: distance(source, target), | ||
}; | ||
}; |