From 0502b44e323ed25139cedaed75bf923696debab5 Mon Sep 17 00:00:00 2001 From: "David A. van Leeuwen" Date: Mon, 10 Oct 2016 12:37:57 +0200 Subject: [PATCH] Renamed CHull to QHull, fixes #8. We also used @stevengj's [advice](https://groups.google.com/d/msg/julia-users/oiz8bbykvag/uR4roTsFAwAJ) to not use @pyimport in a Module. --- LICENSE | 2 +- README.md | 11 +++++------ runtest.jl | 4 ++-- src/{CHull.jl => QHull.jl} | 26 +++++++++++--------------- src/test.jl | 2 +- test/runtests.jl | 6 +++--- 6 files changed, 23 insertions(+), 28 deletions(-) rename src/{CHull.jl => QHull.jl} (65%) diff --git a/LICENSE b/LICENSE index e070817..9a878a1 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index c928f8b..66c626b 100644 --- a/README.md +++ b/README.md @@ -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) ``` - - diff --git a/runtest.jl b/runtest.jl index fdb1f32..61208a4 100755 --- a/runtest.jl +++ b/runtest.jl @@ -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") diff --git a/src/CHull.jl b/src/QHull.jl similarity index 65% rename from src/CHull.jl rename to src/QHull.jl index b140f77..cb562b5 100644 --- a/src/CHull.jl +++ b/src/QHull.jl @@ -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} @@ -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) @@ -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 diff --git a/src/test.jl b/src/test.jl index 5d507d3..0a5a3be 100644 --- a/src/test.jl +++ b/src/test.jl @@ -1,4 +1,4 @@ -using CHull +using QHull p = rand(10,2) ch = chull(p) diff --git a/test/runtests.jl b/test/runtests.jl index 74b542a..e03399f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Base.Test -import CHull +import QHull pts = [-1.0 0; 1 1; @@ -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)