Skip to content

Commit 476cf2f

Browse files
committed
Test all single accelerators in poly clipping tests
1 parent 5391a78 commit 476cf2f

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

test/methods/clipping/polygon_clipping.jl

+30-25
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test_pairs = [
166166
const ϵ = 1e-10
167167
# Compare clipping results from GeometryOps and LibGEOS
168168
function compare_GO_LG_clipping(GO_f, LG_f, p1, p2)
169-
GO_result_list = GO_f(p1, p2; target = GI.PolygonTrait())
169+
170170
LG_result_geom = LG_f(p1, p2)
171171
if LG_result_geom isa LG.GeometryCollection
172172
poly_list = LG.Polygon[]
@@ -175,38 +175,43 @@ function compare_GO_LG_clipping(GO_f, LG_f, p1, p2)
175175
end
176176
LG_result_geom = LG.MultiPolygon(poly_list)
177177
end
178-
# Check if nothing is returned
179-
if isempty(GO_result_list) && (LG.isEmpty(LG_result_geom) || LG.area(LG_result_geom) == 0)
180-
return true
181-
end
182-
# Check for unnecessary points
183-
if sum(GI.npoint, GO_result_list; init = 0.0) > GI.npoint(LG_result_geom)
184-
return false
185-
end
186-
# Make sure last point is repeated
187-
for poly in GO_result_list
188-
for ring in GI.getring(poly)
189-
GI.getpoint(ring, 1) != GI.getpoint(ring, GI.npoint(ring)) && return false
178+
179+
for _accelerator in (GO.AutoAccelerator(), GO.NestedLoop(), GO.SingleSTRtree(), GO.SingleNaturalTree(), #=GO.DoubleNaturalTree(), =# #=GO.ThinnedDoubleNaturalTree(), =# #=GO.DoubleSTRtree()=#)
180+
@testset let accelerator = _accelerator # this is a ContextTestSet that is otherwise invisible but adds context to the testset
181+
GO_result_list = GO_f(GO.FosterHormannClipping(accelerator), p1, p2; target = GI.PolygonTrait())
182+
# Check if nothing is returned
183+
if isempty(GO_result_list) && (LG.isEmpty(LG_result_geom) || LG.area(LG_result_geom) == 0)
184+
@test true
185+
continue
186+
end
187+
# Check for unnecessary points
188+
@test !(sum(GI.npoint, GO_result_list; init = 0.0) > GI.npoint(LG_result_geom))
189+
# Make sure last point is repeated
190+
for poly in GO_result_list
191+
for ring in GI.getring(poly)
192+
@test !(GI.getpoint(ring, 1) != GI.getpoint(ring, GI.npoint(ring)))
193+
end
190194
end
191-
end
192195

193-
# Check if polygons cover the same area
194-
local GO_result_geom
195-
if length(GO_result_list) == 1
196-
GO_result_geom = GO_result_list[1]
197-
else
198-
GO_result_geom = GI.MultiPolygon(GO_result_list)
199-
end
200-
diff_1_area = LG.area(LG.difference(GO_result_geom, LG_result_geom))
201-
diff_2_area = LG.area(LG.difference(LG_result_geom, GO_result_geom))
202-
return diff_1_area ϵ && diff_2_area ϵ
196+
# Check if polygons cover the same area
197+
local GO_result_geom
198+
if length(GO_result_list) == 1
199+
GO_result_geom = GO_result_list[1]
200+
else
201+
GO_result_geom = GI.MultiPolygon(GO_result_list)
202+
end
203+
diff_1_area = LG.area(LG.difference(GO_result_geom, LG_result_geom))
204+
diff_2_area = LG.area(LG.difference(LG_result_geom, GO_result_geom))
205+
@test diff_1_area ϵ && diff_2_area ϵ
206+
end # testset
207+
end # loop
203208
end
204209

205210
# Test clipping functions and print error message if tests fail
206211
function test_clipping(GO_f, LG_f, f_name)
207212
for (p1, p2, sg1, sg2, sdesc) in test_pairs
208213
@testset_implementations "$sg1 $f_name $sg2 - $sdesc" begin
209-
@test compare_GO_LG_clipping(GO_f, LG_f, $p1, $p2)
214+
compare_GO_LG_clipping(GO_f, LG_f, $p1, $p2) # this executes tests internally
210215
end
211216
end
212217
return

0 commit comments

Comments
 (0)