Fix quadNode getChildByIndex inconsistent with DhSectionPos

This commit is contained in:
James Seibel
2023-03-25 07:43:55 -05:00
parent 8a32d7f84a
commit a985e1c542
2 changed files with 26 additions and 6 deletions
@@ -74,10 +74,10 @@ public class QuadNode<T>
* Returns the DhLodPos 1 detail level lower <br><br>
*
* Relative child positions returned for each index: <br>
* 0 = (0,0) <br>
* 1 = (1,0) <br>
* 2 = (0,1) <br>
* 3 = (1,1) <br>
* 0 = (0,0) - North West <br>
* 1 = (1,0) - South West <br>
* 2 = (0,1) - North East <br>
* 3 = (1,1) - South East <br>
*
* @param child0to3 must be an int between 0 and 3
*/
@@ -88,9 +88,9 @@ public class QuadNode<T>
case 0:
return nwChild;
case 1:
return neChild;
case 2:
return swChild;
case 2:
return neChild;
case 3:
return seChild;
@@ -523,6 +523,26 @@ public class QuadTreeTest
}
}
@Test
public void quadNodeChildPositionIndexTest()
{
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte)10, 0, 0), (byte)0);
rootNode.forEachDirectChild((child, childPos) ->
{
rootNode.setValue(childPos, 1, null);
});
Assert.assertEquals("node not filled", rootNode.getChildValueCount(), 4);
for (int i = 0; i < 4; i++)
{
DhSectionPos childPos = rootNode.sectionPos.getChildByIndex(i);
QuadNode<Integer> childNode = rootNode.getChildByIndex(i);
Assert.assertEquals("child position not the same as "+DhSectionPos.class.getSimpleName()+"'s getChildByIndex()", childPos, childNode.sectionPos);
}
}