From 608d75c0057eec43faf31e81614331e51fdda988 Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sat, 31 Dec 2016 11:29:31 -0700
Subject: [PATCH] Check for positions before drawing.

---
 scripts/dotgrid.js | 22 +++++++++-------------
 scripts/init.js    |  2 +-
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/scripts/dotgrid.js b/scripts/dotgrid.js
index 19d530a..6133aa5 100644
--- a/scripts/dotgrid.js
+++ b/scripts/dotgrid.js
@@ -65,12 +65,6 @@ function Dotgrid(width,height,grid_x,grid_y)
 
   this.mouse_down = function(e)
   {
-    var pos = this.position_in_grid(e.clientX,e.clientY);
-    pos = this.position_on_grid(pos[0],pos[1]);
-    
-    if(from === null){ this.set_from(pos); }
-    else if(to === null){ this.set_to(pos); }
-    else{  }
   }
 
   this.mouse_move = function(e)
@@ -84,6 +78,12 @@ function Dotgrid(width,height,grid_x,grid_y)
 
   this.mouse_up = function(e)
   {
+    var pos = this.position_in_grid(e.clientX,e.clientY);
+    pos = this.position_on_grid(pos[0],pos[1]);
+    
+    if(from === null){ this.set_from(pos); }
+    else if(to === null){ this.set_to(pos); }
+    else{  }
     
   }
 
@@ -106,15 +106,9 @@ function Dotgrid(width,height,grid_x,grid_y)
   }
 
   // Draw
-
   this.draw_line = function()
   {
-    draw_line();
-  }
-
-  function draw_line()
-  {
-    console.log(vector_element);
+    if(from === null || to === null){ return; }
 
     var s = document.createElementNS('http://www.w3.org/2000/svg', 'line');
     s.setAttribute('x1', -from[0]);
@@ -132,6 +126,8 @@ function Dotgrid(width,height,grid_x,grid_y)
 
   this.draw_arc = function(orientation)
   {
+    if(from === null || to === null){ return; }
+
     var s = document.createElementNS("http://www.w3.org/2000/svg", "path");
     s.setAttribute("d","M"+(-from[0])+","+(from[1])+" A15,15 0 "+orientation+" "+(-to[0])+","+(to[1])+"");
     s.setAttribute('stroke', "#000000");
diff --git a/scripts/init.js b/scripts/init.js
index 369b239..a0f0f2c 100644
--- a/scripts/init.js
+++ b/scripts/init.js
@@ -1,4 +1,4 @@
-dotgrid = new Dotgrid(300,300,20,20);
+dotgrid = new Dotgrid(300,300,21,21);
 dotgrid.install();
 
 var keyboard = new Keyboard();