@@ -6,7 +6,7 @@ import Extents
6
6
import GeoInterface as GI
7
7
import AbstractTrees
8
8
9
- # public isspatialtree, getchild, nchild, child_indices_extents
9
+ # public isspatialtree, getchild, nchild, child_indices_extents, node_extent
10
10
export query, do_query
11
11
12
12
# ## Interface
@@ -66,11 +66,29 @@ isleaf(node) = error("isleaf is not implemented for node type $(typeof(node))")
66
66
Return an iterator over the indices and extents of the children of a node.
67
67
68
68
Each value of the iterator should take the form `(i, extent)`.
69
+
70
+ This can only be invoked on leaf nodes!
69
71
"""
70
72
function child_indices_extents (node)
71
73
return zip (1 : nchild (node), getchild (node))
72
74
end
73
75
76
+ """
77
+ node_extent(node)
78
+
79
+ Return the extent like object of the node.
80
+ Falls back to `GI.extent` by default, which falls back
81
+ to `Extents.extent`.
82
+
83
+ Generally, defining `Extents.extent(node)` is sufficient here, and you
84
+ won't need to define this
85
+
86
+ The reason we don't use that directly is to give users of this interface
87
+ a way to define bounding boxes that are not extents, like spherical caps
88
+ and other such things.
89
+ """
90
+ node_extent (node) = GI. extent (node)
91
+
74
92
# ## Query functions
75
93
# These are generic functions that work with any spatial tree type that implements the interface.
76
94
@@ -92,7 +110,7 @@ function do_query(f::F, predicate::P, node::N) where {F, P, N}
92
110
end
93
111
else
94
112
for child in getchild (node)
95
- if predicate (GI . extent (child))
113
+ if predicate (node_extent (child))
96
114
@controlflow do_query (f, predicate, child)
97
115
end
98
116
end
@@ -156,20 +174,20 @@ function do_dual_query(f::F, predicate::P, node1::N1, node2::N2) where {F, P, N1
156
174
end
157
175
elseif isleaf (node1) # node2 is not a leaf, node1 is - recurse further into node2
158
176
for child in getchild (node2)
159
- if predicate (GI . extent (node1), GI . extent (child))
177
+ if predicate (node_extent (node1), node_extent (child))
160
178
@controlflow do_dual_query (f, predicate, node1, child)
161
179
end
162
180
end
163
181
elseif isleaf (node2) # node1 is not a leaf, node2 is - recurse further into node1
164
182
for child in getchild (node1)
165
- if predicate (GI . extent (child), GI . extent (node2))
183
+ if predicate (node_extent (child), node_extent (node2))
166
184
@controlflow do_dual_query (f, predicate, child, node2)
167
185
end
168
186
end
169
187
else # neither node is a leaf, recurse into both children
170
188
for child1 in getchild (node1)
171
189
for child2 in getchild (node2)
172
- if predicate (GI . extent (child1), GI . extent (child2))
190
+ if predicate (node_extent (child1), node_extent (child2))
173
191
@controlflow do_dual_query (f, predicate, child1, child2)
174
192
end
175
193
end
0 commit comments