I’m looking for an algorithm that takes two rectangles defined by (xa1,ya1,xa2,ya2) and (xb1,yb1,xb2,yb2), checks if they can be combined into a single rectangle and if they can, returns the new rectangle. An example:
xa1=0,ya1=0,xa2=320,ya2=119
xb1=0,yb1=120,xb2=320,yb2=239
These two rectangles can be combined into the following rectangle:
xc1=0,yc1=0,xc2=320,yc2=240
How would you implement such an algorithm? Thanks!
After much fiddling I kind of worked out what you want. Note that there is still some contention to what you mean by ‘strict bounding box’: the sample in you original question does not satisfy the description you gave:
This implementation should give you plenty of ideas, and I’m sure you know how to write
if you really wanted that.
Codepad code:
Output: