Resolve bugs in polygon rasterization.

This commit resolves a number of bugs in polygon rasterization,
primarily based on unsafe assumptions about the inputs of the
rasterizer.

Fixes #412, #407.

This pull request also includes a temporary reimplementation of AsPolygonSet to get around a scala reflection bug.