Fixed conversion from world to chunk coords.

Added test that catches this case.
This commit is contained in:
Harrison Deng 2020-04-27 15:14:33 -05:00
parent 26ebf7af33
commit 49f26f7901
2 changed files with 6 additions and 1 deletions

View File

@ -38,7 +38,7 @@ public class Utilities {
xRes = x / CHUNK_SIZE;
}
int yRes = 0;
if (x < 0) {
if (y < 0) {
yRes = (int) Math.floor((float) y / CHUNK_SIZE);
} else {
yRes = y / CHUNK_SIZE;

View File

@ -61,6 +61,11 @@ public class UtilitiesTest {
assertEquals(new Point2(-4, -3), Utilities.worldToChunkCoordinates(-55, -33));
}
@Test
public void testWorldToChunkCoordinatesNegativeOffClose() {
assertEquals(new Point2(15, -15), Utilities.worldToChunkCoordinates(255, -227));
}
@Test
public void testWorldToChunkCoordinatesPositivePerfect() {
assertEquals(new Point2(4, 5), Utilities.worldToChunkCoordinates(64, 80));