Of course I did consider unit size. Spearmen in example is 1x1 unit.
Another example that does not work:
createUnit('spearman', 0, { 5, 5 })
createUnit('spearman', 0, { 5, 7 })
createUnit('spearman', 0, { 5, 9 })
To make it easier to find bug, this code works:
createUnit('spearman', 0, { 5, 5 })
createUnit('spearman', 0, { 5, 10 })
createUnit('spearman', 0, { 5, 15 })
But, of course, creates 4 empty spaces between the 3 spearmen. So it is not helpful.