Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Packs relative coordinates into an int with optional side bits. Layout: [6 side bits][8 Y][9 Z][9 X]
* <p>
* Valid range: X/Z: -256 to +255 (9-bit signed), Y: -128 to +127 (8-bit signed).
* Values outside this range will silently wrap due to masking.
* Valid range: X/Z: -256 to +255 (9-bit signed), Y: -128 to +127 (8-bit signed). Values outside this range will
* silently wrap due to masking.
*/
public final class RelativeCoordinatePacker {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ public class RelativeCoordinatePackerTest {
@Test
void testPackUnpackRoundTrip() {
// X/Z: 9-bit signed (-256 to +255), Y: 8-bit signed (-128 to +127)
int[][] coords = {
{ 0, 0, 0 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 },
{ -1, 0, 0 }, { 0, -1, 0 }, { 0, 0, -1 }, { -1, -1, -1 },
{ 31, 31, 31 }, { -32, -32, -32 }, { -15, 10, -20 },
int[][] coords = { { 0, 0, 0 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { -1, 0, 0 }, { 0, -1, 0 }, { 0, 0, -1 },
{ -1, -1, -1 }, { 31, 31, 31 }, { -32, -32, -32 }, { -15, 10, -20 },
// Extended range tests
{ 255, 127, 255 }, { -256, -128, -256 },
{ 100, -50, -200 }, { -200, 100, 150 },
};
{ 255, 127, 255 }, { -256, -128, -256 }, { 100, -50, -200 }, { -200, 100, 150 }, };
for (int[] c : coords) {
int packed = RelativeCoordinatePacker.pack(c[0], c[1], c[2]);
assertEquals(c[0], RelativeCoordinatePacker.unpackX(packed), "X for " + c[0]);
Expand Down