From 6297bd86f77c699e8e0d1b4a2cf495e9c9ba8bb2 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Wed, 15 Apr 2009 01:51:10 -0400 Subject: [PATCH] Bug 488418: Simplify kinetic averaging code, r=stuart --- mobile/chrome/content/InputHandler.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/mobile/chrome/content/InputHandler.js b/mobile/chrome/content/InputHandler.js index 1509d14fd71b..cee7cd7668c3 100644 --- a/mobile/chrome/content/InputHandler.js +++ b/mobile/chrome/content/InputHandler.js @@ -524,30 +524,23 @@ KineticData.prototype = { if (mblen < 2) return false; - let speedBufX = []; - let speedBufY = []; + let tempX = 0; + let tempY = 0; // build arrays of each movement's speed in pixels/ms let prev = mb[0]; for (let i = 1; i < mblen; i++) { let me = mb[i]; - let speedX = (me.sx - prev.sx) / (me.t - prev.t); - speedBufX.push(speedX); - - let speedY = (me.sy - prev.sy) / (me.t - prev.t); - speedBufY.push(speedY); + tempX += (me.sx - prev.sx) / (me.t - prev.t); + tempY += (me.sy - prev.sy) / (me.t - prev.t); prev = me; } - function average(buf) { - return buf.reduce(function(a,b) a+b) / buf.length; - } - - // average the speeds out (This could probably be a bit smarter) - this._speedX = average(speedBufX); - this._speedY = average(speedBufY); + // average the speeds out (this could probably be a bit smarter) + this.speedX = tempX / mblen; + this.speedY = tempY / mblen; // fire off our kinetic timer which will do all the work this._startKineticTimer();