Skip to content

Commit d381de4

Browse files
committed
Fix reported speed and duration during inertia
1 parent 4afb8a4 commit d381de4

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

interact.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@
30213021
this.velocityY = 0;
30223022
}
30233023
else if (phase === 'inertiastart') {
3024-
this.timeStamp = new Date().getTime();
3024+
this.timeStamp = interaction.prevEvent.timeStamp;
30253025
this.dt = interaction.prevEvent.dt;
30263026
this.duration = interaction.prevEvent.duration;
30273027
this.speed = interaction.prevEvent.speed;
@@ -3033,47 +3033,18 @@
30333033
this.dt = this.timeStamp - interaction.prevEvent.timeStamp;
30343034
this.duration = this.timeStamp - interaction.downTime;
30353035

3036-
var dx, dy, dt;
3037-
3038-
// Use natural event coordinates (without snapping/restricions)
3039-
// subtract modifications from previous event if event given is
3040-
// not a native event
30413036
if (event instanceof InteractEvent) {
3042-
// change in time in seconds
3043-
// use event sequence duration for end events
3044-
// => average speed of the event sequence
3045-
// (minimum dt of 1ms)
3046-
dt = Math.max((ending? this.duration: this.dt) / 1000, 0.001);
3047-
dx = this[sourceX] - interaction.prevEvent[sourceX];
3048-
dy = this[sourceY] - interaction.prevEvent[sourceY];
3049-
3050-
if (this.snap && this.snap.locked) {
3051-
dx -= this.snap.dx;
3052-
dy -= this.snap.dy;
3053-
}
3037+
var dx = this[sourceX] - interaction.prevEvent[sourceX],
3038+
dy = this[sourceY] - interaction.prevEvent[sourceY],
3039+
dt = this.dt / 1000;
30543040

3055-
if (this.restrict) {
3056-
dx -= this.restrict.dx;
3057-
dy -= this.restrict.dy;
3058-
}
3059-
3060-
if (interaction.prevEvent.snap && interaction.prevEvent.snap.locked) {
3061-
dx -= (interaction.prevEvent[sourceX] - interaction.prevEvent.snap.dx);
3062-
dy -= (interaction.prevEvent[sourceY] - interaction.prevEvent.snap.dy);
3063-
}
3064-
3065-
if (interaction.prevEvent.restrict) {
3066-
dx += interaction.prevEvent.restrict.dx;
3067-
dy += interaction.prevEvent.restrict.dy;
3068-
}
3069-
3070-
// speed and velocity in pixels per second
30713041
this.speed = hypot(dx, dy) / dt;
30723042
this.velocityX = dx / dt;
30733043
this.velocityY = dy / dt;
30743044
}
3075-
// if normal move event, use previous user event coords
3045+
// if normal move or end event, use previous user event coords
30763046
else {
3047+
// speed and velocity in pixels per second
30773048
this.speed = interaction.pointerDelta[deltaSource].speed;
30783049
this.velocityX = interaction.pointerDelta[deltaSource].vx;
30793050
this.velocityY = interaction.pointerDelta[deltaSource].vy;

0 commit comments

Comments
 (0)