| 818 | /************************************************************************/ |
| 819 | |
| 820 | static void CPLQuadTreeCollectFeatures(const CPLQuadTree *hQuadTree, |
| 821 | const QuadTreeNode *psNode, |
| 822 | const CPLRectObj *pAoi, |
| 823 | int *pnFeatureCount, int *pnMaxFeatures, |
| 824 | void ***pppFeatureList) |
| 825 | { |
| 826 | /* -------------------------------------------------------------------- */ |
| 827 | /* Does this psNode overlap the area of interest at all? If not, */ |
| 828 | /* return without adding to the list at all. */ |
| 829 | /* -------------------------------------------------------------------- */ |
| 830 | if (!CPL_RectOverlap(&psNode->rect, pAoi)) |
| 831 | return; |
| 832 | |
| 833 | /* -------------------------------------------------------------------- */ |
| 834 | /* Grow the list to hold the features on this psNode. */ |
| 835 | /* -------------------------------------------------------------------- */ |
| 836 | if (*pnFeatureCount + psNode->nFeatures > *pnMaxFeatures) |
| 837 | { |
| 838 | // TODO(schwehr): Symbolic constant. |
| 839 | *pnMaxFeatures = (*pnFeatureCount + psNode->nFeatures) * 2 + 20; |
| 840 | *pppFeatureList = static_cast<void **>( |
| 841 | CPLRealloc(*pppFeatureList, sizeof(void *) * *pnMaxFeatures)); |
| 842 | } |
| 843 | |
| 844 | /* -------------------------------------------------------------------- */ |
| 845 | /* Add the local features to the list. */ |
| 846 | /* -------------------------------------------------------------------- */ |
| 847 | for (int i = 0; i < psNode->nFeatures; i++) |
| 848 | { |
| 849 | if (hQuadTree->pfnGetBounds == nullptr && |
| 850 | hQuadTree->pfnGetBoundsEx == nullptr) |
| 851 | { |
| 852 | if (CPL_RectOverlap(&psNode->pasBounds[i], pAoi)) |
| 853 | (*pppFeatureList)[(*pnFeatureCount)++] = psNode->pahFeatures[i]; |
| 854 | } |
| 855 | else |
| 856 | { |
| 857 | CPLRectObj bounds; |
| 858 | if (hQuadTree->pfnGetBoundsEx) |
| 859 | hQuadTree->pfnGetBoundsEx(psNode->pahFeatures[i], |
| 860 | hQuadTree->pUserData, &bounds); |
| 861 | else |
| 862 | hQuadTree->pfnGetBounds(psNode->pahFeatures[i], &bounds); |
| 863 | |
| 864 | if (CPL_RectOverlap(&bounds, pAoi)) |
| 865 | (*pppFeatureList)[(*pnFeatureCount)++] = psNode->pahFeatures[i]; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /* -------------------------------------------------------------------- */ |
| 870 | /* Recurse to subnodes if they exist. */ |
| 871 | /* -------------------------------------------------------------------- */ |
| 872 | for (int i = 0; i < psNode->nNumSubNodes; i++) |
| 873 | { |
| 874 | if (psNode->apSubNode[i]) |
| 875 | CPLQuadTreeCollectFeatures(hQuadTree, psNode->apSubNode[i], pAoi, |
| 876 | pnFeatureCount, pnMaxFeatures, |
| 877 | pppFeatureList); |
no test coverage detected