Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/QHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 8 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down