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!
I'd draw the following pictures and would write it down as algorithm:
...xxxxxxx xxxxxxx....
. x . x x . x .
. x . x x . x .
...xxxxxxx xxxxxxx....
xxxxxxx .......
x x . .
x.....x xxxxxxx
xxxxxxx x.....x
. . x x
....... xxxxxxx
..........
. .
. xxxx .
. x x .
. x x .
. xxxx .
..........
xxxxxxxxxxxxxx
x x
x ....... x
x . . x
x . . x
x ....... x
x x
xxxxxxxxxxxxxx
Check out for corner cases!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With