Fixed perfect chunk coordinates in utilities.
Added respective tests to ensure this doesn't break.
This commit is contained in:
parent
39381f07f9
commit
ec27a9bc10
@ -53,13 +53,15 @@ public class Utilities {
|
||||
public static Point2 worldToLocalChunkCoordinates(int x, int y) {
|
||||
int xRes = 0;
|
||||
if (x < 0) {
|
||||
xRes = CHUNK_SIZE + (x % CHUNK_SIZE);
|
||||
xRes = CHUNK_SIZE - 1 + (x % CHUNK_SIZE);
|
||||
xRes %= CHUNK_SIZE - 1;
|
||||
} else {
|
||||
xRes = x % CHUNK_SIZE;
|
||||
}
|
||||
int yRes = 0;
|
||||
if (y < 0) {
|
||||
yRes = CHUNK_SIZE + (y % CHUNK_SIZE);
|
||||
yRes = CHUNK_SIZE - 1 + (y % CHUNK_SIZE);
|
||||
yRes %= CHUNK_SIZE - 1;
|
||||
} else {
|
||||
yRes = y % CHUNK_SIZE;
|
||||
}
|
||||
|
@ -73,13 +73,25 @@ public class UtilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testWorldToLocalCoordinatesNegative() {
|
||||
assertEquals(new Point2(2, 5), Utilities.worldToLocalChunkCoordinates(-62, -27));
|
||||
assertEquals(new Point2(2, 5), Utilities.worldToLocalChunkCoordinates(new Point2(-62, -27)));
|
||||
assertEquals(new Point2(1, 4), Utilities.worldToLocalChunkCoordinates(-62, -27));
|
||||
assertEquals(new Point2(1, 4), Utilities.worldToLocalChunkCoordinates(new Point2(-62, -27)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldToLocalCoordinatesNegativePerfect() {
|
||||
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(-128, -32));
|
||||
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(new Point2(-256, -16)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldToLocalCoordinatesPositive() {
|
||||
assertEquals(new Point2(7, 3), Utilities.worldToLocalChunkCoordinates(39, 83));
|
||||
assertEquals(new Point2(7, 3), Utilities.worldToLocalChunkCoordinates(new Point2(39, 83)));
|
||||
assertEquals(new Point2(6, 2), Utilities.worldToLocalChunkCoordinates(39, 83));
|
||||
assertEquals(new Point2(6, 2), Utilities.worldToLocalChunkCoordinates(new Point2(39, 83)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldToLocalCoordinatesPositivePerfect() {
|
||||
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(1024, 32));
|
||||
assertEquals(new Point2(0, 0), Utilities.worldToLocalChunkCoordinates(new Point2(16, 80)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user