mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-12 15:02:11 +00:00
Bug 488418: Simplify kinetic averaging code, r=stuart
This commit is contained in:
parent
b3b7762080
commit
6297bd86f7
@ -524,30 +524,23 @@ KineticData.prototype = {
|
|||||||
if (mblen < 2)
|
if (mblen < 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
let speedBufX = [];
|
let tempX = 0;
|
||||||
let speedBufY = [];
|
let tempY = 0;
|
||||||
|
|
||||||
// build arrays of each movement's speed in pixels/ms
|
// build arrays of each movement's speed in pixels/ms
|
||||||
let prev = mb[0];
|
let prev = mb[0];
|
||||||
for (let i = 1; i < mblen; i++) {
|
for (let i = 1; i < mblen; i++) {
|
||||||
let me = mb[i];
|
let me = mb[i];
|
||||||
|
|
||||||
let speedX = (me.sx - prev.sx) / (me.t - prev.t);
|
tempX += (me.sx - prev.sx) / (me.t - prev.t);
|
||||||
speedBufX.push(speedX);
|
tempY += (me.sy - prev.sy) / (me.t - prev.t);
|
||||||
|
|
||||||
let speedY = (me.sy - prev.sy) / (me.t - prev.t);
|
|
||||||
speedBufY.push(speedY);
|
|
||||||
|
|
||||||
prev = me;
|
prev = me;
|
||||||
}
|
}
|
||||||
|
|
||||||
function average(buf) {
|
// average the speeds out (this could probably be a bit smarter)
|
||||||
return buf.reduce(function(a,b) a+b) / buf.length;
|
this.speedX = tempX / mblen;
|
||||||
}
|
this.speedY = tempY / mblen;
|
||||||
|
|
||||||
// average the speeds out (This could probably be a bit smarter)
|
|
||||||
this._speedX = average(speedBufX);
|
|
||||||
this._speedY = average(speedBufY);
|
|
||||||
|
|
||||||
// fire off our kinetic timer which will do all the work
|
// fire off our kinetic timer which will do all the work
|
||||||
this._startKineticTimer();
|
this._startKineticTimer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user