Skip to content

Commit

Permalink
Renamed CHull to QHull, fixes #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidavdav committed Oct 10, 2016
1 parent 6d06b8f commit 0502b44
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright (c) 2013--2016 David A. van Leeuwen, Michael Krabbe Borregaard, Chris Binz, and others.

The Julia package "CHull" is licensed under a Better License.
The Julia package "QHull" is licensed under a Better License.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
CHull
QHull
=====
[![Build Status](https://travis-ci.org/davidavdav/CHull.jl.svg)](https://travis-ci.org/davidavdav/CHull.jl)
[![Build Status](https://travis-ci.org/davidavdav/QHull.jl.svg)](https://travis-ci.org/davidavdav/QHull.jl)


A Julia wrapper around a PyCall wrapper around `scipy.spatial.ConvexHull`, which uses the qhull Convex Hull library.

The qhull library for computing the convex hull of data points seems to be the standard and very widely used.

This module is a quick wrapper around a Python wrapper around the library, as suggested by [Miles Lubin](https://groups.google.com/d/topic/julia-users/e9m8t5W3TVs/discussion).
This module is a quick wrapper around a Python wrapper around the library, as suggested by [Miles Lubin](https://groups.google.com/d/topic/julia-users/e9m8t5W3TVs/discussion).

Synopsis
--------

```julia

using CHull
using QHull

p = rand(10,2)
ch = chull(p)
ch.points # original points
ch.vertices # indices to line segments forming the convex hull
ch.simplices # the simplexes forming the convex hull
show(ch)
```


4 changes: 2 additions & 2 deletions runtest.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env julia
include("src/CHull.jl")
using CHull
include("src/QHull.jl")
using QHull

cd("test")
include("test/runtests.jl")
26 changes: 11 additions & 15 deletions src/CHull.jl → src/QHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
## This code is licensed under the GNU General Public License, version 2
## See the file LICENSE in this distribution

module CHull
__precompile__(true)
module QHull

export Chull, chull, display, show

using PyCall
@pyimport scipy.spatial as spatial
const spatial = PyNULL()

function __init__()
copy!(spatial, pyimport_conda("scipy.spatial", "scipy"))
end

type Chull{T<:Real}
points::Array{T}
Expand All @@ -25,7 +30,7 @@ end

function chull{T<:Real}(x::Array{T})
r, c = size(x)
py = spatial.ConvexHull(x)
py = spatial[:ConvexHull](x)
points = convert(Array{T}, py["points"])
vertices = convert(Array{Int}, py["vertices"])
incone(vertices)
Expand All @@ -36,21 +41,12 @@ function chull{T<:Real}(x::Array{T})
Chull(points, vertices, simplices)
end

import Base.show
## I don't seem to be able to print newlines in the display()
#function display(t::TextDisplay, ch::Chull)
# display(t, string("Convex Hull of ", size(ch.points,1), " points in ", size(ch.points,2), "dimensions"))
# display(t, ch.vertices)
# display(t, ch.points[sort(ch.vertices[:,1]),:])
#end

## should I use print statements in show()
function show(io::IO, ch::Chull)
println(io, string("Convex Hull of ", size(ch.points,1), " points in ", size(ch.points,2), " dimensions"))
function Base.show(io::IO, ::MIME"text/plain", ch::Chull)
println(io, string("Convex Hull of ", size(ch.points, 1), " points in ", size(ch.points, 2), " dimensions"))
println(io, "Hull segment vertex indices:")
println(io, ch.vertices)
println(io, "Points on convex hull in original order:\n")
println(io, ch.points[sort(ch.vertices[:,1]),:])
println(io, ch.points[sort(ch.vertices[:, 1]), :])
end

using RecipesBase
Expand Down
2 changes: 1 addition & 1 deletion src/test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CHull
using QHull

p = rand(10,2)
ch = chull(p)
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Base.Test
import CHull
import QHull

pts = [-1.0 0;
1 1;
Expand All @@ -9,11 +9,11 @@ pts = [-1.0 0;
0 3;
-1 2]

hull = CHull.chull(pts)
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]]

## multi-dim
x = randn(1000, 5)
hull = CHull.chull(x)
hull = QHull.chull(x)

0 comments on commit 0502b44

Please sign in to comment.