Skip to content

Commit bdabbcd

Browse files
committed
Merge pull request #27 from SimonDanisch/master
Make Contour.jl compatible with GLVisualize
2 parents 18d3653 + a096490 commit bdabbcd

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
language: julia
22
sudo: false
3+
os:
4+
- linux
5+
- osx
36
julia:
47
- nightly
5-
- release
68
- 0.4
7-
- 0.3
89
notifications:
910
- email: false
11+
script:
12+
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
13+
- julia --inline=no -e 'Pkg.clone(pwd()); Pkg.test("Contour"; coverage=true)'
14+
after_success:
15+
- julia -e 'cd(Pkg.dir("Contour")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ and `z` is a matrix arranged such that `z[xi,yi]` correspond to the location
2121

2222

2323
```julia
24-
x = [-3:0.01:3]
25-
y = [-4:0.02:5]
24+
x = -3:0.01:3
25+
y = -4:0.02:5
2626

27-
z = [(xi^2 + yi^2)::Float64 for xi in x, yi in y]
27+
z = [Float64((xi^2 + yi^2)) for xi in x, yi in y]
2828
```
2929

3030
Let's find the contour line corresponding to `z = 4.0`:
@@ -50,13 +50,13 @@ julia> c.lines
5050
[0.05,1.99937],[0.04,1.9996],[0.03,1.99977],[0.02,1.9999],[0.01,1.99997],
5151
[0.0,2.0]])
5252
```
53-
53+
5454
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
5555

5656
```julia
57-
type ContourLevel
58-
level::Float64
59-
lines::Vector{Curve2}
57+
type ContourLevel{T}
58+
level::T
59+
lines::Vector{Curve2{T}}
6060
end
6161
```
6262

@@ -73,8 +73,8 @@ julia> plot(xs, ys) # using your favorite plotting tool
7373

7474
`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.
7575

76-
We can also find the contours at multiple levels using `contours`,
77-
which returns an array of `ContourLevel` types.
76+
We can also find the contours at multiple levels using `contours`,
77+
which returns an array of `ContourLevel` types.
7878

7979
```julia
8080
julia> h = [4.0, 5.0, 6.0];
@@ -92,7 +92,7 @@ specify the number of levels we want.
9292
julia> N = 3;
9393
julia> c = contours(x, y, z, N)
9494
3-element Array{ContourLevel,1}:
95-
ContourLevel(8.5,[Curve2{Float64}([[0.62,2.84877],,[0.62,2.84877]])])
95+
ContourLevel(8.5,[Curve2{Float64}([[0.62,2.84877],,[0.62,2.84877]])])
9696
ContourLevel(17.0,[Curve2{Float64}([[3.0,2.82841],,[3.0,-2.82841]])])
9797
ContourLevel(25.5,[Curve2{Float64}([[3.0,4.06201],,[-3.0,4.06201]])])
9898
```

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
julia 0.3
1+
julia 0.4
22
Compat
3-
ImmutableArrays
3+
FixedSizeArrays

src/Contour.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module Contour
22

3-
using Compat, ImmutableArrays
3+
using Compat, FixedSizeArrays
44

55
export ContourLevel, Curve2, contour, contours, coordinates
66

77
type Curve2{T}
8-
vertices::Vector{Vector2{T}}
8+
vertices::Vector{Point{2,T}}
99
end
10-
Curve2{T}(::Type{T}) = Curve2(Vector2{T}[])
10+
Curve2{T}(::Type{T}) = Curve2(Point{2, T}[])
1111

12-
type ContourLevel
13-
level::Float64
14-
lines::Vector{Curve2{Float64}}
12+
type ContourLevel{T}
13+
level::T
14+
lines::Vector{Curve2{T}}
1515
end
16-
ContourLevel(h::Float64) = ContourLevel(h, Curve2{Float64}[])
17-
ContourLevel(h::Real) = ContourLevel(@compat Float64(h))
16+
ContourLevel{T<:AbstractFloat}(h::T) = ContourLevel(h, Curve2{T}[])
17+
ContourLevel{T}(h::T) = ContourLevel(Float64(h))
1818

1919
function contour(x, y, z, level::Number)
2020
# Todo: size checking on x,y,z
@@ -32,10 +32,10 @@ function contourlevels(z,n)
3232
range(zmin+dz,dz,n)
3333
end
3434

35-
function coordinates(c::Curve2)
35+
function coordinates{T}(c::Curve2{T})
3636
N = length(c.vertices)
37-
xlist = Array(Float64,N)
38-
ylist = Array(Float64,N)
37+
xlist = Array(T,N)
38+
ylist = Array(T,N)
3939

4040
for (i,v) in enumerate(c.vertices)
4141
xlist[i] = v[1]
@@ -144,9 +144,9 @@ const fwd, rev = (@compat UInt8(0)), (@compat UInt8(1))
144144

145145
function add_vertex!{T}(curve::Curve2{T}, pos::(@compat Tuple{T,T}), dir::UInt8)
146146
if dir == fwd
147-
push!(curve.vertices, Vector2{T}(pos...))
147+
push!(curve.vertices, Point{2,T}(pos...))
148148
else
149-
unshift!(curve.vertices, Vector2{T}(pos...))
149+
unshift!(curve.vertices, Point{2,T}(pos...))
150150
end
151151
end
152152

@@ -233,7 +233,7 @@ function trace_contour(x, y, z, h::Number, cells::Dict{(@compat Tuple{Int,Int}),
233233
# It then tries to trace the contour in the opposite direction.
234234

235235
while length(cells) > 0
236-
contour = Curve2(Float64)
236+
contour = Curve2(promote_type(map(eltype, (x,y,z))...))
237237

238238
# Pick initial box
239239
(xi_0, yi_0), cell = first(cells)

test/verify_vertices.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using ImmutableArrays
2-
31
# Setup test axes that will be shared among the tests
42

53
# Shift the axes so that they do not line up with
@@ -111,7 +109,7 @@ end
111109

112110
# Issue #12
113111
x = float(collect(1:3));
114-
y = copy(x);
112+
y = copy(x);
115113
z = eye(3,3);
116114
contours(x,y,z)
117115

@@ -139,7 +137,7 @@ for line in contourlevels.lines
139137
ys .== [v[2] for v in line.vertices]
140138
end
141139

142-
# Test that closed contours are identified correctly
140+
# Test that closed contours are identified correctly
143141
# when ambiguous cells are involved
144142

145143
Z = float([1 1 1 1 1 1

0 commit comments

Comments
 (0)