Merge pull request #33 from jaylmao/master

Fix typo for 'vertices'
This commit is contained in:
Лu Лinveгa 2018-05-09 21:58:08 +12:00 committed by GitHub
commit 55e52f52a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 39 deletions

View File

@ -287,7 +287,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y)
{ {
if(this.preview_prev == operation){ return; } if(this.preview_prev == operation){ return; }
this.preview_el.innerHTML = !operation || operation == "close" || !dotgrid.tool.can_cast(operation) ? `<path d='M0,0'></path>` : `<path d='${dotgrid.tool.path(dotgrid.tool.index,[{type:operation,verteces:dotgrid.tool.verteces}])}'></path>`; this.preview_el.innerHTML = !operation || operation == "close" || !dotgrid.tool.can_cast(operation) ? `<path d='M0,0'></path>` : `<path d='${dotgrid.tool.path(dotgrid.tool.index,[{type:operation,vertices:dotgrid.tool.vertices}])}'></path>`;
this.preview_prev = operation; this.preview_prev = operation;
} }
@ -520,4 +520,4 @@ window.addEventListener('dragover',function(e)
String.prototype.capitalize = function() String.prototype.capitalize = function()
{ {
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase(); return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
} }

View File

@ -49,16 +49,16 @@ function Guide()
} }
} }
// Verteces // Vertices
for(id in dotgrid.tool.verteces){ for(id in dotgrid.tool.vertices){
this.draw_vertex(dotgrid.tool.verteces[id]); this.draw_vertex(dotgrid.tool.vertices[id]);
} }
// Handles // Handles
for(segment_id in dotgrid.tool.layer()){ for(segment_id in dotgrid.tool.layer()){
var segment = dotgrid.tool.layer()[segment_id]; var segment = dotgrid.tool.layer()[segment_id];
for(vertex_id in segment.verteces){ for(vertex_id in segment.vertices){
var vertex = segment.verteces[vertex_id]; var vertex = segment.vertices[vertex_id];
this.draw_handle(vertex); this.draw_handle(vertex);
} }
} }
@ -138,4 +138,4 @@ function Guide()
} }
function pos_is_equal(a,b){ return a && b && Math.abs(a.x) == Math.abs(b.x) && Math.abs(a.y) == Math.abs(b.y) } function pos_is_equal(a,b){ return a && b && Math.abs(a.x) == Math.abs(b.x) && Math.abs(a.y) == Math.abs(b.y) }
} }

View File

