Fixed terrain checking issue

Terrain checking was not correcting calculating for the topmost right
corner.