Add DhSectionPos.getNumberOfLodSectionsWide()

This commit is contained in:
James Seibel
2023-09-14 07:52:04 -05:00
parent 00806933e0
commit 269b763b73
3 changed files with 44 additions and 13 deletions
@@ -30,7 +30,7 @@ public class BitShiftUtil
{
/**
* Equivalent to: <br>
* {@literal 1 << value0, } <br>
* {@literal 1 << value, } <br>
* 2^value, <br>
* Math.pow(2, value) <br><br>
*
@@ -189,6 +189,14 @@ public class DhSectionPos
return new DhLodUnit(this.sectionDetailLevel, BitShiftUtil.powerOfTwo(offset));
}
public int getNumberOfLodSectionsWide() { return this.getNumberOfLodSectionsWide(this.sectionDetailLevel); } // TODO this always returns 1...
public int getNumberOfLodSectionsWide(byte returnDetailLevel)
{
LodUtil.assertTrue(returnDetailLevel <= this.sectionDetailLevel, "returnDetailLevel must be less than sectionDetail"); // TODO add something to the method name stating this
byte offset = (byte) (this.sectionDetailLevel - returnDetailLevel);
return BitShiftUtil.powerOfTwo(offset);
}
//==================//
+35 -12
View File
@@ -264,19 +264,30 @@ public class DhSectionPosTest
// widths should be the same regardless of position in the world
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(1, originSectionPos.getWidth().numberOfLodSectionsWide);
Assert.assertEquals(1, originSectionPos.getNumberOfLodSectionsWide());
Assert.assertEquals(originSectionPos.getWidth().numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide());
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(1, sectionPos.getWidth().numberOfLodSectionsWide);
Assert.assertEquals(1, sectionPos.getNumberOfLodSectionsWide());
Assert.assertEquals(sectionPos.getWidth().numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide());
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(1, originSectionPos.getWidth().numberOfLodSectionsWide);
Assert.assertEquals(1, originSectionPos.getNumberOfLodSectionsWide());
Assert.assertEquals(originSectionPos.getWidth().numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide());
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(1, sectionPos.getWidth().numberOfLodSectionsWide);
Assert.assertEquals(1, sectionPos.getNumberOfLodSectionsWide());
Assert.assertEquals(sectionPos.getWidth().numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide());
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(1, originSectionPos.getWidth().numberOfLodSectionsWide);
Assert.assertEquals(1, originSectionPos.getNumberOfLodSectionsWide());
Assert.assertEquals(originSectionPos.getWidth().numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide());
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(1, sectionPos.getWidth().numberOfLodSectionsWide);
Assert.assertEquals(1, sectionPos.getNumberOfLodSectionsWide());
Assert.assertEquals(sectionPos.getWidth().numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide());
}
@Test
@@ -285,20 +296,32 @@ public class DhSectionPosTest
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
originSectionPos = originSectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(2, originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
Assert.assertEquals(2, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
Assert.assertEquals(originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
sectionPos = sectionPos.convertNewToDetailLevel((byte) 1);
Assert.assertEquals(2, sectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
Assert.assertEquals(2, sectionPos.getNumberOfLodSectionsWide((byte) 0));
Assert.assertEquals(sectionPos.getWidth((byte) 0).numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide((byte) 0));
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
Assert.assertEquals(64, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
Assert.assertEquals(originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide((byte) 0));
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, sectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
Assert.assertEquals(64, sectionPos.getNumberOfLodSectionsWide((byte) 0));
Assert.assertEquals(sectionPos.getWidth((byte) 0).numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide((byte) 0));
originSectionPos = originSectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(4096, originSectionPos.getWidth((byte) 3).numberOfLodSectionsWide);
Assert.assertEquals(4096, originSectionPos.getNumberOfLodSectionsWide((byte) 3));
Assert.assertEquals(originSectionPos.getWidth((byte) 3).numberOfLodSectionsWide, originSectionPos.getNumberOfLodSectionsWide((byte) 3));
sectionPos = sectionPos.convertNewToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(4096, sectionPos.getWidth((byte) 3).numberOfLodSectionsWide);
Assert.assertEquals(4096, sectionPos.getNumberOfLodSectionsWide((byte) 3));
Assert.assertEquals(sectionPos.getWidth((byte) 3).numberOfLodSectionsWide, sectionPos.getNumberOfLodSectionsWide((byte) 3));
}