Skip to content

Commit

Permalink
fix show for single points
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Freudenberg committed Apr 18, 2024
1 parent 1c6e9df commit 49494f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/SortTileRecursiveTree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
38 changes: 27 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 49494f8

Please sign in to comment.