|
| 1 | +using Test |
| 2 | + |
| 3 | +using GeometryOps.SpatialTreeInterface |
| 4 | +using GeometryOps.SpatialTreeInterface: isspatialtree, isleaf, getchild, nchild, child_indices_extents, node_extent |
| 5 | +using GeometryOps.SpatialTreeInterface: query, do_query, do_dual_query |
| 6 | +using Extents |
| 7 | +using GeoInterface: GeoInterface as GI |
| 8 | + |
| 9 | +using GeometryOps.SpatialTreeInterface: FlatNoTree |
| 10 | + |
| 11 | +# Test FlatNoTree implementation |
| 12 | +@testset "FlatNoTree" begin |
| 13 | + # Test with a simple vector of extents |
| 14 | + extents = [ |
| 15 | + Extents.Extent(X=(0.0, 1.0), Y=(0.0, 1.0)), |
| 16 | + Extents.Extent(X=(1.0, 2.0), Y=(1.0, 2.0)), |
| 17 | + Extents.Extent(X=(2.0, 3.0), Y=(2.0, 3.0)) |
| 18 | + ] |
| 19 | + tree = FlatNoTree(extents) |
| 20 | + |
| 21 | + @testset "Basic interface" begin |
| 22 | + @test isleaf(tree) |
| 23 | + @test isspatialtree(tree) |
| 24 | + @test isspatialtree(typeof(tree)) |
| 25 | + end |
| 26 | + |
| 27 | + @testset "child_indices_extents" begin |
| 28 | + # Test that we get the correct indices and extents |
| 29 | + indices_extents = collect(child_indices_extents(tree)) |
| 30 | + @test length(indices_extents) == 3 |
| 31 | + @test indices_extents[1] == (1, extents[1]) |
| 32 | + @test indices_extents[2] == (2, extents[2]) |
| 33 | + @test indices_extents[3] == (3, extents[3]) |
| 34 | + end |
| 35 | + |
| 36 | + @testset "Query functionality" begin |
| 37 | + # Test query with a predicate that matches all |
| 38 | + all_pred = x -> true |
| 39 | + results = query(tree, all_pred) |
| 40 | + @test sort(results) == [1, 2, 3] |
| 41 | + |
| 42 | + # Test query with a predicate that matches none |
| 43 | + none_pred = x -> false |
| 44 | + results = query(tree, none_pred) |
| 45 | + @test isempty(results) |
| 46 | + |
| 47 | + # Test query with a specific extent predicate |
| 48 | + search_extent = Extents.Extent(X=(0.5, 1.5), Y=(0.5, 1.5)) |
| 49 | + results = query(tree, Base.Fix1(Extents.intersects, search_extent)) |
| 50 | + @test sort(results) == [1, 2] # Should match first two extents |
| 51 | + end |
| 52 | + |
| 53 | + @testset "Dual query functionality" begin |
| 54 | + # Create two trees for dual query testing |
| 55 | + tree1 = FlatNoTree([ |
| 56 | + Extents.Extent(X=(0.0, 1.0), Y=(0.0, 1.0)), |
| 57 | + Extents.Extent(X=(1.0, 2.0), Y=(1.0, 2.0)) |
| 58 | + ]) |
| 59 | + tree2 = FlatNoTree([ |
| 60 | + Extents.Extent(X=(0.5, 1.5), Y=(0.5, 1.5)), |
| 61 | + Extents.Extent(X=(1.5, 2.5), Y=(1.5, 2.5)) |
| 62 | + ]) |
| 63 | + |
| 64 | + # Test dual query with a predicate that matches all |
| 65 | + all_pred = (x, y) -> true |
| 66 | + results = Tuple{Int, Int}[] |
| 67 | + do_dual_query((i, j) -> push!(results, (i, j)), all_pred, tree1, tree2) |
| 68 | + @test sort(results) == [(1,1), (1,2), (2,1), (2,2)] |
| 69 | + |
| 70 | + # Test dual query with a specific predicate |
| 71 | + intersects_pred = (x, y) -> Extents.intersects(x, y) |
| 72 | + results = Tuple{Int, Int}[] |
| 73 | + do_dual_query((i, j) -> push!(results, (i, j)), intersects_pred, tree1, tree2) |
| 74 | + @test sort(results) == [(1,1), (2,1), (2,2)] |
| 75 | + end |
| 76 | +end |
| 77 | + |
0 commit comments