mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 22:13:12 +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;
|
return firstVertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
OctalTreeDepth compareOctalCodesDepth(unsigned char* codeA, unsigned char* codeB) {
|
OctalCodeComparison compareOctalCodes(unsigned char* codeA, unsigned char* codeB) {
|
||||||
if (!codeA || !codeB) {
|
if (!codeA || !codeB) {
|
||||||
return ILLEGAL_CODE;
|
return ILLEGAL_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OctalTreeDepth result = SHALLOWER; // assume it's shallower
|
OctalCodeComparison result = LESS_THAN; // assume it's shallower
|
||||||
int codeLenthA = numberOfThreeBitSectionsInCode(codeA);
|
|
||||||
int codeLenthB = numberOfThreeBitSectionsInCode(codeB);
|
|
||||||
|
|
||||||
if (codeLenthA > codeLenthB) {
|
int numberOfBytes = std::min(bytesRequiredForCodeLength(*codeA), bytesRequiredForCodeLength(*codeB));
|
||||||
result = DEEPER;
|
int compare = memcmp(codeA, codeB, numberOfBytes);
|
||||||
} 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);
|
|
||||||
|
|
||||||
if (compare < 0) {
|
if (compare < 0) {
|
||||||
result = LESS_THAN;
|
result = LESS_THAN;
|
||||||
} else if (compare > 0) {
|
} else if (compare > 0) {
|
||||||
result = GREATER_THAN;
|
result = GREATER_THAN;
|
||||||
} else {
|
} else {
|
||||||
int codeLenthA = numberOfThreeBitSectionsInCode(codeA);
|
int codeLengthA = numberOfThreeBitSectionsInCode(codeA);
|
||||||
int codeLenthB = numberOfThreeBitSectionsInCode(codeB);
|
int codeLengthB = numberOfThreeBitSectionsInCode(codeB);
|
||||||
|
|
||||||
if (codeLenthA == codeLenthB) {
|
if (codeLengthA == codeLengthB) {
|
||||||
// if the memcmp matched exactly, and they were the same length,
|
// if the memcmp matched exactly, and they were the same length,
|
||||||
// then these must be the same code!
|
// then these must be the same code!
|
||||||
result = EXACT_MATCH;
|
result = EXACT_MATCH;
|
||||||
} else {
|
} else {
|
||||||
// if the memcmp matched exactly, but they aren't the same length,
|
// 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
|
// then they have a matching common parent, but they aren't the same
|
||||||
if (codeLenthA < codeLenthB) {
|
if (codeLengthA < codeLengthB) {
|
||||||
result = LESS_THAN;
|
result = LESS_THAN;
|
||||||
} else {
|
} else {
|
||||||
result = GREATER_THAN;
|
result = GREATER_THAN;
|
||||||
|
|
|
@ -24,14 +24,11 @@ float * firstVertexForCode(unsigned char * octalCode);
|
||||||
void copyFirstVertexForCode(unsigned char * octalCode, float* output);
|
void copyFirstVertexForCode(unsigned char * octalCode, float* output);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SHALLOWER,
|
ILLEGAL_CODE = -2,
|
||||||
EQUAL_DEPTH,
|
LESS_THAN = -1,
|
||||||
EXACT_MATCH,
|
EXACT_MATCH = 0,
|
||||||
DEEPER,
|
GREATER_THAN = 1
|
||||||
ILLEGAL_CODE,
|
} OctalCodeComparison;
|
||||||
GREATER_THAN,
|
|
||||||
LESS_THAN
|
|
||||||
} OctalTreeDepth;
|
|
||||||
|
|
||||||
OctalTreeDepth compareOctalCodes(unsigned char* code1, unsigned char* code2);
|
OctalCodeComparison compareOctalCodes(unsigned char* code1, unsigned char* code2);
|
||||||
#endif /* defined(__hifi__OctalCode__) */
|
#endif /* defined(__hifi__OctalCode__) */
|
||||||
|
|
|
@ -39,7 +39,7 @@ void VoxelNodeBag::insert(VoxelNode* node) {
|
||||||
for (int i = 0; i < _elementsInUse; i++) {
|
for (int i = 0; i < _elementsInUse; i++) {
|
||||||
|
|
||||||
// compare the newNode to the elements already in the bag
|
// 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 we found a code in the bag that matches, then just return, since the element is already in the bag.
|
||||||
if (comparison == EXACT_MATCH) {
|
if (comparison == EXACT_MATCH) {
|
||||||
|
|
Loading…
Reference in a new issue