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 8935ae5d3c56e4e7f3b73b9c6b50ae92e3f505ff..f01aeae5dc8ecdd2b1981a733ce3a9afa7a89e93 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; }