From 5315577a9b068e054087805d0125f38121d1b466 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 6 Feb 2018 14:02:13 +1300 Subject: [PATCH] Fixed translation --- sources/scripts/dotgrid.js | 36 ++++-------------------------------- sources/scripts/tool.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/sources/scripts/dotgrid.js b/sources/scripts/dotgrid.js index f153d23..0aeb921 100644 --- a/sources/scripts/dotgrid.js +++ b/sources/scripts/dotgrid.js @@ -250,19 +250,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.draw(); } - this.delete = function() - { - if(from || to || end){ - dotgrid.reset(); - dotgrid.draw(); - return; - } - - this.segments.pop(); - dotgrid.history.push(dotgrid.segments); - this.draw(); - } - this.delete_at = function(pos) { var segs = []; @@ -279,21 +266,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.draw(); } - this.translate = function(t) - { - for(id in dotgrid.segments){ - var segment = dotgrid.segments[id]; - if(segment.from && segment.from.is_equal(dotgrid.translation.from)){ segment.from = new Pos(-dotgrid.translation.to.x,dotgrid.translation.to.y)} - if(segment.to && segment.to.is_equal(dotgrid.translation.from)){ segment.to = new Pos(-dotgrid.translation.to.x,dotgrid.translation.to.y)} - if(segment.end && segment.end.is_equal(dotgrid.translation.from)){ segment.end = new Pos(-dotgrid.translation.to.x,dotgrid.translation.to.y)} - } - - dotgrid.translation = null; - dotgrid.reset(); - - dotgrid.draw(); - } - // STROKE this.draw_line = function() @@ -370,7 +342,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca pos = this.position_on_grid(pos); if(e.altKey){ dotgrid.delete_at(pos); return; } - if(dotgrid.handle_at(pos)){ dotgrid.translation = {from:pos,to:pos}; return; } + if(dotgrid.tool.vertex_at(pos)){ dotgrid.translation = {from:pos,to:pos}; return; } if(!o){ return; } @@ -411,12 +383,12 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca if(pos.x>0) { dotgrid.translation = null; return; } - if(dotgrid.translation && !dotgrid.translation.to.is_equal(dotgrid.translation.from) ){ - dotgrid.translate(dotgrid.translation); + if(dotgrid.translation){ + dotgrid.tool.translate(dotgrid.translation.from,dotgrid.translation.to); + dotgrid.translation = null; return; } - dotgrid.translation = null; this.tool.add_vertex({x:pos.x * -1,y:pos.y}); this.draw(); } diff --git a/sources/scripts/tool.js b/sources/scripts/tool.js index f284c76..9466dc9 100644 --- a/sources/scripts/tool.js +++ b/sources/scripts/tool.js @@ -54,6 +54,34 @@ function Tool() return html } + this.vertex_at = function(pos) + { + for(segment_id in this.layers[this.layer]){ + var segment = this.layers[this.layer][segment_id]; + for(vertex_id in segment.verteces){ + var vertex = segment.verteces[vertex_id]; + if(vertex.x == Math.abs(pos.x) && vertex.y == Math.abs(pos.y)){ + return vertex; + } + } + } + return null; + } + + this.translate = function(a,b) + { + for(segment_id in this.layers[this.layer]){ + var segment = this.layers[this.layer][segment_id]; + for(vertex_id in segment.verteces){ + var vertex = segment.verteces[vertex_id]; + 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)}; + } + } + } + dotgrid.draw(); + } + this.clear = function() { this.verteces = [];