#pragma once #include "compat/assert.hpp" #include "RTree.h" #include #include namespace floormat { constexpr inline bool rect_intersects(Vector2 min1, Vector2 max1, Vector2 min2, Vector2 max2) { return min1.x() < max2.x() && max1.x() > min2.x() && min1.y() < max2.y() && max1.y() > min2.y(); } } // namespace floormat RTREE_TEMPLATE template int RTREE_QUAL::Search(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], F&& callback) const { #ifndef FM_NO_DEBUG for(int index=0; index bool RTREE_QUAL::Search(Node* a_node, Rect* a_rect, int& a_foundCount, F&& callback) const { fm_assert(a_node); fm_assert(a_node->m_level >= 0); fm_assert(a_rect); if(a_node->IsInternalNode()) { // This is an internal node in the tree for(int index=0; index < a_node->m_count; ++index) { if(Overlap(a_rect, &a_node->m_branch[index].m_rect)) { if(!Search(a_node->m_branch[index].m_child, a_rect, a_foundCount, callback)) { // The callback indicated to stop searching return false; } } } } else { // This is a leaf node for(int index=0; index < a_node->m_count; ++index) { if(Overlap(a_rect, &a_node->m_branch[index].m_rect)) { ++a_foundCount; const Rect& r = a_node->m_branch[index].m_rect; if(!callback(a_node->m_branch[index].m_data, r)) return false; // Don't continue searching } } } return true; // Continue searching }