Skip to content

Commit 46bc7d2

Browse files
authored
add docstrings (#11)
1 parent ff7a83c commit 46bc7d2

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

rtree-capi/include/rtree-capi.h

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,88 @@ typedef struct RTreeH RTreeH;
1717

1818
typedef struct RTreeNodeH RTreeNodeH;
1919

20+
/**
21+
* Returns a new tree containing the given objects. The input arrays must have the same length.
22+
* Returns an empty tree if the input arrays are empty.
23+
* Supported dimensions are currently 1, 2, and 3. Returns an InvalidDimension error for unsupported dimensions.
24+
* You must free the returned tree with `rtree_free`.
25+
*/
2026
RTreeError rtree_bulk_load(struct RTreeH **tree,
2127
const double *mins,
2228
const double *maxs,
2329
const size_t *ids,
2430
size_t n,
2531
uint32_t dim);
2632

33+
/**
34+
* Returns a new empty tree with the given dimension.
35+
*/
2736
RTreeError rtree_create(struct RTreeH **tree, uint32_t dim);
2837

29-
RTreeError rtree_depth(const struct RTreeH *tree, size_t *depth_out);
38+
/**
39+
* Returns the depth of the tree, defined as the number of edges in the longest path from the root to a leaf.
40+
* An empty tree has depth 0.
41+
*/
42+
RTreeError rtree_depth(const struct RTreeH *tree,
43+
size_t *depth_out);
3044

45+
/**
46+
* Frees the given tree.
47+
*/
3148
RTreeError rtree_free(struct RTreeH *tree);
3249

50+
/**
51+
* Frees the ids returned by `rtree_locate_all_at_point`.
52+
*/
3353
RTreeError rtree_free_ids(size_t *ids, size_t n);
3454

55+
/**
56+
* Returns the dimension of the tree.
57+
*/
3558
RTreeError rtree_get_dimension(const struct RTreeH *tree, uint32_t *dim);
3659

60+
/**
61+
* Returns the ids of all objects in the tree that contain the given point.
62+
* If no objects contain the point, returns nids_out = 0.
63+
* You must free the returned ids with `rtree_free_ids`.
64+
*/
3765
RTreeError rtree_locate_all_at_point(const struct RTreeH *tree,
3866
const double *point,
3967
size_t **ids_out,
4068
size_t *nids_out);
4169

70+
/**
71+
* Returns the child nodes of a given node. You must free the returned child nodes with `rtree_node_children_free`.
72+
* If the node is a leaf, or a root node of an empty tree, returns nchildren = 0.
73+
*/
4274
RTreeError rtree_node_children(const struct RTreeNodeH *node,
4375
struct RTreeNodeH ***children,
4476
size_t *nchildren);
4577

78+
/**
79+
* Frees the child nodes returned by `rtree_node_children`.
80+
*/
4681
RTreeError rtree_node_children_free(struct RTreeNodeH **children, size_t n);
4782

83+
/**
84+
* Returns the minimum bounding box that covers all the boxes in the node.
85+
* Returns an EmptyNodeEnvelope error if given a root node of an empty tree, which has no envelope.
86+
*/
4887
RTreeError rtree_node_envelope(const struct RTreeNodeH *node, double *min_out, double *max_out);
4988

89+
/**
90+
* Frees the node returned by `rtree_root_node`.
91+
*/
5092
RTreeError rtree_node_free(struct RTreeNodeH *node);
5193

94+
/**
95+
* Returns the root node of a tree. You must free the returned node with `rtree_node_free`.
96+
* If the tree is empty, returns an EmptyNode.
97+
*/
5298
RTreeError rtree_root_node(const struct RTreeH *tree, struct RTreeNodeH **node);
5399

100+
/**
101+
* Returns the size of the tree, defined as the number of objects in the tree.
102+
* An empty tree has size 0.
103+
*/
54104
RTreeError rtree_size(const struct RTreeH *tree, size_t *size_out);

rtree-capi/src/node.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ enum NodeRef {
1515

1616
pub enum RTreeNodeH {}
1717

18+
/// Returns the root node of a tree. You must free the returned node with `rtree_node_free`.
19+
/// If the tree is empty, returns an EmptyNode.
1820
#[no_mangle]
1921
pub extern "C" fn rtree_root_node(tree: *const RTreeH, node: *mut *mut RTreeNodeH) -> RTreeError {
2022
if tree.is_null() || node.is_null() {
@@ -40,6 +42,8 @@ pub extern "C" fn rtree_root_node(tree: *const RTreeH, node: *mut *mut RTreeNode
4042
RTreeError::Success
4143
}
4244

45+
/// Returns the child nodes of a given node. You must free the returned child nodes with `rtree_node_children_free`.
46+
/// If the node is a leaf, or a root node of an empty tree, returns nchildren = 0.
4347
#[no_mangle]
4448
pub extern "C" fn rtree_node_children(
4549
node: *const RTreeNodeH,
@@ -115,6 +119,8 @@ fn write_aabb<const DIM: usize>(aabb: AABB<[f64; DIM]>, min_out: *mut f64, max_o
115119
}
116120
}
117121

122+
/// Returns the minimum bounding box that covers all the boxes in the node.
123+
/// Returns an EmptyNodeEnvelope error if given a root node of an empty tree, which has no envelope.
118124
#[no_mangle]
119125
pub extern "C" fn rtree_node_envelope(
120126
node: *const RTreeNodeH,
@@ -146,6 +152,7 @@ pub extern "C" fn rtree_node_envelope(
146152
RTreeError::Success
147153
}
148154

155+
/// Frees the node returned by `rtree_root_node`.
149156
#[no_mangle]
150157
pub extern "C" fn rtree_node_free(node: *mut RTreeNodeH) -> RTreeError {
151158
if node.is_null() {
@@ -155,6 +162,7 @@ pub extern "C" fn rtree_node_free(node: *mut RTreeNodeH) -> RTreeError {
155162
RTreeError::Success
156163
}
157164

165+
/// Frees the child nodes returned by `rtree_node_children`.
158166
#[no_mangle]
159167
pub extern "C" fn rtree_node_children_free(children: *mut *mut RTreeNodeH, n: usize) -> RTreeError {
160168
if children.is_null() {

rtree-capi/src/rtree.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum RTreeDim {
1616
// Opaque handle for C api
1717
pub enum RTreeH {}
1818

19+
/// Returns a new empty tree with the given dimension.
1920
#[no_mangle]
2021
pub extern "C" fn rtree_create(tree: *mut *mut RTreeH, dim: u32) -> RTreeError {
2122
if tree.is_null() {
@@ -31,6 +32,7 @@ pub extern "C" fn rtree_create(tree: *mut *mut RTreeH, dim: u32) -> RTreeError {
3132
RTreeError::Success
3233
}
3334

35+
/// Frees the given tree.
3436
#[no_mangle]
3537
pub extern "C" fn rtree_free(tree: *mut RTreeH) -> RTreeError {
3638
if tree.is_null() {
@@ -48,6 +50,7 @@ fn _rtree_get_dimension(tree: &RTreeDim) -> u32 {
4850
}
4951
}
5052

53+
/// Returns the dimension of the tree.
5154
#[no_mangle]
5255
pub extern "C" fn rtree_get_dimension(tree: *const RTreeH, dim: *mut u32) -> RTreeError {
5356
if tree.is_null() || dim.is_null() {
@@ -92,6 +95,10 @@ fn _interval_tree_bulk_load(
9295
IntervalTree::bulk_load(mins, maxs, data)
9396
}
9497

98+
/// Returns a new tree containing the given objects. The input arrays must have the same length.
99+
/// Returns an empty tree if the input arrays are empty.
100+
/// Supported dimensions are currently 1, 2, and 3. Returns an InvalidDimension error for unsupported dimensions.
101+
/// You must free the returned tree with `rtree_free`.
95102
#[no_mangle]
96103
pub extern "C" fn rtree_bulk_load(
97104
tree: *mut *mut RTreeH,
@@ -131,6 +138,9 @@ pub extern "C" fn rtree_bulk_load(
131138
RTreeError::Success
132139
}
133140

141+
/// Returns the ids of all objects in the tree that contain the given point.
142+
/// If no objects contain the point, returns nids_out = 0.
143+
/// You must free the returned ids with `rtree_free_ids`.
134144
#[no_mangle]
135145
pub extern "C" fn rtree_locate_all_at_point(
136146
tree: *const RTreeH,
@@ -168,6 +178,8 @@ pub extern "C" fn rtree_locate_all_at_point(
168178
RTreeError::Success
169179
}
170180

181+
/// Returns the size of the tree, defined as the number of objects in the tree.
182+
/// An empty tree has size 0.
171183
#[no_mangle]
172184
pub extern "C" fn rtree_size(tree: *const RTreeH, size_out: *mut usize) -> RTreeError {
173185
if tree.is_null() || size_out.is_null() {
@@ -207,6 +219,8 @@ fn _rtree_depth<T: RTreeObject>(node: &ParentNode<T>) -> usize {
207219
.unwrap_or(0)
208220
}
209221

222+
/// Returns the depth of the tree, defined as the number of edges in the longest path from the root to a leaf.
223+
/// An empty tree has depth 0.
210224
#[no_mangle]
211225
pub extern "C" fn rtree_depth(tree: *const RTreeH, depth_out: *mut usize) -> RTreeError {
212226
if tree.is_null() || depth_out.is_null() {
@@ -231,6 +245,7 @@ pub extern "C" fn rtree_depth(tree: *const RTreeH, depth_out: *mut usize) -> RTr
231245
RTreeError::Success
232246
}
233247

248+
/// Frees the ids returned by `rtree_locate_all_at_point`.
234249
#[no_mangle]
235250
pub extern "C" fn rtree_free_ids(ids: *mut usize, n: usize) -> RTreeError {
236251
if ids.is_null() {

0 commit comments

Comments
 (0)