Tuesday 15 June 2010

c# - How to query a grid with a boundary that wraps around the bounds of the grid -



c# - How to query a grid with a boundary that wraps around the bounds of the grid -

using c# i'm trying find if a particular cell (marked greenish x below) within boundary of cell (marked bluish x below). boundary needs loop around if goes off of edges. in illustration boundary 1 cell wide bigger, size of grid whole.

int greenx = 1; int greeny = 1; int bluex = 4; int bluey = 4; int boundarysize = 1; if (greenx >= (bluex - boundarysize) && greenx <= (bluex + boundarysize) && greeny >= (bluey - boundarysize) && greeny <= (bluey + boundarysize)) { // within boundary }

the code have works long no part of boundary goes on edge. simple problem can't figure out. help appreciated.

c# grid

No comments:

Post a Comment