From 558fca79360c69e451e20a550bcdf345e73cd0f7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 2 Aug 2013 11:12:33 -0700 Subject: [PATCH] latest jurisdiction work --- libraries/shared/src/OctalCode.cpp | 39 ++++++++++++++++++++++++ libraries/shared/src/OctalCode.h | 4 ++- libraries/voxels/src/JurisdictionMap.cpp | 30 ++++++++++++++++-- libraries/voxels/src/JurisdictionMap.h | 11 ++++--- libraries/voxels/src/VoxelTree.cpp | 15 +++++++-- voxel-server/src/main.cpp | 7 ++--- 6 files changed, 92 insertions(+), 14 deletions(-) diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index b085a146a2..8acc9a922f 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -257,3 +257,42 @@ unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* return newCode; } +bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild) { + if (!possibleAncestor || !possibleDescendent) { + return false; + } + + int ancestorCodeLength = numberOfThreeBitSectionsInCode(possibleAncestor); + if (ancestorCodeLength == 0) { + return true; // this is the root, it's the anscestor of all + } + + int descendentCodeLength = numberOfThreeBitSectionsInCode(possibleDescendent); + + // if the caller also include a child, then our descendent length is actually one extra! + if (descendentsChild != CHECK_NODE_ONLY) { + descendentCodeLength++; + } + + if (ancestorCodeLength > descendentCodeLength) { + return false; // if the descendent is shorter, it can't be a descendent + } + + // compare the sections for the ancestor to the descendent + for (int section = 0; section < ancestorCodeLength; section++) { + char sectionValueAncestor = getOctalCodeSectionValue(possibleAncestor, section); + char sectionValueDescendent; + if (ancestorCodeLength <= descendentCodeLength) { + sectionValueDescendent = getOctalCodeSectionValue(possibleDescendent, section); + } else { + assert(descendentsChild != CHECK_NODE_ONLY); + sectionValueDescendent = descendentsChild; + } + if (sectionValueAncestor != sectionValueDescendent) { + return false; // first non-match, means they don't match + } + } + + // they all match, so we are an ancestor + return true; +} diff --git a/libraries/shared/src/OctalCode.h b/libraries/shared/src/OctalCode.h index 228d5f72b5..477751ea7c 100644 --- a/libraries/shared/src/OctalCode.h +++ b/libraries/shared/src/OctalCode.h @@ -21,7 +21,6 @@ const int BLUE_INDEX = 2; void printOctalCode(unsigned char * octalCode); int bytesRequiredForCodeLength(unsigned char threeBitCodes); -bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode); int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode); unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber); int numberOfThreeBitSectionsInCode(unsigned char * octalCode); @@ -29,6 +28,9 @@ unsigned char* chopOctalCode(unsigned char* originalOctalCode, int chopLevels); unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode, bool includeColorSpace = false); +const int CHECK_NODE_ONLY = -1; +bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild = CHECK_NODE_ONLY); + // Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return // but other than that these do the same thing. float * firstVertexForCode(unsigned char * octalCode); diff --git a/libraries/voxels/src/JurisdictionMap.cpp b/libraries/voxels/src/JurisdictionMap.cpp index 5c1fc5c52f..b67963d8d6 100644 --- a/libraries/voxels/src/JurisdictionMap.cpp +++ b/libraries/voxels/src/JurisdictionMap.cpp @@ -56,8 +56,34 @@ void JurisdictionMap::init(unsigned char* rootOctalCode, const std::vector