From a985e1c54239283296107daff8ec41a2ecaa7a49 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 25 Mar 2023 07:43:55 -0500 Subject: [PATCH] Fix quadNode getChildByIndex inconsistent with DhSectionPos --- .../core/util/objects/quadTree/QuadNode.java | 12 +++++------ core/src/test/java/tests/QuadTreeTest.java | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/seibel/lod/core/util/objects/quadTree/QuadNode.java b/core/src/main/java/com/seibel/lod/core/util/objects/quadTree/QuadNode.java index a37287650..434340e65 100644 --- a/core/src/main/java/com/seibel/lod/core/util/objects/quadTree/QuadNode.java +++ b/core/src/main/java/com/seibel/lod/core/util/objects/quadTree/QuadNode.java @@ -74,10 +74,10 @@ public class QuadNode * Returns the DhLodPos 1 detail level lower

* * Relative child positions returned for each index:
- * 0 = (0,0)
- * 1 = (1,0)
- * 2 = (0,1)
- * 3 = (1,1)
+ * 0 = (0,0) - North West
+ * 1 = (1,0) - South West
+ * 2 = (0,1) - North East
+ * 3 = (1,1) - South East
* * @param child0to3 must be an int between 0 and 3 */ @@ -88,9 +88,9 @@ public class QuadNode case 0: return nwChild; case 1: - return neChild; - case 2: return swChild; + case 2: + return neChild; case 3: return seChild; diff --git a/core/src/test/java/tests/QuadTreeTest.java b/core/src/test/java/tests/QuadTreeTest.java index 101866228..4feff37f0 100644 --- a/core/src/test/java/tests/QuadTreeTest.java +++ b/core/src/test/java/tests/QuadTreeTest.java @@ -523,6 +523,26 @@ public class QuadTreeTest } } + @Test + public void quadNodeChildPositionIndexTest() + { + QuadNode 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 childNode = rootNode.getChildByIndex(i); + Assert.assertEquals("child position not the same as "+DhSectionPos.class.getSimpleName()+"'s getChildByIndex()", childPos, childNode.sectionPos); + } + + } +