diff --git a/src/QHull.jl b/src/QHull.jl index ac7d866..2d598bc 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -18,28 +18,32 @@ function __init__() end type Chull{T<:Real} + area::T + equations::Matrix{T} + ndim::Int64 + max_bound::Vector{T} + min_bound::Vector{T} + neighbors::Matrix{Int32} + npoints::Int64 + nsimplex::Int64 points::Matrix{T} - vertices::Vector{Int} - simplices::Vector{Vector{Int}} - facets::Matrix{T} + simplices::Matrix{Int32} + vertices::Vector{Int32} + volume::T end -## helper for base-0 / base-1 difference -incone(x) = for i in 1:length(x) - x[i] += 1 -end function chull{T<:Real}(x::Matrix{T}) - 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"]) - Chull(points, vertices, simplices, facets) + + hull = spatial[:ConvexHull](x) + + ch = Chull([hull[field] for field in fieldnames(Chull)]...) + + # fix base-0 / base-1 difference + ch.vertices += 1 + ch.simplices += 1 + ch.neighbors += 1 + return ch end include("polyhedron.jl") diff --git a/src/polyhedron.jl b/src/polyhedron.jl index 9a677e2..5fc2190 100644 --- a/src/polyhedron.jl +++ b/src/polyhedron.jl @@ -73,8 +73,8 @@ function qhull{N, T}(h::SimpleVRepresentation{N, T}) ch = chull(V) V = ch.points[ch.vertices, :] vnored = SimpleVRepresentation(V) - A = ch.facets[:, 1:N] - b = ch.facets[:, N+1] + A = ch.equations[:, 1:N] + b = ch.equations[:, N+1] h = SimpleHRepresentation(A, b) vnored, h end @@ -97,7 +97,7 @@ function qhull{N, T<:Real}(h::SimpleHRepresentation{N, T}) ch = chull(B) C = ch.points[ch.vertices, :] hnored = SimpleHRepresentation(C, ones(size(C, 1))) - Vlift = ch.facets + Vlift = ch.equations nvreps = size(Vlift, 1) irays = IntSet() ipoints = IntSet() diff --git a/test/runtests.jl b/test/runtests.jl index cdd81f5..2790ae9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,9 +10,9 @@ pts = [-1.0 0; -1 2] hull = QHull.chull(pts) -@test hull.vertices == [1, 3, 4, 6, 7] +@test hull.vertices == Int32[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)