Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
augustt198 committed Jul 18, 2024
1 parent e29f23d commit af897da
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
55 changes: 43 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -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
20 changes: 1 addition & 19 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

0 comments on commit af897da

Please sign in to comment.