optimization, avoid generating cells outside the grid when evaluating rules