Skip to content

Commit 41a30eb

Browse files
authored
remove unnecessary conversions in QHull (#41)
closes #40
1 parent 391da0c commit 41a30eb

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/QHull.jl

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,19 @@ end
1818

1919
mutable struct Chull{T<:Real}
2020
points::Matrix{T}
21-
vertices::Vector{Int}
22-
simplices::Vector{Vector{Int}}
21+
vertices::Vector{Int32}
22+
simplices::Matrix{Int32}
2323
facets::Matrix{T}
2424
area::Float64
2525
volume::Float64
2626
end
2727

28-
## helper for base-0 / base-1 difference
29-
incone(x) = for i in 1:length(x)
30-
x[i] += 1
31-
end
32-
3328
function chull(x::Matrix{T}) where T<:Real
3429
py = spatial.ConvexHull(x)
35-
points = convert(Matrix{T}, py."points")
36-
vertices = convert(Vector{Int}, py."vertices")
37-
incone(vertices)
38-
simplices = convert(Vector{Vector{Int}}, py."simplices")
39-
for simplex in simplices
40-
incone(simplex)
41-
end
42-
facets = convert(Matrix{T}, py."equations")
43-
area = convert(Float64, py."area")
44-
volume = convert(Float64, py."volume")
45-
Chull(points, vertices, simplices, facets, area, volume)
30+
res = Chull(py.points, py.vertices, py.simplices, py.equations, py.area, py.volume)
31+
res.vertices .+= 1
32+
res.simplices .+= 1
33+
res
4634
end
4735

4836
include("polyhedron.jl")

test/runtests.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ using Test
22
import QHull
33

44
@testset "chull" begin
5-
pts = [-1.0 0;
6-
1 1;
7-
3 0;
8-
3 3;
9-
2 2;
10-
0 3;
11-
-1 2]
5+
pts = [-1.0 0
6+
1 1
7+
3 0
8+
3 3
9+
2 2
10+
0 3
11+
-1 2]
1212

1313
hull = QHull.chull(pts)
1414
@test hull.vertices == [1, 3, 4, 6, 7]
1515
@test size(hull.points) == size(pts)
16-
@test hull.simplices == Array{Int,1}[[3,1], [4,3], [6,4], [7,1], [7,6]]
16+
@test hull.simplices == Int32[3 1; 4 3; 6 4; 7 1; 7 6]
1717

1818
# multi-dim
1919
x = randn(1000, 5)

0 commit comments

Comments
 (0)