Some reworking of the grid collision algorithm.

Should be a bit faster and more accurate. Hopefully a lot less
bizarre sorting swaps in the future.