From d0d3a7f13488de89f0cf4a28ffacc3c804d3fd6e Mon Sep 17 00:00:00 2001 From: Uwe Oestermeier Date: Fri, 31 May 2019 09:51:01 +0200 Subject: [PATCH] Fixed throwing problems with 2+ pointers --- lib/interaction.js | 17 ++++++++++++++--- lib/scatter.js | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/interaction.js b/lib/interaction.js index 1b2bf74..a63c6d9 100755 --- a/lib/interaction.js +++ b/lib/interaction.js @@ -122,12 +122,23 @@ export class PointMap extends MapProxy { } export class InteractionDelta { - constructor(x, y, zoom, rotate, about) { + /** + *Creates an instance of InteractionDelta. + * @param {*} x + * @param {*} y + * @param {*} zoom + * @param {*} rotate + * @param {*} about + * @param {*} number - number of involved pointer + * @memberof InteractionDelta + */ + constructor(x, y, zoom, rotate, about, number) { this.x = x this.y = y this.zoom = zoom this.rotate = rotate this.about = about + this.number = number } toString() { @@ -217,14 +228,14 @@ export class InteractionPoints { let currentAngle = Points.angle(c1, c2) let previousAngle = Points.angle(p1, p2) let alpha = this.diffAngle(currentAngle, previousAngle) - return new InteractionDelta(delta.x, delta.y, zoom, alpha, cm) + return new InteractionDelta(delta.x, delta.y, zoom, alpha, cm, csize) } else if (csize == 1 && psize == 1 && this.current.firstKey() == this.previous.firstKey()) { // We need to ensure that the keys are the same, since single points with different keys // can jump let current = this.current.first() let previous = this.previous.first() let delta = Points.subtract(current, previous) - return new InteractionDelta(delta.x, delta.y, 1.0, 0.0, current) + return new InteractionDelta(delta.x, delta.y, 1.0, 0.0, current, csize) } return null } diff --git a/lib/scatter.js b/lib/scatter.js index e08f31c..c575217 100644 --- a/lib/scatter.js +++ b/lib/scatter.js @@ -127,7 +127,9 @@ class Throwable { this.lastframe = t if (dt > 0) { // Avoid division by zero errors later on - let velocity = { t: t, dt: dt, dx: delta.x, dy: delta.y } + // and consider the number of involved pointers sind addVelocity will be called by the + // onMove events + let velocity = { t: t, dt: dt, dx: delta.x / delta.number, dy: delta.y / delta.number} this.velocities.push(velocity) while (this.velocities.length > buffer) { this.velocities.shift()