I have a Javascript function that isn't returning the result I expected. I am trying to determine if an x,y point exists within a rectangle based on 2 other x,y points. In my code x and y are the original point in question. z1 and z2 are the top left coordinates of the rectangle and z3 and z4 are the bottom right coordinates.
function isInside(x,y,z1,z2,z3,z4){
x1 = Math.min(z1, z3);
x2 = Math.max(z1, z3);
y1 = Math.min(z2, z4);
y2 = Math.max(z2, z4);
if ((x1 <= x <= x2) && (y1 <= y <= y2)) {
console.log (x1 + "," + x + "," + x2);
console.log (y1 + "," + y + "," + y2);
return true;
} else {
return false;
};
};
If I evaluate isInside(110,175,50,50,100,100) I am getting true. This is unexpected as point 110,175 does not exist within a rectangle of 50,50 and 100,100. Any help would be appreciated.