Tested new way to compute interaction delta.

This commit is contained in:
2019-07-24 08:54:09 +02:00
parent ef4267e926
commit cc6ef8de46
3 changed files with 243 additions and 2 deletions
+75 -1
View File
@@ -5350,6 +5350,78 @@
* @memberof InteractionPoints
*/
delta() {
let prev = [];
let curr = [];
let cm = { x: 0, y: 0};
let pm = { x: 0, y: 0};
let count = 0;
for(let key of this.current.keys()) {
if (this.previous.has(key)) {
let p = this.previous.get(key);
let c = this.current.get(key);
pm = Points.add(pm, p);
cm = Points.add(cm, c);
prev.push(p);
curr.push(c);
count += 1;
}
}
if (count > 0) {
pm = Points.multiplyScalar(pm, 1 / count);
cm = Points.multiplyScalar(cm, 1 / count);
let delta = Points.subtract(cm, pm);
let scale = 0;
let scaled = 0;
let alpha = 0;
let zoom = 1;
for(let i=0; i<count; i++) {
let p = prev[i];
let c = curr[i];
let previousAngle = Points.angle(p, pm);
let currentAngle = Points.angle(c, cm);
let diff = this.diffAngle(currentAngle, previousAngle);
alpha += diff;
let distance1 = Points.distance(p, pm);
let distance2 = Points.distance(c, cm);
if (distance1 != 0 && distance2 != 0) {
scale += distance2 / distance1;
scaled += 1;
}
}
if (scaled > 0) {
zoom = scale / scaled;
}
alpha /= count;
let current = this.current.farthests();
let c1 = current[0];
let c2 = current[1];
let distance2 = Points.distance(c1, c2);
return new InteractionDelta(
delta.x,
delta.y,
zoom,
alpha,
cm,
count,
distance2
)
}
else {
return null
}
}
/**
* Computes the delta between interaction points at t and t+1.
*
* @returns InteractionDelta
* @memberof InteractionPoints
*/
deltaByTwoFarthestsPoints() {
let csize = this.current.size;
let psize = this.previous.size;
if (csize >= 2 && csize == psize) {
@@ -6893,7 +6965,9 @@
if (delta.distance < this.minInteractionDistance) {
let ratio = delta.distance / this.minInteractionDistance;
rotate *= ratio;
zoom *= ratio;
let zoomDelta = zoom - 1;
zoomDelta *= ratio;
zoom = 1 + zoomDelta;
}
this.transform(delta, zoom, rotate, delta.about);