Skip to content

Commit 97cd758

Browse files
committed
(#85) Updated linear movementtype to return nanoseconds
Nanoseconds instead of milliseconds allow for higher resolution
1 parent c0282de commit 97cd758

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Diff for: lib/movementtype.function.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
export const linear = (
2-
amountOfSteps: number,
3-
speedInPixelsPerSecond: number,
2+
amountOfSteps: number,
3+
speedInPixelsPerSecond: number,
44
): number[] => {
5-
const timeSteps = [];
6-
let stepDuration = Math.floor((1 / speedInPixelsPerSecond) * 1000);
7-
if (stepDuration <= 0) {
8-
stepDuration = 1;
9-
}
10-
for (let idx = 0; idx < amountOfSteps; ++idx) {
11-
timeSteps.push(stepDuration);
12-
}
13-
return timeSteps;
5+
const timeSteps = [];
6+
// Duration per movement step in nanoseconds
7+
let stepDuration = (1 / speedInPixelsPerSecond) * 1_000_000_000;
8+
if (stepDuration <= 0) {
9+
stepDuration = 0;
10+
}
11+
for (let idx = 0; idx < amountOfSteps; ++idx) {
12+
timeSteps.push(stepDuration);
13+
}
14+
return timeSteps;
1415
};

0 commit comments

Comments
 (0)