Skip to content

Commit d7e3e35

Browse files
committed
docs: Fix README and CONTRIBUTING inconsistencies with implementation
- Update README.md API Reference to match actual implementation - Add detailed parameter descriptions for all methods - Include missing getter methods for precision control - Fix insert() signature to show optional parameters - Add len() and n property documentation - Remove "(2D only)" from varargs query (works for 3D/4D too) - Add return type annotations for clarity - Update CONTRIBUTING.md project structure - Update file paths to reflect current project layout - Change cpp/ to include/prtree/core/ and src/cpp/bindings/ - Update Python wrapper path from __init__.py to core.py - Add pyproject.toml to project structure - Update test directory structure (unit/integration/e2e) All examples verified to work correctly with current implementation.
1 parent 2c6288d commit d7e3e35

File tree

2 files changed

+109
-27
lines changed

2 files changed

+109
-27
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ make quick # Quick test (clean + build + test)
103103
```
104104

105105
3. **Make changes**
106-
- C++ code: `cpp/prtree.h`, `cpp/main.cc`
107-
- Python wrapper: `src/python_prtree/__init__.py`
108-
- Tests: `tests/test_PRTree.py`
106+
- C++ core: `include/prtree/core/prtree.h`
107+
- Python bindings: `src/cpp/bindings/python_bindings.cc`
108+
- Python wrapper: `src/python_prtree/core.py`
109+
- Tests: `tests/unit/`, `tests/integration/`, `tests/e2e/`
109110

110111
4. **Build and test**
111112
```bash
@@ -144,7 +145,7 @@ make quick # Quick test (clean + build + test)
144145

145146
3. **Implement feature**
146147
```cpp
147-
// cpp/prtree.h
148+
// include/prtree/core/prtree.h
148149
// Add implementation
149150
```
150151

@@ -205,20 +206,30 @@ make test-coverage
205206

206207
```
207208
python_prtree/
208-
├── cpp/ # C++ implementation
209-
│ ├── prtree.h # PRTree core implementation
210-
│ ├── main.cc # Python bindings
211-
│ ├── parallel.h # Parallel processing utilities
212-
│ └── small_vector.h # Optimized vector
213-
├── src/python_prtree/ # Python wrapper
214-
│ └── __init__.py
209+
├── include/ # C++ public headers
210+
│ └── prtree/
211+
│ ├── core/ # Core algorithm headers
212+
│ │ └── prtree.h # PRTree core implementation
213+
│ └── utils/ # Utility headers
214+
│ ├── parallel.h # Parallel processing utilities
215+
│ └── small_vector.h # Optimized vector
216+
├── src/
217+
│ ├── cpp/ # C++ implementation
218+
│ │ └── bindings/ # Python bindings
219+
│ │ └── python_bindings.cc
220+
│ └── python_prtree/ # Python wrapper
221+
│ ├── __init__.py # Package entry point
222+
│ └── core.py # Main user-facing classes
215223
├── tests/ # Test suite
216-
│ └── test_PRTree.py
224+
│ ├── unit/ # Unit tests
225+
│ ├── integration/ # Integration tests
226+
│ └── e2e/ # End-to-end tests
217227
├── third/ # Third-party libraries (submodules)
218228
│ ├── pybind11/
219229
│ └── snappy/
220230
├── CMakeLists.txt # CMake configuration
221-
├── setup.py # Packaging configuration
231+
├── pyproject.toml # Project metadata and dependencies
232+
├── setup.py # Build configuration
222233
├── Makefile # Development workflow
223234
└── README.md # User documentation
224235
```

README.md

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ tree4d = PRTree4D(indices, boxes_4d) # 4D boxes
6767
```python
6868
# Query with point coordinates
6969
result = tree.query([0.5, 0.5]) # Returns indices
70-
result = tree.query(0.5, 0.5) # Varargs also supported (2D only)
70+
result = tree.query(0.5, 0.5) # Varargs also supported
7171
```
7272

7373
### Dynamic Updates
@@ -216,22 +216,93 @@ For detailed development setup, see [DEVELOPMENT.md](docs/DEVELOPMENT.md).
216216

