Let's say I have a line drawn as so in HTML5 Canvas:
...
ctx.beginPath();
ctx.moveTo(x,y);
ctx.lineTo(x1,y1);
ctx.closePath();
...
I want to find out if the mouse down event happened on this line, and I have code like this:
var handleMouseDown = function(e) {
var coords = translateCoords(e.x,e.y);
...
if (ctx.isPointInPath(coords.x, coords.y) {
...
Now, this code works fine in the case of circles & rectangles, but not for lines. I have 2 questions:
My thinking is that perhaps calling closePath() on a line itself is incorrect. Question - how can I check if the mouse down event happened on this line?
How can I extend this to find if the mouse down event happened near the line?