I was always interested in the easiest way to find out if a point is in a triangle or in this case a rectangle cut in half diagonally.
Say I have a 64x64 pixel rectangle. With this rectangle, I want to return TRUE if the passed point is in the upper left corner of the rectangle, and FALSE if it is not.
----- | /| | / | |<__|
Horray for bad ASCII art.
In any case, the hypothetical points for this triangle that return TRUE will be (0,0) and (63,0) and (0, 63). If the point hits the line (for example, 50.0), it will also return TRUE.
Assuming 0.0 is in the upper left corner and increases down ...
I had a possible solution in my head, but it seems more complicated than it should be - accepting the transmitted value of Y, determining where it will be in the rectangle, and calculating manually where the line will be cut with Y. For example, the passed value of Y 16 will be a quarter of the height of the rectangle. And thus, depending on which side you checked (left or right), the line should have been 16 or 48 pixels, depending on the direction of the line. In the above example, since we are testing the upper left corner, at a height of 16 pixels, the line will be 48 pixels wide
There must be a better way.
EDIT: A rectangle may also look the same
----- |\ | | \ | |__>|
But I believe that in most cases, the current responses that have already been provided should still be delayed ...