RTree
RTree
R-tree for efficient 2D spatial indexing and querying of bounding boxes. More…
#include <RTree.hpp>
Public Functions
| Name | |
|---|---|
| RTree() | |
| ~RTree() =default | |
| RTree(RTree && other) | |
| RTree & | operator=(RTree && other) |
| RTree(const RTree & ) =delete | |
| RTree & | operator=(const RTree & ) =delete |
| bool | insert(const BoundingBox & bbox, T data) Insert a bounding box with associated data into the R-tree. |
| bool | insert(float min_x, float min_y, float max_x, float max_y, T data) Insert a bounding box with associated data into the R-tree. |
| void | query(const BoundingBox & query_bounds, std::vector< RTreeEntry< T > > & results) const Query entries that intersect with a bounding box. |
| void | queryPointers(const BoundingBox & query_bounds, std::vector< const RTreeEntry< T > * > & results) const Query entries that intersect with a bounding box, returning pointers. |
| void | queryPoint(float x, float y, std::vector< RTreeEntry< T > > & results) const Find all entries that contain the given point. |
| void | queryPointPointers(float x, float y, std::vector< const RTreeEntry< T > * > & results) const Find all entries that contain the given point, returning pointers. |
| const RTreeEntry< T > * | findNearest(float x, float y, float max_distance) const Find the nearest entry to the given point within a maximum distance. |
| void | clear() Clear all entries from the R-tree. |
| size_t | size() const Get the total number of entries in the R-tree. |
| BoundingBox | getBounds() const Get the bounding box that encompasses all entries. |
Public Attributes
| Name | |
|---|---|
| int | MIN_ENTRIES |
| int | MAX_ENTRIES |
Detailed Description
template <typename T >
class RTree;R-tree for efficient 2D spatial indexing and querying of bounding boxes.
This implementation is optimized for storing and querying rectangular regions. It supports efficient “contains point” queries and nearest neighbor searches.
Public Functions Documentation
function RTree
inline RTree()function ~RTree
~RTree() =defaultfunction RTree
inline RTree(
RTree && other
)function operator=
inline RTree & operator=(
RTree && other
)function RTree
RTree(
const RTree &
) =deletefunction operator=
RTree & operator=(
const RTree &
) =deletefunction insert
inline bool insert(
const BoundingBox & bbox,
T data
)Insert a bounding box with associated data into the R-tree.
Parameters:
- bbox The bounding box to insert
- data Associated data
Return: True if successfully inserted
function insert
inline bool insert(
float min_x,
float min_y,
float max_x,
float max_y,
T data
)Insert a bounding box with associated data into the R-tree.
Parameters:
- min_x Minimum X coordinate
- min_y Minimum Y coordinate
- max_x Maximum X coordinate
- max_y Maximum Y coordinate
- data Associated data
Return: True if successfully inserted
function query
inline void query(
const BoundingBox & query_bounds,
std::vector< RTreeEntry< T > > & results
) constQuery entries that intersect with a bounding box.
Parameters:
- query_bounds The bounding box to search within
- results Vector to store found entries
function queryPointers
inline void queryPointers(
const BoundingBox & query_bounds,
std::vector< const RTreeEntry< T > * > & results
) constQuery entries that intersect with a bounding box, returning pointers.
Parameters:
- query_bounds The bounding box to search within
- results Vector to store pointers to found entries
function queryPoint
inline void queryPoint(
float x,
float y,
std::vector< RTreeEntry< T > > & results
) constFind all entries that contain the given point.
Parameters:
- x X coordinate
- y Y coordinate
- results Vector to store found entries
function queryPointPointers
inline void queryPointPointers(
float x,
float y,
std::vector< const RTreeEntry< T > * > & results
) constFind all entries that contain the given point, returning pointers.
Parameters:
- x X coordinate
- y Y coordinate
- results Vector to store pointers to found entries
function findNearest
inline const RTreeEntry< T > * findNearest(
float x,
float y,
float max_distance
) constFind the nearest entry to the given point within a maximum distance.
Parameters:
- x X coordinate to search near
- y Y coordinate to search near
- max_distance Maximum distance to search
Return: Pointer to the nearest entry, or nullptr if none found
function clear
inline void clear()Clear all entries from the R-tree.
function size
inline size_t size() constGet the total number of entries in the R-tree.
Return: Total entry count
function getBounds
inline BoundingBox getBounds() constGet the bounding box that encompasses all entries.
Return: The root bounding box
Public Attributes Documentation
variable MIN_ENTRIES
static int MIN_ENTRIES = 2;variable MAX_ENTRIES
static int MAX_ENTRIES = 8;Updated on 2026-11-13 at 20:25:40 +0000