Exemple #1
0
        //Fills the provided vector with resultant points (points
        //contained in the specified range). Returns total results
        unsigned int queryRange(aabb& range, std::vector<T>& results)
        {
            //std::cout << bounds.x << " , " << bounds.y << " w " << bounds.w << " h " << bounds.h << " \n";
            unsigned int totalResults = 0;
            //Make sure range is touching this node
            if (!isColliding(&range, &bounds))
            {
                return 0;
            }
            
            //Add points in this node to results if contained in range
            for (typename std::list<QuadPoint<T> >::iterator it = data.begin(); it!=data.end(); ++it)
            {
                //std::cout << "has point\n";
                if (isPointInRange((*it).x, (*it).y, range))
                {
                    results.push_back((*it).data);
                    totalResults++;
                }
            }

            //Let all child nodes (if any) add points
            if (!tL)
            {
                return totalResults;
            }
            totalResults += tL->queryRange(range, results);
            totalResults += tR->queryRange(range, results);
            totalResults += bL->queryRange(range, results);
            totalResults += bR->queryRange(range, results);
            
            return totalResults;
        }
Exemple #2
0
        //Fills the provided array with resultant points (points
        //contained in the specified range). Returns total results
        //Pass in the maximum for the array as well as the index
        //this function should start at (usually 0)
        unsigned int queryRange(aabb& range, T* results, int& currentIndex, int maxPoints)
        {
            //std::cout << bounds.x << " , " << bounds.y << " w " << bounds.w << " h " << bounds.h << " \n";
            unsigned int totalResults = 0;
            //Make sure the array isn't full
            if (currentIndex >= maxPoints)
            {
                std::cout << "WARNING: queryPoints(): Results array full! (Max points = "<< maxPoints<< ")\n";
                return totalResults;
            }
            
            //Make sure range is touching this node
            if (!isColliding(&range, &bounds))
            {
                return 0;
            }
            
            //Add points in this node to results if contained in range
            for (typename std::list<QuadPoint<T> >::iterator it = data.begin(); it!=data.end(); ++it)
            {
                if (isPointInRange((*it).x, (*it).y, range))
                {
                    if (currentIndex < maxPoints)
                    {
                        results[currentIndex] = (*it).data;
                        totalResults++;
                        currentIndex++;
                    }
                    else
                    {
                        std::cout << "WARNING: queryPoints(): Results array full! (Max points = "<< maxPoints<< ")\n";
                        return totalResults;
                    }
                }
            }

            //Let all child nodes (if any) add points
            if (!tL)
            {
                return totalResults;
            }
            totalResults += tL->queryRange(range, results, currentIndex, maxPoints);
            totalResults += tR->queryRange(range, results, currentIndex, maxPoints);
            totalResults += bL->queryRange(range, results, currentIndex, maxPoints);
            totalResults += bR->queryRange(range, results, currentIndex, maxPoints);
            
            return totalResults;
        }