@ -8,7 +8,7 @@ function Tool()
{ thickness:2,strokeLinecap:"round",strokeLinejoin:"round",color:"#0f0",fill:"none",mirror_style:0 }, { thickness:2,strokeLinecap:"round",strokeLinejoin:"round",color:"#0f0",fill:"none",mirror_style:0 },
{ thickness:2,strokeLinecap:"round",strokeLinejoin:"round",color:"#00f",fill:"none",mirror_style:0 } { thickness:2,strokeLinecap:"round",strokeLinejoin:"round",color:"#00f",fill:"none",mirror_style:0 }
]; ];
this.verteces = []; this.vertices = [];
this.reqs = { line:2,arc_c:2,arc_r:2,bezier:3,close:0 }; this.reqs = { line:2,arc_c:2,arc_r:2,bezier:3,close:0 };
this.start = function() this.start = function()
@ -21,14 +21,14 @@ function Tool()
this.reset = function() this.reset = function()
{ {
this.layers = [[],[],[]]; this.layers = [[],[],[]];
this.verteces = []; this.vertices = [];
this.index = 0; this.index = 0;
dotgrid.set_size({width:300,height:300}) dotgrid.set_size({width:300,height:300})
} }
this.clear = function() this.clear = function()
{ {
this.verteces = []; this.vertices = [];
dotgrid.preview(); dotgrid.preview();
dotgrid.draw(); dotgrid.draw();
} }
@ -81,7 +81,7 @@ function Tool()
this.remove_segment = function() this.remove_segment = function()
{ {
if(this.verteces.length > 0){ this.clear(); return; } if(this.vertices.length > 0){ this.clear(); return; }
this.layer().pop(); this.layer().pop();
this.clear(); this.clear();
@ -92,13 +92,13 @@ function Tool()
{ {
for(segment_id in this.layer()){ for(segment_id in this.layer()){
var segment = this.layer()[segment_id]; var segment = this.layer()[segment_id];
for(vertex_id in segment.verteces){ for(vertex_id in segment.vertices){
var vertex = segment.verteces[vertex_id]; var vertex = segment.vertices[vertex_id];
if(Math.abs(pos.x) == Math.abs(vertex.x) && Math.abs(pos.y) == Math.abs(vertex.y)){ if(Math.abs(pos.x) == Math.abs(vertex.x) && Math.abs(pos.y) == Math.abs(vertex.y)){
segment.verteces.splice(vertex_id,1) segment.vertices.splice(vertex_id,1)
} }
} }
if(segment.verteces.length < 2){ if(segment.vertices.length < 2){
this.layers[this.index].splice(segment_id,1) this.layers[this.index].splice(segment_id,1)
} }
} }
@ -109,15 +109,15 @@ function Tool()
this.add_vertex = function(pos) this.add_vertex = function(pos)
{ {
pos = {x:Math.abs(pos.x),y:Math.abs(pos.y)} pos = {x:Math.abs(pos.x),y:Math.abs(pos.y)}
this.verteces.push(pos); this.vertices.push(pos);
} }
this.vertex_at = function(pos) this.vertex_at = function(pos)
{ {
for(segment_id in this.layer()){ for(segment_id in this.layer()){
var segment = this.layer()[segment_id]; var segment = this.layer()[segment_id];
for(vertex_id in segment.verteces){ for(vertex_id in segment.vertices){
var vertex = segment.verteces[vertex_id]; var vertex = segment.vertices[vertex_id];
if(vertex.x == Math.abs(pos.x) && vertex.y == Math.abs(pos.y)){ if(vertex.x == Math.abs(pos.x) && vertex.y == Math.abs(pos.y)){
return vertex; return vertex;
} }
@ -131,13 +131,13 @@ function Tool()
if(!this.layer()){ this.layers[this.index] = []; } if(!this.layer()){ this.layers[this.index] = []; }
if(!this.can_cast(type)){ console.warn("Cannot cast"); return; } if(!this.can_cast(type)){ console.warn("Cannot cast"); return; }
var append_target = this.can_append({type:type,verteces:this.verteces.slice()}) var append_target = this.can_append({type:type,vertices:this.vertices.slice()})
if(append_target){ if(append_target){
this.layers[this.index][append_target].verteces = this.layers[this.index][append_target].verteces.concat(this.verteces.slice()) this.layers[this.index][append_target].vertices = this.layers[this.index][append_target].vertices.concat(this.vertices.slice())
} }
else{ else{
this.layer().push({type:type,verteces:this.verteces.slice()}) this.layer().push({type:type,vertices:this.vertices.slice()})
} }
this.clear(); this.clear();
@ -152,9 +152,9 @@ function Tool()
for(id in this.layer()){ for(id in this.layer()){
var stroke = this.layer()[id]; var stroke = this.layer()[id];
if(stroke.type != content.type){ continue; } if(stroke.type != content.type){ continue; }
if(!stroke.verteces[stroke.verteces.length-1]){ continue; } if(!stroke.vertices[stroke.vertices.length-1]){ continue; }
if(stroke.verteces[stroke.verteces.length-1].x != content.verteces[0].x){ continue; } if(stroke.vertices[stroke.vertices.length-1].x != content.vertices[0].x){ continue; }
if(stroke.verteces[stroke.verteces.length-1].y != content.verteces[0].y){ continue; } if(stroke.vertices[stroke.vertices.length-1].y != content.vertices[0].y){ continue; }
return id; return id;
} }
return false; return false;
@ -171,11 +171,11 @@ function Tool()
} }
} }
if(type == "bezier"){ if(type == "bezier"){
if(this.verteces.length % 2 == 0){ if(this.vertices.length % 2 == 0){
return false; return false;
} }
} }
return this.verteces.length >= this.reqs[type]; return this.vertices.length >= this.reqs[type];
} }
this.path = function(layer_id = 0, preview = null) this.path = function(layer_id = 0, preview = null)
@ -237,16 +237,16 @@ function Tool()
this.render = function(segment, angle = 0, mirror_x = false, mirror_y = false) this.render = function(segment, angle = 0, mirror_x = false, mirror_y = false)
{ {
var type = segment.type; var type = segment.type;
var verteces = segment.verteces; var vertices = segment.vertices;
var html = ``; var html = ``;
var skip = 0; var skip = 0;
for(id in verteces){ for(id in vertices){
if(skip > 0){ skip -= 1; continue; } if(skip > 0){ skip -= 1; continue; }
var vertex = this.mirror_mod(verteces[id],angle,mirror_x,mirror_y); var vertex = this.mirror_mod(vertices[id],angle,mirror_x,mirror_y);
var next = this.mirror_mod(verteces[parseInt(id)+1],angle,mirror_x,mirror_y) var next = this.mirror_mod(vertices[parseInt(id)+1],angle,mirror_x,mirror_y)
var after_next = this.mirror_mod(verteces[parseInt(id)+2],angle,mirror_x,mirror_y) var after_next = this.mirror_mod(vertices[parseInt(id)+2],angle,mirror_x,mirror_y)
if(id == 0){ if(id == 0){
html += `M${vertex.x},${vertex.y} `; html += `M${vertex.x},${vertex.y} `;
@ -290,10 +290,10 @@ function Tool()
{ {
for(segment_id in this.layer()){ for(segment_id in this.layer()){
var segment = this.layer()[segment_id]; var segment = this.layer()[segment_id];
for(vertex_id in segment.verteces){ for(vertex_id in segment.vertices){
var vertex = segment.verteces[vertex_id]; var vertex = segment.vertices[vertex_id];
if(vertex.x == Math.abs(a.x) && vertex.y == Math.abs(a.y)){ if(vertex.x == Math.abs(a.x) && vertex.y == Math.abs(a.y)){
segment.verteces[vertex_id] = {x:Math.abs(b.x),y:Math.abs(b.y)}; segment.vertices[vertex_id] = {x:Math.abs(b.x),y:Math.abs(b.y)};
} }
} }
} }
@ -308,9 +308,9 @@ function Tool()
for(segment_id in this.layer()){ for(segment_id in this.layer()){
var segment = this.layer()[segment_id]; var segment = this.layer()[segment_id];
for(vertex_id in segment.verteces){ for(vertex_id in segment.vertices){
var vertex = segment.verteces[vertex_id]; var vertex = segment.vertices[vertex_id];
segment.verteces[vertex_id] = {x:vertex.x+offset.x,y:vertex.y-offset.y}; segment.vertices[vertex_id] = {x:vertex.x+offset.x,y:vertex.y-offset.y};
} }
} }
dotgrid.history.push(this.layers); dotgrid.history.push(this.layers);
@ -355,4 +355,4 @@ function Tool()
function rotate_point(pointX, pointY, originX, originY, angle){ angle = angle * Math.PI / 180.0; return { x: (Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX).toFixed(1), y: (Math.sin(angle) * (pointX-originX) + Math.cos(angle) * (pointY-originY) + originY).toFixed(1) }; } function rotate_point(pointX, pointY, originX, originY, angle){ angle = angle * Math.PI / 180.0; return { x: (Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX).toFixed(1), y: (Math.sin(angle) * (pointX-originX) + Math.cos(angle) * (pointY-originY) + originY).toFixed(1) }; }
function copy(data){ return data ? JSON.parse(JSON.stringify(data)) : []; } function copy(data){ return data ? JSON.parse(JSON.stringify(data)) : []; }
function clamp(v, min, max) { return v < min ? min : v > max ? max : v; } function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
} }