217217
#### Constructor
218218
```python
219-
PRTree2D(indices=None, boxes=None)
220-
PRTree2D(filename) # Load from file
219+
PRTree2D() # Empty tree
220+
PRTree2D(indices, boxes) # With data
221+
PRTree2D(filename) # Load from file
221222
```
222223

224+
**Parameters:**
225+
- `indices` (optional): Array of integer indices for each bounding box
226+
- `boxes` (optional): Array of bounding boxes (shape: [n, 2*D] where D is dimension)
227+
- `filename` (optional): Path to saved tree file
228+
223229
#### Methods
224-
- `query(box, return_obj=False)` - Find overlapping boxes
225-
- `batch_query(boxes)` - Parallel batch queries
226-
- `query_intersections()` - Find all intersecting pairs
227-
- `insert(idx, bb, obj=None)` - Add box
228-
- `erase(idx)` - Remove box
229-
- `rebuild()` - Rebuild tree for optimal performance
230-
- `save(filename)` - Save to binary file
231-
- `load(filename)` - Load from binary file
232-
- `size()` - Get number of boxes
233-
- `get_obj(idx)` - Get stored object
234-
- `set_obj(idx, obj)` - Update stored object
230+
231+
**Query Methods:**
232+
- `query(*args, return_obj=False)``List[int]` or `List[Any]`
233+
- Find all bounding boxes that overlap with the query box or point
234+
- Accepts box coordinates as list/array or varargs (e.g., `query(x, y)` for 2D points)
235+
- Set `return_obj=True` to return associated objects instead of indices
236+
237+
- `batch_query(boxes)``List[List[int]]`
238+
- Parallel batch queries for multiple query boxes
239+
- Returns a list of result lists, one per query
240+
241+
- `query_intersections()``np.ndarray`
242+
- Find all pairs of intersecting bounding boxes
243+
- Returns array of shape (n_pairs, 2) containing index pairs
244+
245+
**Modification Methods:**
246+
- `insert(idx=None, bb=None, obj=None)``None`
247+
- Add a new bounding box to the tree
248+
- `idx`: Index for the box (auto-assigned if None)
249+
- `bb`: Bounding box coordinates (required)
250+
- `obj`: Optional Python object to associate with the box
251+
252+
- `erase(idx)``None`
253+
- Remove a bounding box by index
254+
255+
- `rebuild()``None`
256+
- Rebuild tree for optimal performance after many updates
257+
258+
**Persistence Methods:**
259+
- `save(filename)``None`
260+
- Save tree to binary file
261+
262+
- `load(filename)``None`
263+
- Load tree from binary file
264+
265+
**Object Storage Methods:**
266+
- `get_obj(idx)``Any`
267+
- Retrieve the Python object associated with a bounding box
268+
269+
- `set_obj(idx, obj)``None`
270+
- Update the Python object associated with a bounding box
271+
272+
**Size and Properties:**
273+
- `size()``int`
274+
- Get the number of bounding boxes in the tree
275+
276+
- `len(tree)``int`
277+
- Same as `size()`, allows using `len(tree)`
278+
279+
- `n``int` (property)
280+
- Get the number of bounding boxes (same as `size()`)
281+
282+
**Precision Control Methods:**
283+
- `set_adaptive_epsilon(enabled)``None`
284+
- Enable/disable adaptive epsilon based on box sizes
285+
286+
- `set_relative_epsilon(epsilon)``None`
287+
- Set relative epsilon for intersection tests
288+
289+
- `set_absolute_epsilon(epsilon)``None`
290+
- Set absolute epsilon for near-zero cases
291+
292+
- `set_subnormal_detection(enabled)``None`
293+
- Enable/disable subnormal number detection
294+
295+
- `get_adaptive_epsilon()``bool`
296+
- Check if adaptive epsilon is enabled
297+
298+
- `get_relative_epsilon()``float`
299+
- Get current relative epsilon value
300+
301+
- `get_absolute_epsilon()``float`
302+
- Get current absolute epsilon value
303+
304+
- `get_subnormal_detection()``bool`
305+
- Check if subnormal detection is enabled
235306

236307
## Version History
237308

0 commit comments

Comments
 (0)