From 90eeb004fb4cb9517f0f8a1e0a6ec151bee274a4 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sun, 31 Jan 2016 13:36:30 +0100 Subject: [PATCH 1/5] use FixedSizeArrays and make usable with Float32 --- src/Contour.jl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Contour.jl b/src/Contour.jl index 251562a..ef424b4 100644 --- a/src/Contour.jl +++ b/src/Contour.jl @@ -1,20 +1,20 @@ module Contour -using Compat, ImmutableArrays +using Compat, FixedSizeArrays export ContourLevel, Curve2, contour, contours, coordinates type Curve2{T} - vertices::Vector{Vector2{T}} + vertices::Vector{Point{2,T}} end -Curve2{T}(::Type{T}) = Curve2(Vector2{T}[]) +Curve2{T}(::Type{T}) = Curve2(Point{2, T}[]) -type ContourLevel - level::Float64 - lines::Vector{Curve2{Float64}} +type ContourLevel{T} + level::T + lines::Vector{Curve2{T}} end -ContourLevel(h::Float64) = ContourLevel(h, Curve2{Float64}[]) -ContourLevel(h::Real) = ContourLevel(@compat Float64(h)) +ContourLevel{T<:AbstractFloat}(h::T) = ContourLevel(h, Curve2{T}[]) +ContourLevel{T}(h::T) = ContourLevel(Float64(h)) function contour(x, y, z, level::Number) # Todo: size checking on x,y,z @@ -32,10 +32,10 @@ function contourlevels(z,n) range(zmin+dz,dz,n) end -function coordinates(c::Curve2) +function coordinates{T}(c::Curve2{T}) N = length(c.vertices) - xlist = Array(Float64,N) - ylist = Array(Float64,N) + xlist = Array(T,N) + ylist = Array(T,N) for (i,v) in enumerate(c.vertices) xlist[i] = v[1] @@ -144,9 +144,9 @@ const fwd, rev = (@compat UInt8(0)), (@compat UInt8(1)) function add_vertex!{T}(curve::Curve2{T}, pos::(@compat Tuple{T,T}), dir::UInt8) if dir == fwd - push!(curve.vertices, Vector2{T}(pos...)) + push!(curve.vertices, Point{2,T}(pos...)) else - unshift!(curve.vertices, Vector2{T}(pos...)) + unshift!(curve.vertices, Point{2,T}(pos...)) end end @@ -233,7 +233,7 @@ function trace_contour(x, y, z, h::Number, cells::Dict{(@compat Tuple{Int,Int}), # It then tries to trace the contour in the opposite direction. while length(cells) > 0 - contour = Curve2(Float64) + contour = Curve2(promote_type(map(eltype, (x,y,z))...)) # Pick initial box (xi_0, yi_0), cell = first(cells) From 80890750aefb7479dac9098afc998182172c8580 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Sun, 31 Jan 2016 14:37:28 +0100 Subject: [PATCH 2/5] update REQUIRE and README --- README.md | 20 ++++++++++---------- REQUIRE | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e6d5508..4bf0bd5 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,10 @@ and `z` is a matrix arranged such that `z[xi,yi]` correspond to the location ```julia -x = [-3:0.01:3] -y = [-4:0.02:5] +x = -3:0.01:3 +y = -4:0.02:5 -z = [(xi^2 + yi^2)::Float64 for xi in x, yi in y] +z = [Float64((xi^2 + yi^2)) for xi in x, yi in y] ``` Let's find the contour line corresponding to `z = 4.0`: @@ -50,13 +50,13 @@ julia> c.lines [0.05,1.99937],[0.04,1.9996],[0.03,1.99977],[0.02,1.9999],[0.01,1.99997], [0.0,2.0]]) ``` - + The format of the output data is intented to give as extensive information as possible about the contour line, in a format that can be generalized in the future, if/when something like a [`Geometry.jl` package](https://groups.google.com/forum/#!topic/julia-dev/vZpZ8NBX_z8) is created. Each contour level is represented by an instance of ```julia -type ContourLevel - level::Float64 - lines::Vector{Curve2} +type ContourLevel{T} + level::T + lines::Vector{Curve2{T}} end ``` @@ -73,8 +73,8 @@ julia> plot(xs, ys) # using your favorite plotting tool `Contour.jl` makes sure that the coordinates are ordered correctly, and contours that close on themselves are given cyclically, so that e.g. `xs[1]==xs[end]` - in other words, plotting the contour does not require you to add the first point at the end manually to close the curve. -We can also find the contours at multiple levels using `contours`, -which returns an array of `ContourLevel` types. +We can also find the contours at multiple levels using `contours`, +which returns an array of `ContourLevel` types. ```julia julia> h = [4.0, 5.0, 6.0]; @@ -92,7 +92,7 @@ specify the number of levels we want. julia> N = 3; julia> c = contours(x, y, z, N) 3-element Array{ContourLevel,1}: - ContourLevel(8.5,[Curve2{Float64}([[0.62,2.84877],…,[0.62,2.84877]])]) + ContourLevel(8.5,[Curve2{Float64}([[0.62,2.84877],…,[0.62,2.84877]])]) ContourLevel(17.0,[Curve2{Float64}([[3.0,2.82841],…,[3.0,-2.82841]])]) ContourLevel(25.5,[Curve2{Float64}([[3.0,4.06201],…,[-3.0,4.06201]])]) ``` diff --git a/REQUIRE b/REQUIRE index 9918c99..cfcb150 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ -julia 0.3 +julia 0.4 Compat -ImmutableArrays +FixedSizeArrays From 5a449636a968dc4584b01e8c482a6045e5ac7f2e Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Sun, 31 Jan 2016 14:51:01 +0100 Subject: [PATCH 3/5] remove usage of ImmutableArrays --- test/verify_vertices.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/verify_vertices.jl b/test/verify_vertices.jl index 6d8864c..19e714f 100644 --- a/test/verify_vertices.jl +++ b/test/verify_vertices.jl @@ -1,5 +1,3 @@ -using ImmutableArrays - # Setup test axes that will be shared among the tests # Shift the axes so that they do not line up with @@ -111,7 +109,7 @@ end # Issue #12 x = float(collect(1:3)); -y = copy(x); +y = copy(x); z = eye(3,3); contours(x,y,z) @@ -139,7 +137,7 @@ for line in contourlevels.lines ys .== [v[2] for v in line.vertices] end -# Test that closed contours are identified correctly +# Test that closed contours are identified correctly # when ambiguous cells are involved Z = float([1 1 1 1 1 1 From 99fcc243b8623a637143c47bfab784d72ea2aa98 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Sun, 31 Jan 2016 14:53:43 +0100 Subject: [PATCH 4/5] remove unsupported julia versions --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58e3acd..da1f4cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: julia sudo: false julia: - nightly - - release - 0.4 - - 0.3 notifications: - email: false From a096490dc0e930122935695e8655cc81541d66fe Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Sun, 31 Jan 2016 14:56:39 +0100 Subject: [PATCH 5/5] add coverage and osx --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index da1f4cb..7c72105 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,15 @@ language: julia sudo: false +os: + - linux + - osx julia: - nightly - 0.4 notifications: - email: false +script: + - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi + - julia --inline=no -e 'Pkg.clone(pwd()); Pkg.test("Contour"; coverage=true)' +after_success: + - julia -e 'cd(Pkg.dir("Contour")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'