@@ -3,37 +3,53 @@ using Test
3
3
using GeometryOps. SpatialTreeInterface
4
4
using GeometryOps. SpatialTreeInterface: isspatialtree, isleaf, getchild, nchild, child_indices_extents, node_extent
5
5
using GeometryOps. SpatialTreeInterface: query, do_query, do_dual_query
6
+ using GeometryOps. SpatialTreeInterface: FlatNoTree
6
7
using Extents
7
8
using GeoInterface: GeoInterface as GI
9
+ using SortTileRecursiveTree: STRtree
8
10
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
-
11
+ # Generic test functions for spatial trees
12
+ function test_basic_interface (TreeType)
21
13
@testset " Basic interface" begin
14
+ # Create a simple tree with one extent
15
+ extents = [Extents. Extent (X= (0.0 , 1.0 ), Y= (0.0 , 1.0 ))]
16
+ tree = TreeType (extents)
17
+
22
18
@test isleaf (tree)
23
19
@test isspatialtree (tree)
24
20
@test isspatialtree (typeof (tree))
25
21
end
22
+ end
26
23
24
+ function test_child_indices_extents (TreeType)
27
25
@testset " child_indices_extents" begin
26
+ # Create a tree with three extents
27
+ extents = [
28
+ Extents. Extent (X= (0.0 , 1.0 ), Y= (0.0 , 1.0 )),
29
+ Extents. Extent (X= (1.0 , 2.0 ), Y= (1.0 , 2.0 )),
30
+ Extents. Extent (X= (2.0 , 3.0 ), Y= (2.0 , 3.0 ))
31
+ ]
32
+ tree = TreeType (extents)
33
+
28
34
# Test that we get the correct indices and extents
29
35
indices_extents = collect (child_indices_extents (tree))
30
36
@test length (indices_extents) == 3
31
37
@test indices_extents[1 ] == (1 , extents[1 ])
32
38
@test indices_extents[2 ] == (2 , extents[2 ])
33
39
@test indices_extents[3 ] == (3 , extents[3 ])
34
40
end
41
+ end
35
42
43
+ function test_query_functionality (TreeType)
36
44
@testset " Query functionality" begin
45
+ # Create a tree with three extents
46
+ extents = [
47
+ Extents. Extent (X= (0.0 , 1.0 ), Y= (0.0 , 1.0 )),
48
+ Extents. Extent (X= (1.0 , 2.0 ), Y= (1.0 , 2.0 )),
49
+ Extents. Extent (X= (2.0 , 3.0 ), Y= (2.0 , 3.0 ))
50
+ ]
51
+ tree = TreeType (extents)
52
+
37
53
# Test query with a predicate that matches all
38
54
all_pred = x -> true
39
55
results = query (tree, all_pred)
@@ -49,14 +65,16 @@ using GeometryOps.SpatialTreeInterface: FlatNoTree
49
65
results = query (tree, Base. Fix1 (Extents. intersects, search_extent))
50
66
@test sort (results) == [1 , 2 ] # Should match first two extents
51
67
end
68
+ end
52
69
70
+ function test_dual_query_functionality (TreeType)
53
71
@testset " Dual query functionality" begin
54
- # Create two trees for dual query testing
55
- tree1 = FlatNoTree ([
72
+ # Create two trees with overlapping extents
73
+ tree1 = TreeType ([
56
74
Extents. Extent (X= (0.0 , 1.0 ), Y= (0.0 , 1.0 )),
57
75
Extents. Extent (X= (1.0 , 2.0 ), Y= (1.0 , 2.0 ))
58
76
])
59
- tree2 = FlatNoTree ([
77
+ tree2 = TreeType ([
60
78
Extents. Extent (X= (0.5 , 1.5 ), Y= (0.5 , 1.5 )),
61
79
Extents. Extent (X= (1.5 , 2.5 ), Y= (1.5 , 2.5 ))
62
80
])
@@ -65,7 +83,7 @@ using GeometryOps.SpatialTreeInterface: FlatNoTree
65
83
all_pred = (x, y) -> true
66
84
results = Tuple{Int, Int}[]
67
85
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 )]
86
+ @test length (results) == 4 # 2 points in tree1 * 2 points in tree2
69
87
70
88
# Test dual query with a specific predicate
71
89
intersects_pred = (x, y) -> Extents. intersects (x, y)
@@ -75,3 +93,62 @@ using GeometryOps.SpatialTreeInterface: FlatNoTree
75
93
end
76
94
end
77
95
96
+ function test_geometry_support (TreeType)
97
+ @testset " Geometry support" begin
98
+ # Create a tree with 100 points
99
+ points = tuple .(1 : 100 , 1 : 100 )
100
+ tree = TreeType (points)
101
+
102
+ # Test basic interface
103
+ @test isleaf (tree)
104
+ @test isspatialtree (tree)
105
+ @test isspatialtree (typeof (tree))
106
+
107
+ # Test child indices and extents
108
+ indices_extents = collect (child_indices_extents (tree))
109
+ @test length (indices_extents) == 100
110
+
111
+ # Check first and last points
112
+ first_idx, first_extent = indices_extents[1 ]
113
+ last_idx, last_extent = indices_extents[100 ]
114
+
115
+ @test first_idx == 1
116
+ @test last_idx == 100
117
+ @test first_extent == Extents. Extent (X= (1.0 , 1.0 ), Y= (1.0 , 1.0 ))
118
+ @test last_extent == Extents. Extent (X= (100.0 , 100.0 ), Y= (100.0 , 100.0 ))
119
+
120
+ # Test query functionality
121
+ all_pred = x -> true
122
+ results = query (tree, all_pred)
123
+ @test sort (results) == collect (1 : 100 )
124
+
125
+ none_pred = x -> false
126
+ results = query (tree, none_pred)
127
+ @test isempty (results)
128
+
129
+ search_extent = Extents. Extent (X= (45.0 , 55.0 ), Y= (45.0 , 55.0 ))
130
+ results = query (tree, Base. Fix1 (Extents. intersects, search_extent))
131
+ @test sort (results) == collect (45 : 55 )
132
+ end
133
+ end
134
+
135
+ # Test FlatNoTree implementation
136
+ @testset " FlatNoTree" begin
137
+ test_basic_interface (FlatNoTree)
138
+ test_child_indices_extents (FlatNoTree)
139
+ test_query_functionality (FlatNoTree)
140
+ test_dual_query_functionality (FlatNoTree)
141
+ test_geometry_support (FlatNoTree)
142
+ end
143
+
144
+ # Test STRtree implementation
145
+ @testset " STRtree" begin
146
+ test_basic_interface (STRtree)
147
+ test_child_indices_extents (STRtree)
148
+ test_query_functionality (STRtree)
149
+ test_dual_query_functionality (STRtree)
150
+ test_geometry_support (STRtree)
151
+ end
152
+
153
+
154
+
0 commit comments