mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 19:55:07 +02:00
got rid of compareOctalCodesDepth() and cleaned up compareOctalCodes()
This commit is contained in:
parent
ee814d7ddc
commit
8a5633a0db
3 changed files with 15 additions and 40 deletions
|
@ -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;
|
||||
|
|
|
@ -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__) */
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue