The second one does not work correctly if the tile size is 1. The problem is with
var mid = tileSize/2;
if tileSize is 1 it will always return 0 (since it is an integer operation).
The fix would be:
var mid = tileSize/2.0;
--32pins 19:08, 8 June 2011 (PDT)