Easier rotation of 9-grids

Not sure if this will be of any use to you but I though I should mention it just in case.
I was watching “Dev Stream #115: More Roof Work” where Tony was dealing with 9-grids and rotations. It reminded me of a similar problem that I was pondering a few weeks ago.
In my case I wanted an easy way to compare two 9-grids with different rotations, so I had to rotate the indices.
I found that it got a lot easier if I put the 9 in the middle and had 1 to 8 go around the edge like a clock. That way, when I want to rotate the indices I can skip the 9 and for the rest I just add 2 for each 90 degrees of rotation and use modulus 8 to start over from 1 when going past 8.

( index[1-8] + (rotation / 45) ) mod 8 = rotated index

I’ve only done it in pseudo code so far, so I’m not sure if it might be better to start at 0 instead of 1 and stuff like that and I know you usually need to do some extra work when using modulus with negative numbers, but that sort of stuff is language specific. If you get the idea those things shouldn’t be hard to fix.
Anyway, like I said, mentioning it just in case you ever need it. Cheers!


Great thought @Agon, let me page @Ponder to make sure he sees this…