makes code clearer

This commit is contained in:
Francisco Dans 2015-08-19 10:52:14 +02:00
parent 2296a7e901
commit bbd8402281

View File

@ -496,33 +496,27 @@ var contour = require('./contour');
},
applyFilters: function(){
if(this.globalGrid.length > 0){
for (var i = 0, c = 0; i < this.globalGrid.length; i++){
if (this.globalGrid[i] && this.globalGrid[i].length > c){
c = this.globalGrid[i].length;
}
}
if (this.globalGrid.length > 0) {
var cellsY = this.globalGrid.length-1;
var contourValues = [0, 4, 8, 16];
var ctx = this._ctx;
var res = this.options.resolution;
var anchor = this.options.resolution/2;
ctx.strokeStyle = "white";
for(var c = 0; c < contourValues.length; c++){
for (var y = 0; y < cellsY; y++){
if(this.globalGrid[y]){
for (var c = 0; c < contourValues.length; c++) {
for (var y = 0; y < cellsY; y++) {
if (this.globalGrid[y]) {
for (var x = 0; x < this.globalGrid[y].length-1; x++){
var currentCell = [this.globalGrid[y][x], this.globalGrid[y][x+1], this.globalGrid[y+1][x+1], this.globalGrid[y+1][x]];
var pipe = this._getPipe(currentCell, contourValues[c]);
if (pipe){
ctx.beginPath();
ctx.moveTo(x * res + anchor + res * pipe[0][0], y * res + anchor + res * pipe[0][1]);
ctx.lineTo(x * res + anchor + res * pipe[1][0], y * res + anchor + res * pipe[1][1]);
ctx.moveTo(res(x + 0.5 + pipe[0][0]), res(y + 0.5 + pipe[0][1]));
ctx.lineTo(res(x + 0.5 + pipe[1][0]), res(y + 0.5 + pipe[1][1]));
ctx.stroke();
if (pipe.length === 4){
ctx.beginPath();
ctx.moveTo(x * res + anchor + res * pipe[2][0], y * res + anchor + res * pipe[2][1]);
ctx.lineTo(x * res + anchor + res * pipe[3][0], y * res + anchor + res * pipe[3][1]);
ctx.moveTo(res(x + 0.5 + pipe[2][0]), res(y + 0.5 + pipe[2][1]));
ctx.lineTo(res(x + 0.5 + pipe[3][0]), res(y + 0.5 + pipe[3][1]));
ctx.stroke();
}
}