From 3db32964f008bfa0e2c2081340de7f9556ba3ee9 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Tue, 12 May 2015 12:11:54 +0200 Subject: [PATCH] caches balls by radii --- lib/torque/renderer/ball.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/torque/renderer/ball.js b/lib/torque/renderer/ball.js index 8d0ae25..746d1a7 100644 --- a/lib/torque/renderer/ball.js +++ b/lib/torque/renderer/ball.js @@ -4,24 +4,23 @@ // developed by Francisco Dans //////////////////////////////// -var work = require('webworkify'); - function BallRenderer(thecanvas){ this.canvas = thecanvas; this.ctx = this.canvas.getContext("2d"); this.width = this.canvas.width; + this.chWidth = this.canvas.width * 4; this.height = this.canvas.height; this.size = this.width * this.height; this.pointLayer = new Uint8ClampedArray(this.size * 4); - this.radius = 15; this.drawnTemp = {}; this.prof = 0; this.gradient = {}; this.ballsSoFar = 0; this.balls = 0; this.cumulative = true; - this.RW4 = this.radius * this.width *4; this.availableWorkers = 10; + this.mode = "heat"; + this.cachedBalls = []; } BallRenderer.prototype = { getBallIndices: function(x, y){ @@ -29,8 +28,10 @@ BallRenderer.prototype = { return indices; }, - addBall: function(x0, y0){ - if(this.cachedBall){ + addBall: function(x0, y0, st){ + this.radius = st["marker-width"]; + this.RW4 = this.radius * this.width *4; + if(this.cachedBalls[this.radius]){ var startingPoint = this.getRIndexPos(x0, y0) - this.RW4 - this.radius*4; var i = 0, pointer = startingPoint, @@ -39,7 +40,7 @@ BallRenderer.prototype = { endPoint = this.getRIndexPos(x0, y0) + this.RW4 + this.radius; while (pointer <= endPoint){ while (pointer <= linemax){ - this.pointLayer[pointer+3] += this.cachedBall[i+3]; + this.pointLayer[pointer+3] += this.cachedBalls[this.radius][i+3]; i+=4; pointer+=4; } @@ -52,7 +53,7 @@ BallRenderer.prototype = { } }, precacheBall: function(x0, y0){ - this.cachedBall = new Uint8ClampedArray(Math.pow(2 * this.radius + 1, 2)*4); + this.cachedBalls[this.radius] = new Uint8ClampedArray(Math.pow(2 * this.radius + 1, 2)*4); x0 = this.radius; y0 = this.radius; var orad = this.radius; @@ -89,7 +90,7 @@ BallRenderer.prototype = { }, addPoint: function(x, y, alpha){ var indexPos = (y*(this.radius*2+1)+x)*4; - this.cachedBall[indexPos + 3] += alpha; + this.cachedBalls[this.radius][indexPos + 3] += alpha; }, map_range: function(value, low1, high1, low2, high2) { return low2 + (high2 - low2) * (value - low1) / (high1 - low1);