I think so.
The worst case I can think of (grid = [0,1) x [0,1)) is: Top = -0.25, Left = -0.25, Bottom = 0.25, Right = 0.25
It looks (on packaging):
______ |_| |_| | | |_ _| |_|__|_|
Right now, you need to check the four corners to see if there is a point in them. However, I believe that by running the test in the space [1,2) x [1,2), you can avoid the problem because it becomes a rectangle again.
______ | | | | | _|_ |____| | |___|
Simplify the problem by calculating the width and height of the rectangle.
Width=Mod(Right-Left+MAP_SIZE,MAP_SIZE) Height=Mod(Bottom-Top+MAP_SIZE,MAP_SIZE)
Now calculate the wrapped location for the top left
LeftNew=Mod(Left+MAP_SIZE,MAP_SIZE) TopNew=Mod(Top+MAP_SIZE,MAP_SIZE)
Calculate the new one from bottom to right:
RightNew=LeftNew+Width BottomNew=TopNew+Height
Now, for each point you want to test, add MAP_SIZE and check if it is inside the new rect!
TestNew=AddPoints(Test,MAP_SIZE) If (TestNew.X>=LeftNew && TestNew.X<=RightNew && TestNew.Y>=TopNew && TestNew.T<=BottomNew) { We have a point inside! }
I have not tested this exhaustively, but currently I think that is correct.