Who said anything about rotation? I mentioned how to visualise which parts of the map would be connected to give it a topology similar to that of a sphere (either fold the map along the line of 0 latitude and imagine the edges are joined together, or imagine a cylinder with the caps sewn shut).
Here's some pseudo-code for that. Map your coordinates into the range -1 to +1 (-1 on the X axis would be the West edge, +1 on the X axis would be the East edge, +1 on the Y axis would be the North edge, -1 on the Y axis would be the South edge).
if(x > 1) x = x - 2; // maps x = +1 to x = -1
if(x < -1) x = x + 2; // maps x = -1 to x = +1
Wrapping by going North:
if(y > 1) x = -x, y = 1 - (y - 1); // reflect x coordinate in y axis (i.e. the line x = 0) and reflect y coordinate around line y = 1
1 - (y - 1) simplifies to 1 - y + 1 = 2 - y
Wrapping by going South:
if(y < -1) x = -x, y = -1 - (y - (-1)); // reflect x coordinate in y axis and reflect y coordinate around line y = -1
-1 - (y - (-1)) simplifies to -1 - (y + 1) = -2 - y
Example: you move off the south edge of the map and your x, y coordinates would have placed you at (0.6, -1.25). Your new coordinates would be (-0.6, -2 - (-1.25)) = (-0.6, -0.75)
EDIT: It is possible to cross both east/west and go off the top or bottom in the same move. Solve this by checking for going off the east or west edge first, adjust the x coordinate, and then check the new position against the top and bottom of the map.
Edited by Paradigm Shifter, 11 July 2013 - 01:14 AM.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley