From 8a5633a0dbe6b89e0fa0beef9eee6b2a8e0ab46a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Apr 2013 10:09:15 -0700 Subject: [PATCH] got rid of compareOctalCodesDepth() and cleaned up compareOctalCodes() --- libraries/shared/src/OctalCode.cpp | 38 ++++++--------------------- libraries/shared/src/OctalCode.h | 15 +++++------ libraries/voxels/src/VoxelNodeBag.cpp | 2 +- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index 62768569f1..da2b017875 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -135,54 +135,32 @@ float * firstVertexForCode(unsigned char * octalCode) { return firstVertex; } -OctalTreeDepth compareOctalCodesDepth(unsigned char* codeA, unsigned char* codeB) { +OctalCodeComparison compareOctalCodes(unsigned char* codeA, unsigned char* codeB) { if (!codeA || !codeB) { return ILLEGAL_CODE; } - OctalTreeDepth result = SHALLOWER; // assume it's shallower - int codeLenthA = numberOfThreeBitSectionsInCode(codeA); - int codeLenthB = numberOfThreeBitSectionsInCode(codeB); + OctalCodeComparison result = LESS_THAN; // assume it's shallower - if (codeLenthA > codeLenthB) { - result = DEEPER; - } else if (codeLenthA == codeLenthB) { - int numberOfBytes = bytesRequiredForCodeLength(*codeA); // they are the same!! - if (0 == memcmp(codeA,codeB,numberOfBytes)) { - result = EXACT_MATCH; - } else { - result = EQUAL_DEPTH; - } - } - return result; -} - -OctalTreeDepth compareOctalCodes(unsigned char* codeA, unsigned char* codeB) { - if (!codeA || !codeB) { - return ILLEGAL_CODE; - } - - OctalTreeDepth result = LESS_THAN; // assume it's shallower - - int numberOfBytes = std::min(bytesRequiredForCodeLength(*codeA),bytesRequiredForCodeLength(*codeB)); - int compare = memcmp(codeA,codeB,numberOfBytes); + int numberOfBytes = std::min(bytesRequiredForCodeLength(*codeA), bytesRequiredForCodeLength(*codeB)); + int compare = memcmp(codeA, codeB, numberOfBytes); if (compare < 0) { result = LESS_THAN; } else if (compare > 0) { result = GREATER_THAN; } else { - int codeLenthA = numberOfThreeBitSectionsInCode(codeA); - int codeLenthB = numberOfThreeBitSectionsInCode(codeB); + int codeLengthA = numberOfThreeBitSectionsInCode(codeA); + int codeLengthB = numberOfThreeBitSectionsInCode(codeB); - if (codeLenthA == codeLenthB) { + if (codeLengthA == codeLengthB) { // if the memcmp matched exactly, and they were the same length, // then these must be the same code! result = EXACT_MATCH; } else { // if the memcmp matched exactly, but they aren't the same length, // then they have a matching common parent, but they aren't the same - if (codeLenthA < codeLenthB) { + if (codeLengthA < codeLengthB) { result = LESS_THAN; } else { result = GREATER_THAN; diff --git a/libraries/shared/src/OctalCode.h b/libraries/shared/src/OctalCode.h index be939f2495..bf4a6ef699 100644 --- a/libraries/shared/src/OctalCode.h +++ b/libraries/shared/src/OctalCode.h @@ -24,14 +24,11 @@ float * firstVertexForCode(unsigned char * octalCode); void copyFirstVertexForCode(unsigned char * octalCode, float* output); typedef enum { - SHALLOWER, - EQUAL_DEPTH, - EXACT_MATCH, - DEEPER, - ILLEGAL_CODE, - GREATER_THAN, - LESS_THAN -} OctalTreeDepth; + ILLEGAL_CODE = -2, + LESS_THAN = -1, + EXACT_MATCH = 0, + GREATER_THAN = 1 +} OctalCodeComparison; -OctalTreeDepth compareOctalCodes(unsigned char* code1, unsigned char* code2); +OctalCodeComparison compareOctalCodes(unsigned char* code1, unsigned char* code2); #endif /* defined(__hifi__OctalCode__) */ diff --git a/libraries/voxels/src/VoxelNodeBag.cpp b/libraries/voxels/src/VoxelNodeBag.cpp index 370b2dac02..60ea2e47d4 100644 --- a/libraries/voxels/src/VoxelNodeBag.cpp +++ b/libraries/voxels/src/VoxelNodeBag.cpp @@ -39,7 +39,7 @@ void VoxelNodeBag::insert(VoxelNode* node) { for (int i = 0; i < _elementsInUse; i++) { // compare the newNode to the elements already in the bag - OctalTreeDepth comparison = compareOctalCodes(_bagElements[i]->octalCode,node->octalCode); + OctalCodeComparison comparison = compareOctalCodes(_bagElements[i]->octalCode,node->octalCode); // If we found a code in the bag that matches, then just return, since the element is already in the bag. if (comparison == EXACT_MATCH) {