Add tests for clipping to horizontal margins.

Also fix vertical clipping tests to be more robust by making a better
ref for them.

Also fix polygon tests to work when the shape is clipped by expanding
the margin box for those tests.