1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! # AABB - Hilbert R-tree Spatial Index
//!
//! A Rust library providing a simple and efficient Hilbert R-tree implementation
//! for spatial queries on axis-aligned bounding boxes (AABBs).
//!
//! ## Features
//!
//! - **Hilbert Curve Ordering**: Uses Hilbert space-filling curve for improved spatial locality
//! - **AABB Intersection Queries**: Fast rectangular bounding box intersection testing
//! - **Simple API**: Easy to use with minimal setup
//! - **Static Optimization**: Efficient for static or infrequently-modified spatial data
//!
//!
//! ## Quick Start
//!
//! ```rust
//! use aabb::prelude::*;
//!
//! // Create a new spatial index
//! let mut tree = AABB::new();
//!
//! // Add some bounding boxes (min_x, min_y, max_x, max_y)
//! tree.add(0.0, 0.0, 2.0, 2.0); // Box 0: large box
//! tree.add(1.0, 1.0, 3.0, 3.0); // Box 1: overlapping box
//! tree.add(5.0, 5.0, 6.0, 6.0); // Box 2: distant box
//! tree.add(1.5, 1.5, 2.5, 2.5); // Box 3: small box inside others
//!
//! // Build the spatial index (required before querying)
//! tree.build();
//!
//! // Query for boxes intersecting a region
//! let mut results = Vec::new();
//! // minx, miny, maxx, maxy
//! tree.query_intersecting(1.2, 1.2, 2.8, 2.8, &mut results);
//!
//! // Results contains indices of intersecting boxes
//! println!("Found {} intersecting boxes: {:?}", results.len(), results);
//! // Output: Found 3 intersecting boxes: [0, 1, 3]
//!
//! // Query for boxes intersecting with an already-indexed item (no self-intersection)
//! let _ = tree.query_intersecting_id(0, &mut results);
//! println!("Boxes intersecting with box 0: {:?}", results);
//! // Output: Boxes intersecting with box 0: [1, 3]
//!
//! // You can reuse the results vector for multiple queries
//! tree.query_intersecting(4.0, 4.0, 7.0, 7.0, &mut results);
//! println!("Found {} boxes in distant region: {:?}", results.len(), results);
//! // Output: Found 1 boxes in distant region: [2]
//!
//! // Point queries - find boxes containing a specific point
//! tree.query_point(1.8, 1.8, &mut results);
//! println!("Point (1.8, 1.8) is in boxes: {:?}", results);
//!
//! // Containment queries - find boxes that contain a rectangle
//! tree.query_contain(1.2, 1.2, 1.8, 1.8, &mut results);
//! println!("Boxes containing rectangle: {:?}", results);
//!
//! // K-limited queries - find first K intersecting boxes for performance
//! tree.query_intersecting_k(0.0, 0.0, 3.0, 3.0, 2, &mut results);
//! println!("First 2 intersecting boxes: {:?}", results);
//!
//! // K-nearest neighbor queries - use k=1 for single nearest
//! tree.query_nearest_k(2.0, 2.0, 1, &mut results);
//! println!("Nearest box to (2.0, 2.0): {:?}", results);
//!
//! // Distance-based queries - find boxes in circular region
//! tree.query_circle(1.5, 1.5, 2.0, &mut results);
//! println!("Boxes in circle: {:?}", results);
//!
//! // K-nearest neighbor queries
//! tree.query_nearest_k(2.0, 2.0, 2, &mut results);
//! println!("2 nearest boxes to (2.0, 2.0): {:?}", results);
//!
//! // Directional queries - find boxes in rectangle's movement path
//! // Start with rectangle (1.5, 1.5) x (2.5, 2.5) and move right by distance 3
//! tree.query_in_direction(1.5, 1.5, 2.5, 2.5, 1.0, 0.0, 3.0, &mut results);
//! println!("Boxes intersecting movement path: {:?}", results);
//!
//! // Directional K-nearest queries - find K nearest boxes in movement path
//! tree.query_in_direction_k(1.5, 1.5, 2.5, 2.5, 1.0, 0.0, 2, 3.0, &mut results);
//! println!("2 nearest boxes in movement path: {:?}", results);
//!
//! ```
//!
//! ## Available Query Methods
//!
//! ### Basic Spatial Queries
//! - [`query_intersecting`] `(f64, i32)` - Find boxes that intersect a rectangle
//! - [`query_intersecting_id`] `(f64, i32)` - Find boxes that intersect an already-indexed item
//! - [`query_intersecting_k`] `(f64, i32)` - Find first K intersecting boxes
//! - [`query_point`] `(f64, i32)` - Find boxes that contain a point
//! - [`query_contain`] `(f64, i32)` - Find boxes that contain a rectangle
//! - [`query_contained_within`] `(f64, i32)` - Find boxes contained within a rectangle
//!
//! ### Distance-Based Queries
//! - [`query_nearest_k`] `(f64)` - Find K nearest boxes to a point (use k=1 for single nearest)
//! - [`query_circle`] `(f64)` - Find boxes intersecting a circular region
//!
//! ### Point-Specific Optimized Queries
//! - [`query_nearest_k_points`] `(f64)` - Find K nearest points (stored as (x, x, y, y)), sorted by distance
//! - [`query_circle_points`] `(f64)` - Find points within a circular region (optimized for point data)
//!
//! **Note:** Point-specific methods assume all items in the tree are stored as degenerate boxes (points)
//! where `min_x == max_x` and `min_y == max_y`. For mixed data (both points and boxes), use the general methods instead.
//!
//! ### Directional Queries
//! - [`query_in_direction`] `(f64)` - Find boxes intersecting a rectangle's movement path
//! - [`query_in_direction_k`] `(f64)` - Find K nearest boxes intersecting a rectangle's movement path
//!
//! [`query_intersecting`]: HilbertRTree::query_intersecting
//! [`query_intersecting_id`]: HilbertRTree::query_intersecting_id
//! [`query_intersecting_k`]: HilbertRTree::query_intersecting_k
//! [`query_point`]: HilbertRTree::query_point
//! [`query_contain`]: HilbertRTree::query_contain
//! [`query_contained_within`]: HilbertRTree::query_contained_within
//! [`query_nearest_k`]: HilbertRTree::query_nearest_k
//! [`query_circle`]: HilbertRTree::query_circle
//! [`query_nearest_k_points`]: HilbertRTree::query_nearest_k_points
//! [`query_circle_points`]: HilbertRTree::query_circle_points
//! [`query_in_direction`]: HilbertRTree::query_in_direction
//! [`query_in_direction_k`]: HilbertRTree::query_in_direction_k
//!
//! ## How It Works
//!
//! The Hilbert R-tree stores bounding boxes in a flat array and sorts them by their
//! Hilbert curve index (computed from box centers). This provides good spatial locality
//! for most spatial queries while maintaining a simple, cache-friendly data structure.
//!
//! The Hilbert curve is a space-filling curve that maps 2D coordinates to a 1D sequence
//! while preserving spatial locality - points that are close in 2D space tend to be
//! close in the 1D Hilbert ordering.
/// Core Hilbert R-tree spatial index data structure (flat sorted version)
/// Hierarchical Hilbert R-tree spatial index (flatbush-inspired)
/// Hierarchical Hilbert R-tree spatial index for i32 coordinates (memory-efficient)
/// Integration tests for the library
/// Comparison tests between both implementations
/// Component tests for granular method testing
/// Component tests for HilbertRTreeI32
/// Legacy query tests
/// Point-specific optimization tests
/// Prelude for convenient imports
pub use HilbertRTreeLeg;
pub use HilbertRTree;
pub use HilbertRTreeI32;
pub use ;
/// Add two unsigned 64-bit integers