So, I'm trying to figure out how to implement the method of selecting lines or edges in the drawing area, but my math is a bit missing. This is what I got so far:
- A collection of lines, each line has two endpoints (one for starting and one for ending the line).
- Lines are drawn correctly on canvas
- Mouse click events are accepted when you click on the canvas, so I can get the x and y coordinates of the mouse pointer
I know that I can iterate over a list of strings, but I have no idea how to build an algorithm to select a string at a given coordinate (i.e., a mouse click). Has anyone got any ideas or pointed me in the right direction?
public Line selectLine(Point mousePoint) {
for (Line l : getLines()) {
Point start = l.getStart();
Point end = l.getEnd();
if (canSelect(start, end, mousePoint)) {
return l;
}
}
return null;
}
public boolean canSelect(Point start, Point end, Point selectAt) {
return false;
}
Spike source
share