- Copied map tile merging algorithm from the editor