static int SHPTreeNodeTrim( SHPTreeNode * psTreeNode ) { int i; /* -------------------------------------------------------------------- */ /* Trim subtrees, and free subnodes that come back empty. */ /* -------------------------------------------------------------------- */ for( i = 0; i < psTreeNode->nSubNodes; i++ ) { if( SHPTreeNodeTrim( psTreeNode->apsSubNode[i] ) ) { SHPDestroyTreeNode( psTreeNode->apsSubNode[i] ); psTreeNode->apsSubNode[i] = psTreeNode->apsSubNode[psTreeNode->nSubNodes-1]; psTreeNode->nSubNodes--; i--; /* process the new occupant of this subnode entry */ } } /* -------------------------------------------------------------------- */ /* We should be trimmed if we have no subnodes, and no shapes. */ /* -------------------------------------------------------------------- */ return( psTreeNode->nSubNodes == 0 && psTreeNode->nShapeCount == 0 ); }
static void SHPDestroyTreeNode( SHPTreeNode * psTreeNode ) { int i; for( i = 0; i < psTreeNode->nSubNodes; i++ ) { if( psTreeNode->apsSubNode[i] != NULL ) SHPDestroyTreeNode( psTreeNode->apsSubNode[i] ); } if( psTreeNode->panShapeIds != NULL ) free( psTreeNode->panShapeIds ); if( psTreeNode->papsShapeObj != NULL ) { for( i = 0; i < psTreeNode->nShapeCount; i++ ) { if( psTreeNode->papsShapeObj[i] != NULL ) SHPDestroyObject( psTreeNode->papsShapeObj[i] ); } free( psTreeNode->papsShapeObj ); } free( psTreeNode ); }
void SHPAPI_CALL SHPDestroyTree( SHPTree * psTree ) { SHPDestroyTreeNode( psTree->psRoot ); free( psTree ); }
static int SHPTreeNodeTrim( SHPTreeNode * psTreeNode ) { int i; /* -------------------------------------------------------------------- */ /* Trim subtrees, and free subnodes that come back empty. */ /* -------------------------------------------------------------------- */ for( i = 0; i < psTreeNode->nSubNodes; i++ ) { if( SHPTreeNodeTrim( psTreeNode->apsSubNode[i] ) ) { SHPDestroyTreeNode( psTreeNode->apsSubNode[i] ); psTreeNode->apsSubNode[i] = psTreeNode->apsSubNode[psTreeNode->nSubNodes-1]; psTreeNode->nSubNodes--; i--; /* process the new occupant of this subnode entry */ } } /* -------------------------------------------------------------------- */ /* If the current node has 1 subnode and no shapes, promote that */ /* subnode to the current node position. */ /* -------------------------------------------------------------------- */ if( psTreeNode->nSubNodes == 1 && psTreeNode->nShapeCount == 0) { SHPTreeNode* psSubNode = psTreeNode->apsSubNode[0]; memcpy(psTreeNode->adfBoundsMin, psSubNode->adfBoundsMin, sizeof(psSubNode->adfBoundsMin)); memcpy(psTreeNode->adfBoundsMax, psSubNode->adfBoundsMax, sizeof(psSubNode->adfBoundsMax)); psTreeNode->nShapeCount = psSubNode->nShapeCount; assert(psTreeNode->panShapeIds == NULL); psTreeNode->panShapeIds = psSubNode->panShapeIds; assert(psTreeNode->papsShapeObj == NULL); psTreeNode->papsShapeObj = psSubNode->papsShapeObj; psTreeNode->nSubNodes = psSubNode->nSubNodes; for( i = 0; i < psSubNode->nSubNodes; i++ ) psTreeNode->apsSubNode[i] = psSubNode->apsSubNode[i]; free(psSubNode); } /* -------------------------------------------------------------------- */ /* We should be trimmed if we have no subnodes, and no shapes. */ /* -------------------------------------------------------------------- */ return( psTreeNode->nSubNodes == 0 && psTreeNode->nShapeCount == 0 ); }