Fix missing cases, and add exhaustive tests.

My last commit had a couple of bugs and was missing several
interesting cases. I believe I have now written exhaustive
tests for all 0xN, 1xN, 2xN, 3xN rectangles. I think all
interesting cases happen at 5xN or below; maybe even 4xN.