Fixed crash in terrain brush when dealing with unset tiles

This crash was introduced in 43fef0db20f3691714b88785c54211d47b23e7b0,
when the null check was removed from Tile::terrain.

The edge functions are only used by the terrain brush, so they have now
been moved there, with the null check reintroduced.