From 0cc4258e3eb119d75f6b071cf85d554ac9a4f143 Mon Sep 17 00:00:00 2001
From: Wellington Gabriel Vicente de Souza <wellingtongabrielvs@gmail.com>
Date: Tue, 1 May 2018 00:21:34 +0000
Subject: [PATCH] [T3] tidy up code and change file name

---
 T3/{lines.html => index.html} |  0
 T3/lines.js                   | 23 +----------------------
 2 files changed, 1 insertion(+), 22 deletions(-)
 rename T3/{lines.html => index.html} (100%)

diff --git a/T3/lines.html b/T3/index.html
similarity index 100%
rename from T3/lines.html
rename to T3/index.html
diff --git a/T3/lines.js b/T3/lines.js
index 8935ae5..f01aeae 100644
--- a/T3/lines.js
+++ b/T3/lines.js
@@ -79,12 +79,6 @@ function handleMouseUp() {
   draggingSecondEnd = false;  
 }
 
-function distance(x0,y0,xf,yf) {
-  power2X = Math.pow(x0 - xf,2);
-  power2Y = Math.pow(y0 - yf,2);
-  return Math.sqrt(power2X + power2Y);
-}
-
 function dragLine() {
   if (selectedLine != null) {
     if (movingEntireLine) {      
@@ -146,11 +140,6 @@ function dragLine() {
   }
 }
 
-function isOnLine(x0, y0, xf, yf, px, py) {
-    var f = function(somex) { return (yf - y0) / (xf - x0) * (somex - x0) + y0; };
-    return Math.abs(f(px) - py) < 20 && px >= x0 && px <= xf;      
-}
-
 function handleMouse() {
   if (mouseDown && selectedLine == null) {
     for (var i = lines.length - 1; i >= 0; i--) {
@@ -172,16 +161,7 @@ function handleMouse() {
     }
   } else if (rightClick) {
     for (var i = lines.length - 1; i >= 0; i--) {
-      //       distanceMouseX0 = distance(mouseX,mouseY,lines[i].x0,lines[i].y0);
-      // distanceMouseXF = distance(mouseX,mouseY,lines[i].xf,lines[i].yf);
-      // distanceX0XF = distance(lines[i].x0,lines[i].y0,lines[i].xf,lines[i].yf);
-      // console.log(distanceMouseX0,distanceMouseXF,distanceX0XF);
-      // if ((distanceMouseX0 + distanceMouseXF >= distanceX0XF - 20) && (distanceMouseX0 + distanceMouseXF <= distanceX0XF + 20)) {
-      //console.log("isOnLine: ", isOnLine(lines[i].x0,lines[i].y0,lines[i].xf,lines[i].yf,mouseX,mouseY));
-      var mouseOnLine = isOnLine(lines[i].x0,lines[i].y0,lines[i].xf,lines[i].yf,mouseX,mouseY)
-                    || isOnLine(lines[i].xf,lines[i].yf,lines[i].x0,lines[i].y0,mouseX,mouseY);
-      console.log(mouseOnLine);
-      if (mouseOnLine) {
+      if ((mouseY >= lines[i].y0 && mouseY <= lines[i].yf) || (mouseY >= lines[i].yf && mouseY <= lines[i].y0)) {
         if (mouseX >= lines[i].x0 && mouseX <= lines[i].xf) {
           lines[lines.length] = new Line(mouseX,mouseY,lines[i].xf,lines[i].yf);
           lines[i].xf = mouseX;
@@ -221,7 +201,6 @@ function generatePolygon() {
       var tmpxf = 300 * Math.cos(angle) + centerX;
       var tmpyf = 300 * Math.sin(angle) + centerY;
       lines[i] = new Line(tmpx0, tmpy0, tmpxf,tmpyf);
-      console.log(lines[i]);
       tmpx0 = tmpxf;
       tmpy0 = tmpyf;
     }
-- 
GitLab