Skip to content

Commit

Permalink
[twisty] Attempt to filter out events with the same timestamp, to avo…
Browse files Browse the repository at this point in the history
…id dividing by 0.

This may help with
https://www.speedsolving.com/threads/introducing-twizzle-alpha.85019/page-3#post-1451912
due to platform-specific timestamp quirks.
  • Loading branch information
lgarron committed Aug 22, 2021
1 parent 887f285 commit 2fdd01b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/cubing/twisty/views/3D/TwistyOrbitControlsV2.ts
Expand Up @@ -152,11 +152,13 @@ export class TwistyOrbitControlsV2 {
);
this.onMove(movementX, movementY);

this.lastMouseMoveMomentumX =
movementX / (e.timeStamp - this.lastMouseTimestamp);
this.lastMouseMoveMomentumY =
movementY / (e.timeStamp - this.lastMouseTimestamp);
this.lastMouseTimestamp = e.timeStamp;
if (e.timeStamp !== this.lastMouseTimestamp) {
this.lastMouseMoveMomentumX =
movementX / (e.timeStamp - this.lastMouseTimestamp);
this.lastMouseMoveMomentumY =
movementY / (e.timeStamp - this.lastMouseTimestamp);
this.lastMouseTimestamp = e.timeStamp;
}
}

onMouseEnd(e: MouseEvent): void {
Expand Down Expand Up @@ -211,11 +213,13 @@ export class TwistyOrbitControlsV2 {
this.lastTouchClientX = touch.clientX;
this.lastTouchClientY = touch.clientY;

this.lastTouchMoveMomentumX =
movementX / (e.timeStamp - this.lastTouchTimestamp);
this.lastTouchMoveMomentumY =
movementY / (e.timeStamp - this.lastTouchTimestamp);
this.lastTouchTimestamp = e.timeStamp;
if (e.timeStamp !== this.lastTouchTimestamp) {
this.lastTouchMoveMomentumX =
movementX / (e.timeStamp - this.lastTouchTimestamp);
this.lastTouchMoveMomentumY =
movementY / (e.timeStamp - this.lastTouchTimestamp);
this.lastTouchTimestamp = e.timeStamp;
}
}
}
}
Expand Down

0 comments on commit 2fdd01b

Please sign in to comment.