Fixed close casting leak

This commit is contained in:
Devine Lu Linvega 2018-02-06 16:47:25 +13:00
parent 3200f0818c
commit 905b34dd2b

View File

@ -28,7 +28,7 @@ function Tool()
this.cast = function(type) this.cast = function(type)
{ {
if(!this.layer()){ this.layers[this.index] = []; } if(!this.layer()){ this.layers[this.index] = []; }
if(!this.can_cast(type)){ console.log("Not enough verteces"); return; } if(!this.can_cast(type)){ console.warn("Cannot cast"); return; }
this.layer().push({type:type,verteces:this.verteces.slice()}) this.layer().push({type:type,verteces:this.verteces.slice()})
this.clear(); this.clear();
@ -39,18 +39,23 @@ function Tool()
} }
this.can_cast = function(type) this.can_cast = function(type)
{ {
// Cannot cast close twice
if(type == "close"){
var prev = this.layer()[this.layer().length-1];
if(prev.type == "close"){
return false;
}
}
return this.verteces.length >= this.reqs[type]; return this.verteces.length >= this.reqs[type];
} }
this.path = function() this.path = function()
{ {
var html = ""; var html = "";
for(id in this.layer()){ for(id in this.layer()){
var segment = this.layer()[id]; var segment = this.layer()[id];
console.log(segment) html += segment.type == "close" ? "Z " : this.render(segment);
html += this.render(segment);
} }
return html return html
} }
@ -62,9 +67,6 @@ function Tool()
var html = ``; var html = ``;
var skip = 0; var skip = 0;
if(type == "close"){
return `Z `;
}
for(id in verteces){ for(id in verteces){
if(skip > 0){ skip -= 1; continue; } if(skip > 0){ skip -= 1; continue; }
if(id == 0){ html += `M${verteces[id].x},${verteces[id].y} `; continue; } if(id == 0){ html += `M${verteces[id].x},${verteces[id].y} `; continue; }
@ -88,7 +90,7 @@ function Tool()
skip = 2 skip = 2
} }
} }
return html return html
} }