|
@@ -209,9 +209,20 @@ class Line extends Drawable {
|
|
|
}
|
|
|
|
|
|
in(x, y) {
|
|
|
- // console.log("this.x " + this.x, "this.y " + this.y);
|
|
|
- // console.log("x " + x, "y " + y);
|
|
|
- // new Line(this.x, this.y, this.width, 0, "red");
|
|
|
+ let angleCrank = Math.atan2(this.height, this.width);
|
|
|
+ let angleMouse = Math.atan2(y - this.y, x - this.x);
|
|
|
+ let lengthLine = this.distanceTo(this.x + this.width, this.y + this.height);
|
|
|
+ let horizontal = angleMouse - angleCrank;
|
|
|
+ let newX = Math.cos(horizontal) * distance(x, y, this.x, this.y);
|
|
|
+ let newY = Math.sin(horizontal) * distance(x, y, this.x, this.y);
|
|
|
+ if (
|
|
|
+ newX > 0 &&
|
|
|
+ newX < lengthLine &&
|
|
|
+ newY > this.lineWidth / -2 &&
|
|
|
+ newY < this.lineWidth / 2
|
|
|
+ ) {
|
|
|
+ console.log("selected");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|