Refactor the margin functions

Hopefully the comments in these aren't too confusing.

Also updated one of the example graphics to show custom block shapes.