I have a list of rectangles and I need to generate a list of rectangles that intersect.
Rectangles are defined using
- Point
- Size
- Boolean whether the rectangle can move
- Boolean whether the rectangle can be removed
No rectangles can be moved but cannot be removed
An intersection is defined using
- Pointer to first rectangle
- Pointer to second rectangle
- List of points of the first rectangle that are in the second
- List of points of the second rectangle that are in the first
I need a container for this, as rectangles can be added, removed or moved. operations that I need:
- Insert of rectangle
- Remove of rectangle (only possible for those who are marked for it)
- Changing position of rectangle (not size, only possible with those who are marked for it)
- Generating set of intersections.
How would I go about implementing such a container? I can do it easily using cross check method, but that will be far from optimized.
I thought of keeping a map of rectangle -> intersection and then whenever a rectangle is added check if its intersecting anything and add intersection to the map, and when its removed, remove the key from the map, but I don't know how to check if it intersects anything fast, or how to move rectangles without remove and reinsert.
I can use C++11.