diff --git a/test/Project.toml b/test/Project.toml index 9d8e734..8f27e0b 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] +GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" QHull = "a8468747-bd6f-53ef-9e5c-744dbc5c59e7" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/test/runtests.jl b/test/runtests.jl index 63fa37c..b17e8b8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,18 +1,14 @@ using Test -import Random - using Quickhull + import QHull +import GeometryBasics +import Random include("utils.jl") -function vertexset(facets) - foldl((s, f) -> union!(s, f.plane.point_indices), facets; init=Set{Int}()) -end -vertexset(hull::QHull.Chull) = Set(hull.vertices) - for D in (2, 3) - @testset verbose=true "$D-D hull" begin + @testset "$D-D hull" begin sample_ranges = Dict( gridbox => [5, 10, 20, 30], @@ -23,22 +19,57 @@ for D in (2, 3) for (sample_func, Ns) in sample_ranges @testset "$sample_func" begin for N in Ns - Random.seed!(1738 + 2) + Random.seed!(1234) pts = sample_func(N, D) pts_T = Matrix(pts') t1 = @elapsed begin - my_hull = quickhull(pts, Quickhull.Options(kernel=Quickhull.HyperplaneKernelExact_A)) + my_hull = quickhull(pts, Quickhull.Options(kernel=Quickhull.HyperplaneKernelExactSIMD)) end t2 = @elapsed begin their_hull = QHull.chull(pts_T) end my_facets = Quickhull.finished_facets(my_hull.facets) - println("Elapsed ($sample_func $D / $N): $t1 -- $t2 [$(length(my_facets)) facets] [$(size(their_hull.simplices))]") - @test Set(vertices(my_hull)) == vertexset(their_hull) + #println("Elapsed ($sample_func $D / $N): $t1 -- $t2 [$(length(my_facets)) facets] [$(size(their_hull.simplices))]") + @test Set(vertices(my_hull)) == Set(their_hull.vertices) end end end end end + +@testset "kernels" begin + Random.seed!(1234) + pts = sampleball(100_000, 3) + their_hull = QHull.chull(Matrix(pts')) + + Ks = (Quickhull.HyperplaneKernelInexact, + Quickhull.HyperplaneKernelExact_A, + Quickhull.HyperplaneKernelExactSIMD) + + for K ∈ Ks + my_hull = quickhull(pts, Quickhull.Options(kernel=K)) + @test Set(vertices(my_hull)) == Set(their_hull.vertices) + end +end + +@testset "inference" begin + @inferred quickhull([(rand(), rand()) for i = 1:100]) + @inferred quickhull([rand(SVector{3}) for i = 1:100]) + @inferred quickhull([rand(GeometryBasics.Point3f) for i = 1:100]) + + hull = quickhull([rand(GeometryBasics.Point3f) for i = 1:100]) + @inferred points(hull) + @inferred vertices(hull) + @inferred facets(hull) + + @inferred delaunay([(rand(), rand()) for i = 1:100]) + @inferred delaunay([rand(SVector{3}) for i = 1:100]) + @inferred delaunay([rand(GeometryBasics.Point3f) for i = 1:100]) + + tri = delaunay([rand(GeometryBasics.Point2f) for i = 1:100]) + @inferred points(tri) + @inferred vertices(tri) + @inferred facets(tri) +end diff --git a/test/utils.jl b/test/utils.jl index 34e2701..5ec8268 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -22,22 +22,4 @@ function gridbox(N, D) return reduce(hcat, pts) end -# function topocheck(hull, data) -# for f in hull.facets.arr -# if f.prev_handle != FLAG_INDEX_UNUSED -# for h_i in f.adj -# h = hull.facets.arr[h_i] - -# if f.handle ∉ h.adj -# display(data.newfacets) -# treeshow(f) -# treeshow(h) -# end -# @assert f.handle ∈ h.adj -# end -# end -# end -# end - -# 2^D vertices -#hypercube(D) = [float((idx >> i) & 1) for idx=0:(2^D-1), i=0:(D-1)] +hypercube(D) = [float((idx >> i) & 1) for idx=0:(2^D-1), i=0:(D-1)]