Update the grid detection.

When the edge A's angle is 1 degree and the edge B's angle is 89 degree,
these two edges should be in the same grid group. To handle this issue,
we have to consider that when the angle of two edges is close to 90
degree, they are in the same grid group.