Skip to content

Commit 49494f8

Browse files
author
Max Freudenberg
committed
fix show for single points
1 parent 1c6e9df commit 49494f8

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/SortTileRecursiveTree.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ GI.extent(n::STRLeafNode) = foldl(Extents.union, n.extents)
3636

3737
function Base.show(io::IO, tree::SortTileRecursiveTree.STRtree)
3838
println(io, "STRtree")
39-
display(tree.rootnode.extent)
39+
if tree.rootnode isa STRNode
40+
display(tree.rootnode.extent)
41+
elseif tree.rootnode isa STRLeafNode
42+
display(foldl(Extents.union, tree.rootnode.extents))
43+
end
4044
end
4145

4246

test/runtests.jl

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,32 @@ import GeoInterface as GI
66

77

88
@testset "SortTileRecursiveTree.jl" begin
9-
x = 1:100
10-
y = 1:100
11-
points = AG.createpoint.(x, y')
12-
# polygons = AG.buffer.(points, 0.1)
13-
tree = STRtree(points)
14-
@test tree.rootnode isa SortTileRecursiveTree.STRNode
15-
@test tree.rootnode.children[1] isa SortTileRecursiveTree.STRNode
9+
@testset "Single point" begin
10+
point = AG.createpoint(1, 1)
11+
tree = STRtree([point])
12+
13+
# test that showing the thing works
14+
display(tree)
15+
16+
@test query(tree, Extent(X=(0, 1.5), Y=(0, 1.5))) == [1]
17+
@test query(tree, Extent(X=(0, 0.5), Y=(0, 0.5))) == []
18+
end
1619

17-
query_result = query(tree, Extent(X=(0, 100.5), Y=(0, 1.5)))
18-
@test query_result isa Vector{Int}
19-
@test length(query_result) == 100
20-
@test points[query_result] == points[:,1]
20+
@testset "Many points" begin
21+
x = 1:100
22+
y = 1:100
23+
points = AG.createpoint.(x, y')
24+
# polygons = AG.buffer.(points, 0.1)
25+
tree = STRtree(points)
26+
display(tree)
27+
28+
@test tree.rootnode isa SortTileRecursiveTree.STRNode
29+
@test tree.rootnode.children[1] isa SortTileRecursiveTree.STRNode
30+
31+
query_result = query(tree, Extent(X=(0, 100.5), Y=(0, 1.5)))
32+
@test query_result isa Vector{Int}
33+
@test length(query_result) == 100
34+
@test points[query_result] == points[:,1]
35+
@test query(tree, Extent(X=(0, 0.5), Y=(0, 0.5))) == []
36+
end
2137
end

0 commit comments

Comments
 (0)