var x1 = 10
var y1 = 10
var x2 = 500
var y2 = 400
// ...
var a = (x2 - x1) / (y2 - y1)
// ...
var x = mouseX - x1
var y = mouseY - y1
var isLine = (x > 0 && y > 0)
&& Math.abs(a - x / y) / < 0.5
&& x < (x2 - x1)
&& y < (y2 - y1);
function getLineFn(x1, y1, x2, y2) {
var k = (y2 - y1) / (x2 - x1);
var b = y1 - k * x1;
return function(x, y) {
var f = x * k + b;
var d = Math.abs(y - f);
return d < 0.00001;
}
}
var x1 = 10
var y1 = 10
var x2 = 500
var y2 = 400
var isOnLine = getLineFn(x1, y1, x2, y2);
var test = isOnLine(100, 200);
console.log(test);