Take the 2-minute tour ×  I have the following code:
Object.defineProperty(LineSegment.prototype,'hasPoint',{ value:
function (point) {         if (typeof point != 'object' ||
!(point instanceof Point)) {             throw new
TypeError('LineSegment.prototype.hasPoint requires a point
value.'); }         var m = (this.y1 - this.y2) / (this.x1 -
this.x2);         return (this.y1 - point.y) / (this.x1 -
point.x) == m; }  It works fine for lines, but not line
segments. How would I check if the point is out of bounds, and
apply it to JavaScript?  share|improve this question add comment
1 Answer  up vote 1 down vote accepted  The easiest and fastest
answer can only be used if x1 < x2. In that case, the following
return statement:  return (this.y1 - point.y) / (this.x1 -
point.x) == m && point.x >= this.x1 && point.x <= this.x2;  The
first part checks if the point is on the line, the two next
conditions check if the x coordinate is between x1 and x2
(inclusive).  Note: if x2 < x1, you can simply add a conditi