Skip to content
Snippets Groups Projects
Commit 0cc4258e authored by Wellington Gabriel Vicente de Souza's avatar Wellington Gabriel Vicente de Souza
Browse files

[T3] tidy up code and change file name

parent 6b3a07e1
No related branches found
No related tags found
No related merge requests found
File moved
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment