In computational geometry, managing the relationship between spatial objects is a fundamental task. In this problem, you are required to implement a Rectangle Algebra System using C++ Classes and Operator Overloading.
Your goal is to treat geometric rectangles as algebraic elements, where the Intersection and Bounding Box operations are represented by standard operators.
Each rectangle in this system is a Axis-Aligned Bounding Box and is defined by two points (x1 , y1) and (x2 , y2) on its diagonal. You need to implement the constructor to store these information in a useful way.
You must overload the following operators to support complex geometric expressions:
Intersection (A & B):
Returns a new Rectangle representing the overlapping area.
If A and B do not overlap, or one's area is 0, then it should return a zero-area rectangle.
Modified Union, or Bounding Box (A | B):
Returns a new Rectangle that is the smallest axis-aligned rectangle containing both A and B.
Identity Logic: If A is a zero-area rectangle, A | B should return B.
Assignment (A = B):
Ensures that rectangles can be assigned to one another safely.
The system must be able to calculate the area of the resulting rectangle.
Constraints
The first line contains an integer N, the number of rectangles.
The next N lines each contain Name x1 y1 x2 y2.
Name: A unique string ID.
x1 y1 x2 y2: Coordinates of two opposite corner.
The final line is a space-separated algebraic string. Operators include & (Intersection), | (Bounding Box). You must evaluated it from left to right.
A single line containing the area of the final resulting rectangle, with '\n'.