diff --git a/src/QHull.jl b/src/QHull.jl index 28a884c..e8f820d 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -18,31 +18,19 @@ end mutable struct Chull{T<:Real} points::Matrix{T} - vertices::Vector{Int} - simplices::Vector{Vector{Int}} + vertices::Vector{Int32} + simplices::Matrix{Int32} facets::Matrix{T} area::Float64 volume::Float64 end -## helper for base-0 / base-1 difference -incone(x) = for i in 1:length(x) - x[i] += 1 -end - function chull(x::Matrix{T}) where T<:Real py = spatial.ConvexHull(x) - points = convert(Matrix{T}, py."points") - vertices = convert(Vector{Int}, py."vertices") - incone(vertices) - simplices = convert(Vector{Vector{Int}}, py."simplices") - for simplex in simplices - incone(simplex) - end - facets = convert(Matrix{T}, py."equations") - area = convert(Float64, py."area") - volume = convert(Float64, py."volume") - Chull(points, vertices, simplices, facets, area, volume) + res = Chull(py.points, py.vertices, py.simplices, py.equations, py.area, py.volume) + res.vertices .+= 1 + res.simplices .+= 1 + res end include("polyhedron.jl") diff --git a/test/runtests.jl b/test/runtests.jl index aee6396..331941d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,18 +2,18 @@ using Test import QHull @testset "chull" begin - pts = [-1.0 0; - 1 1; - 3 0; - 3 3; - 2 2; - 0 3; - -1 2] + pts = [-1.0 0 + 1 1 + 3 0 + 3 3 + 2 2 + 0 3 + -1 2] hull = QHull.chull(pts) @test hull.vertices == [1, 3, 4, 6, 7] @test size(hull.points) == size(pts) - @test hull.simplices == Array{Int,1}[[3,1], [4,3], [6,4], [7,1], [7,6]] + @test hull.simplices == Int32[3 1; 4 3; 6 4; 7 1; 7 6] # multi-dim x = randn(1000, 5)