Skip to content

Commit 41e8184

Browse files
committed
use an interface function node_extent instead of GI.extent
This allows us to perform any STI compatible algorithm on trees that do not have extents but some other kind of extent like thing....like spherical caps!
1 parent d520c6e commit 41e8184

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/utils/SpatialTreeInterface/SpatialTreeInterface.jl

+23-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Extents
66
import GeoInterface as GI
77
import AbstractTrees
88

9-
# public isspatialtree, getchild, nchild, child_indices_extents
9+
# public isspatialtree, getchild, nchild, child_indices_extents, node_extent
1010
export query, do_query
1111

1212
# ## Interface
@@ -66,11 +66,29 @@ isleaf(node) = error("isleaf is not implemented for node type $(typeof(node))")
6666
Return an iterator over the indices and extents of the children of a node.
6767
6868
Each value of the iterator should take the form `(i, extent)`.
69+
70+
This can only be invoked on leaf nodes!
6971
"""
7072
function child_indices_extents(node)
7173
return zip(1:nchild(node), getchild(node))
7274
end
7375

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+
7492
# ## Query functions
7593
# These are generic functions that work with any spatial tree type that implements the interface.
7694

@@ -92,7 +110,7 @@ function do_query(f::F, predicate::P, node::N) where {F, P, N}
92110
end
93111
else
94112
for child in getchild(node)
95-
if predicate(GI.extent(child))
113+
if predicate(node_extent(child))
96114
@controlflow do_query(f, predicate, child)
97115
end
98116
end
@@ -156,20 +174,20 @@ function do_dual_query(f::F, predicate::P, node1::N1, node2::N2) where {F, P, N1
156174
end
157175
elseif isleaf(node1) # node2 is not a leaf, node1 is - recurse further into node2
158176
for child in getchild(node2)
159-
if predicate(GI.extent(node1), GI.extent(child))
177+
if predicate(node_extent(node1), node_extent(child))
160178
@controlflow do_dual_query(f, predicate, node1, child)
161179
end
162180
end
163181
elseif isleaf(node2) # node1 is not a leaf, node2 is - recurse further into node1
164182
for child in getchild(node1)
165-
if predicate(GI.extent(child), GI.extent(node2))
183+
if predicate(node_extent(child), node_extent(node2))
166184
@controlflow do_dual_query(f, predicate, child, node2)
167185
end
168186
end
169187
else # neither node is a leaf, recurse into both children
170188
for child1 in getchild(node1)
171189
for child2 in getchild(node2)
172-
if predicate(GI.extent(child1), GI.extent(child2))
190+
if predicate(node_extent(child1), node_extent(child2))
173191
@controlflow do_dual_query(f, predicate, child1, child2)
174192
end
175193
end

0 commit comments

Comments
 (0)