I posted this question already on stackoverflow but was pointed to the community since it is more likely to get an answer. There is also a picture representation of what my problem entails.
Essentially, I have a "map" that consists of several rectangular regions. I have access to the coordinates of all the vertices of each rectangular region (their x_min, x_max, y_min, y_max).
I randomly generate a point that lies anywhere on that map. I know the coordinates of that point (x and y). The problem I want to solve is to find out in what region the point lies in.
what I have done, is just go through a big condition statement checking through one by one if the x & y coordinate of the point is between the x_min and x_max and y_min and y_max of every region. However, I feel like there has to be a more scalable, generalizable, and efficient way to do this but I cannot find a way to do so, at least not something that isn't in a library for a different programming language. I thought of maybe doing something where I split the map in half, find out which half the point lies in, count up all the regions in that half, check if there is one region left and if not, split the map in half again and go through the process again. I just don't have a good idea of how that can be implemented and whether that is feasible or better that the current method I have.