adds interpolation as an option

This commit is contained in:
Francisco Dans 2015-08-14 00:42:09 +02:00
parent 471cd3ec19
commit 43d85fd34d

View File

@ -199,24 +199,6 @@ var contour = require('./contour');
prof.end(true);
},
_gridData(tile){
var res = this.options.resolution;
var grid = new Array(256/res);
for(var i =0; i<grid.length; i ++){
grid[i] = new Array(256/res);
for(var j =0; j < grid[i].length; j++){
grid[i][j] = 0;
}
}
for(var i =0; i < tile.renderData.length; i++){
var x = tile.x[i], y = tile.y[i];
grid[y/res][x/res] = tile.renderData[i];
}
return grid;
},
_createCanvas: function() {
return this.options.canvasClass
? new this.options.canvasClass()
@ -331,6 +313,25 @@ var contour = require('./contour');
}
prof.end(true);
},
_gridData: function(tile){
var res = this.options.resolution;
var grid = new Array(256/res);
for(var i =0; i<grid.length; i ++){
grid[i] = new Array(256/res);
for(var j =0; j < grid[i].length; j++){
grid[i][j] = 0;
}
}
for(var i =0; i < tile.renderData.length; i++){
var x = tile.x[i], y = tile.y[i];
grid[y/res][x/res] = tile.renderData[i];
}
return grid.reverse(); // Torque tiles have an inverted y axis!
},
_getPipe: function(cell, contour){
var parsedCell = cell.map(function(cornerValue){
if (cornerValue >= contour){
@ -339,10 +340,11 @@ var contour = require('./contour');
return "0";
}).join("");
var type = parseInt(parsedCell, 2);
var N = [this._lerp(cell[1], cell[0], contour), 0],
S = [this._lerp(cell[2], cell[3], contour), 1],
E = [1, this._lerp(cell[2], cell[1], contour)],
W = [0, this._lerp(cell[3], cell[0], contour)]
var interpolated = true;
var N = interpolated?[this._lerp(cell[1], cell[0], contour), 0]: [0.5,0],
S = interpolated?[this._lerp(cell[2], cell[3], contour), 1]: [0.5,1],
E = interpolated?[1, this._lerp(cell[2], cell[1], contour)]: [1,0.5],
W = interpolated?[0, this._lerp(cell[3], cell[0], contour)]: [0,0.5]
// Blank
if (type === 0 || type === 15) return null;
// W - S