Good afternoon.
My situation:
A rectangle (left, top, right, bottom)
contains a point (x, y)
if left < x < right
and top < y < bottom
(assuming coordinates increase going downwards, which is the case with most hardware i've seen; if your coordinates increase going upwards, the more traditionally mathematical case, swap top
and bottom
). You're not going to get much more efficient than that for the test.
If you consider a rectangle as "containing" a point if it's on the border as well, then replace all the <
s with <=
.
As for what to do with the collection of rectangles...i dunno. I'd think a list sorted by the coordinates of the corners would do something, but i'm not really seeing much benefit to it...at most, you'd be cutting your list of stuff to check by half, on average (with the worst case still requiring checking everything). Half of a whole freaking lot can still be a whole lot. :)