From fa0256d782dd498c6d3e51321260ca375ca9f855 Mon Sep 17 00:00:00 2001 From: Ukmasmu Date: Tue, 5 Jan 2021 16:25:55 +0100 Subject: [PATCH] Moved addVelocity to _move. --- lib/interaction.js | 4 ++-- lib/scatter.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/interaction.js b/lib/interaction.js index 830af1e..8bc67a5 100755 --- a/lib/interaction.js +++ b/lib/interaction.js @@ -849,8 +849,8 @@ export class InteractionDelegate { if (Events.isCaptured(event)) { return false } - let captured = this.target.capture(event) - return captured + + return this.target.capture ? this.target.capture(event) : false } getPosition(event) { diff --git a/lib/scatter.js b/lib/scatter.js index ac38aa5..c6def64 100644 --- a/lib/scatter.js +++ b/lib/scatter.js @@ -117,6 +117,9 @@ class Throwable { let t = performance.now() let dt = t - this.lastframe this.lastframe = t + + // When number is not set or is zero. Use one instead. + let number = delta.number ? delta.number : 1 if (dt > 0) { // Avoid division by zero errors later on // and consider the number of involved pointers sind addVelocity will be called by the @@ -124,13 +127,14 @@ class Throwable { let velocity = { t: t, dt: dt, - dx: delta.x / delta.number, - dy: delta.y / delta.number + dx: delta.x / number, + dy: delta.y / number } this.velocities.push(velocity) while (this.velocities.length > buffer) { this.velocities.shift() } + } } @@ -378,7 +382,6 @@ export class AbstractScatter extends Throwable { let delta = interaction.delta() if (delta != null) { - this.addVelocity(delta) let rotate = delta.rotate let zoom = delta.zoom if (this.maxRotation != null) { @@ -578,6 +581,7 @@ export class AbstractScatter extends Throwable { } _move(delta) { + this.addVelocity(delta) this.x += this.movableX ? delta.x : 0 this.y += this.movableX ? delta.y : 0 } @@ -1392,7 +1396,8 @@ export class DOMScatter extends AbstractScatter { } this._x = x this._y = y - TweenLite.set(this.element, { x: x, y: y }) + this.addVelocity({ x: delta.x, y: delta.y }) + TweenLite.set(this.element, { x, y }) } resizeAfterTransform(zoom) {