From d048652ba947bab30b4643474c562bc3081c8436 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Wed, 25 Feb 2015 12:45:45 +0100 Subject: [PATCH] optimizes drawnTemp a bit more --- lib/torque/renderer/ball.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/torque/renderer/ball.js b/lib/torque/renderer/ball.js index 8c6d739..a46846b 100644 --- a/lib/torque/renderer/ball.js +++ b/lib/torque/renderer/ball.js @@ -12,7 +12,7 @@ function BallRenderer(thecanvas){ this.size = this.width * this.height; this.pointLayer = new Uint8ClampedArray(this.size * 4); this.radius = 30; - this.drawnTemp = []; + this.drawnTemp = {}; this.prof = 0; this.gradient = {}; } @@ -51,19 +51,18 @@ BallRenderer.prototype = { return Math.sqrt( xs + ys ); } // Assumes xi is on the left and xf is on the right - var xPointer = xi; if(typeof this.drawnTemp[yi] === "undefined"){ - while (xPointer <= xf){ - var alpha = this.map_range(lineDistance(xPointer, yi), 0, this.radius, 30, 0); - this.addPoint(xPointer, yi, alpha); - xPointer ++; + while (xi <= xf){ + var alpha = this.map_range(lineDistance(xi, yi), 0, this.radius, 30, 0); + this.addPoint(xi, yi, alpha); + xi ++; } this.drawnTemp[yi]=true; } }, contour: function(granularity){ var step = 255/granularity; - var i = 0, a = new Uint8ClampedArray(granularity+1), c=0; + var i = 1, a = new Uint8ClampedArray(granularity+1), c=0; while (i<255){ a[c] = i; i += step;