Given rectangle_A intersecting rectangle_B,
Which has a union defined such that it is the rectangle containing both rectangles:
I want to determine the coordinates of the (not overlapping) rectangles required to add to rectangle_A to create the union of rectangle_A and rectangle_B:
(note: this is just one configuration of the solution set of rectangles. the white rectangles above could be configured differently, as long as they don't overlap.)
Is there a simple algorithm for every case of rectangle intersection? I've done a first pass and I miss some corners. Evidently not my forté.
Why? When panning in a UI, I only want to (i) update the new parts of the canvas (ii) keep track of what has been painted as a rectangle (the union of rectangle_A and rectangle_B).
Here are some other configurations of rectangle_A and rectangle_B which would require solutions: