From eff934e8b593381d3adc0b6d68e73a3586290ad4 Mon Sep 17 00:00:00 2001 From: Uwe Oestermeier Date: Wed, 28 Apr 2021 17:02:54 +0200 Subject: [PATCH] Moved the addVelocity method after the transform to allow a modification of the delta within the transform method. To make this destructive side effect more explicit transform could return a modified value. But that could effect several projects. --- lib/scatter.js | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/scatter.js b/lib/scatter.js index d9ae104..9e1e91f 100644 --- a/lib/scatter.js +++ b/lib/scatter.js @@ -44,8 +44,7 @@ const END = 'onEnd' */ export class ScatterEvent extends BaseEvent { constructor( - target, - { translate = { x: 0, y: 0 }, scale = null, rotate = 0, about = null, fast = false, type = null } = {} + target, { translate = { x: 0, y: 0 }, scale = null, rotate = 0, about = null, fast = false, type = null } = {} ) { super('scatterTransformed', { target: target }) this.translate = translate @@ -106,7 +105,7 @@ class Throwable { this.velocity = null this.timestamp = null this.onThrowFinished = onThrowFinished - //console.log("onThrowFinished", onThrowFinished) + //console.log("onThrowFinished", onThrowFinished) } observeVelocity() { @@ -184,7 +183,7 @@ class Throwable { animateThrow(time) { if (this.velocity != null) { let dt = this._throwDeltaTime() - // console.log("animateThrow", dt) + // console.log("animateThrow", dt) let next = this.nextVelocity(this.velocity) let prevLength = Points.length(this.velocity) let nextLength = Points.length(next) @@ -382,7 +381,7 @@ export class AbstractScatter extends Throwable { let delta = interaction.delta() if (delta != null) { - this.addVelocity(delta) // uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855 + let rotate = delta.rotate let zoom = delta.zoom if (this.maxRotation != null) { @@ -403,6 +402,8 @@ export class AbstractScatter extends Throwable { } this.transform(delta, zoom, rotate, delta.about) + this.addVelocity(delta) // uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855 + if (zoom != 1) this.interactionAnchor = delta.about } } @@ -467,8 +468,8 @@ export class AbstractScatter extends Throwable { keepOnStage(velocity, collision = 0.5) { let stagePolygon = this.containerPolygon - // UO: since keepOnStage is called in nextVelocity we need to - // ensure a return value + // UO: since keepOnStage is called in nextVelocity we need to + // ensure a return value if (!stagePolygon) return { x: 0, y: 0 } let polygon = this.polygon let bounced = this.bouncing() @@ -479,7 +480,7 @@ export class AbstractScatter extends Throwable { let dx = this.movableX ? velocity.x : 0 let dy = this.movableY ? velocity.y : 0 let factor = this.throwDamping - // if (recentered) { + // if (recentered) { if (x < 0) { dx = -dx factor = collision @@ -515,10 +516,10 @@ export class AbstractScatter extends Throwable { onComplete: this.close.bind(this) }) } else if (this.scale < this.minScale + this.scaleCloseThreshold) { - this.zoom(this.minScale + this.scaleCloseThreshold, { - animate: 0.4 - }) - } + this.zoom(this.minScale + this.scaleCloseThreshold, { + animate: 0.4 + }) + } } rotateDegrees(degrees, anchor) { @@ -621,7 +622,7 @@ export class AbstractScatter extends Throwable { let newOrigin = Points.arc(anchor, beta + rotate, distance * thresholdedZoom) let extra = Points.subtract(newOrigin, origin) const anchorOffset = Points.subtract(anchor, origin) - // this._move(offset) + // this._move(offset) this.scale = newScale this.rotation += rotate let offset = Points.negate(anchorOffset) @@ -911,8 +912,7 @@ export class DOMScatterContainer { * @param {DOM node} debugCanvas - Shows debug infos about touches if not null */ constructor( - element, - { + element, { stopEvents = 'auto', claimEvents = true, useCapture = true, @@ -1076,8 +1076,7 @@ export class DOMScatterContainer { export class DOMScatter extends AbstractScatter { constructor( element, - container, - { + container, { startScale = 1.0, minScale = 0.1, maxScale = 1.0, @@ -1274,10 +1273,10 @@ export class DOMScatter extends AbstractScatter { let r = this.bounds let w2 = r.width / 2 let h2 = r.height / 2 - // if (this.resizable) { - // w2 *= this.scale - // h2 *= this.scale - // } + // if (this.resizable) { + // w2 *= this.scale + // h2 *= this.scale + // } var x = r.left + w2 var y = r.top + h2 return { x, y } @@ -1397,7 +1396,7 @@ export class DOMScatter extends AbstractScatter { } this._x = x this._y = y - // this.addVelocity({ x: delta.x, y: delta.y }) uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855 + // this.addVelocity({ x: delta.x, y: delta.y }) uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855 TweenLite.set(this.element, { x, y }) } @@ -1504,4 +1503,4 @@ export class DOMScatter extends AbstractScatter { } } -DOMScatter.zIndex = 1000 +DOMScatter.zIndex = 1000 \ No newline at end of file