diff --git a/src/SortTileRecursiveTree.jl b/src/SortTileRecursiveTree.jl index 271d0c5..4efecd2 100644 --- a/src/SortTileRecursiveTree.jl +++ b/src/SortTileRecursiveTree.jl @@ -36,7 +36,11 @@ GI.extent(n::STRLeafNode) = foldl(Extents.union, n.extents) function Base.show(io::IO, tree::SortTileRecursiveTree.STRtree) println(io, "STRtree") - display(tree.rootnode.extent) + if tree.rootnode isa STRNode + display(tree.rootnode.extent) + elseif tree.rootnode isa STRLeafNode + display(foldl(Extents.union, tree.rootnode.extents)) + end end diff --git a/test/runtests.jl b/test/runtests.jl index 5ec9e70..9443def 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,16 +6,32 @@ import GeoInterface as GI @testset "SortTileRecursiveTree.jl" begin - x = 1:100 - y = 1:100 - points = AG.createpoint.(x, y') - # polygons = AG.buffer.(points, 0.1) - tree = STRtree(points) - @test tree.rootnode isa SortTileRecursiveTree.STRNode - @test tree.rootnode.children[1] isa SortTileRecursiveTree.STRNode + @testset "Single point" begin + point = AG.createpoint(1, 1) + tree = STRtree([point]) + + # test that showing the thing works + display(tree) + + @test query(tree, Extent(X=(0, 1.5), Y=(0, 1.5))) == [1] + @test query(tree, Extent(X=(0, 0.5), Y=(0, 0.5))) == [] + end - query_result = query(tree, Extent(X=(0, 100.5), Y=(0, 1.5))) - @test query_result isa Vector{Int} - @test length(query_result) == 100 - @test points[query_result] == points[:,1] + @testset "Many points" begin + x = 1:100 + y = 1:100 + points = AG.createpoint.(x, y') + # polygons = AG.buffer.(points, 0.1) + tree = STRtree(points) + display(tree) + + @test tree.rootnode isa SortTileRecursiveTree.STRNode + @test tree.rootnode.children[1] isa SortTileRecursiveTree.STRNode + + query_result = query(tree, Extent(X=(0, 100.5), Y=(0, 1.5))) + @test query_result isa Vector{Int} + @test length(query_result) == 100 + @test points[query_result] == points[:,1] + @test query(tree, Extent(X=(0, 0.5), Y=(0, 0.5))) == [] + end end