Skip to content

Commit

Permalink
Fixed a couple of regressions in line dragging. #7
Browse files Browse the repository at this point in the history
  • Loading branch information
tiger12506 committed May 21, 2016
1 parent 2d71dce commit e0d5cfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function display() {
scene.lines[i].draw(context);
}


hittest();

setTimeout(display, refreshRate);
Expand Down Expand Up @@ -89,6 +88,7 @@ function init() {
lineMove.x2 -= xMove;
lineMove.y1 -= yMove;
lineMove.y2 -= yMove;
lineMove.recompute();
lineMove.color = lineMove.BASE_COLOR;
lineMove = null;
}
Expand All @@ -101,7 +101,7 @@ function init() {
};

document.onmousedown = function(e) {
if (e.button == 0) {
if (e.button == 0 && !lineStart) {
for (var i = 0; i < scene.lines.length; i++) {
if (intersects(e.pageX, e.pageY, scene.lines[i], thickness)) {
droppedPoint['x'] = e.pageX;
Expand All @@ -115,6 +115,8 @@ function init() {
}

document.ondblclick = function(e) {
lineStart = false;
lineMove = null;
dead = [];
for (var i = 0; i < scene.lines.length; i++) {
if (intersects(e.pageX, e.pageY, scene.lines[i], thickness)) {
Expand Down
13 changes: 8 additions & 5 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ function Line(x1, y1, x2, y2) {
this.min = 1;
this.color = this.BASE_COLOR;

// Precomputed values
this.length = Math.sqrt(Math.pow(this.x2-this.x1, 2) + Math.pow(this.y2-this.y1, 2));
this.x2y1y2x1 = this.x2 * this.y1 - this.y2 * this.x1;
this.ax = (this.x2 - this.x1);
this.ay = (this.y2 - this.y1);
this.recompute = function() {
// Precomputed values
this.length = Math.sqrt(Math.pow(this.x2-this.x1, 2) + Math.pow(this.y2-this.y1, 2));
this.x2y1y2x1 = this.x2 * this.y1 - this.y2 * this.x1;
this.ax = (this.x2 - this.x1);
this.ay = (this.y2 - this.y1);
}
this.recompute();

this.draw = function (context) {
var oldstroke = context.strokeStyle;
Expand Down

0 comments on commit e0d5cfd

Please sign in to comment.