Ok, as some of you know, I am porting Zoo Tycoon to the calculator.
However, I have come across a problem1 that is a little complex.
So, I have a list of exhibits, which might look like (for one exhibit) {5,50,85,25} (These aren't actual coords, they just give an idea. The first two values are the X and Y for one corner, the other two are the X and Y for the opposite corner). Then I draw a new exhibit, using the following psuedocode:
Get starting point (Input w/ no arguments) or go to another mode (Not covered here)
Check if this point is in an exhibit (Got this covered)
If it's in an exhibit, throw an error and go to the beginning again.
If it isn't, ask for length and width
Check against minimum exhibit size. If it's too small, throw an error and give a choice to start again or enter new values.
Check if it's inside or overlapping another exhibit or building (Here's the problem).
So, I need to see if I can build {10,20,50,15} while {5,50,85,25} is there. And I need to use math to do it. Only, I can't think of an algorithm that will catch this. I'd need to check that it starts over and finishes under the exhibit (Assume Quadrant I if you draw this), and then it throws an error. It also has to catch any overlap at all. Any ideas? I could check if it's between the top two points and beneath them, but that seems like it will take too long to execute any time an exhibit is built.