main-page-machines: add methods for coordinate translation

Instead of repeating the code (and getting it wrong in places), add two helper
methods and a test for them.