Previous solution did not work well on high resolutions due to
incorrect tile calculations - was not updating edges and sometimes
hanged in endless loop trying to find upper-left or bottom-right
tiles.
New solution follows Sfall's HRP implementation.