Skip to content

Commit daad6eb

Browse files
authored
fix 0.7 deprecations and drop 0.5 (#40)
* fix 0.7 deprecation warnings * remove mutability on some wrappers
1 parent f1b6713 commit daad6eb

File tree

5 files changed

+72
-72
lines changed

5 files changed

+72
-72
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ sudo: false
33
os:
44
- linux
55
julia:
6-
- 0.5
76
- 0.6
7+
- nightly
88
notifications:
99
- email: false
1010
after_success:

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
julia 0.5
1+
julia 0.6
22
Compat 0.9.4
33
StaticArrays

src/Contour.jl

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ __precompile__()
22

33
module Contour
44

5-
using Compat, StaticArrays
5+
using StaticArrays
66

77
export
88
ContourLevel,
@@ -16,21 +16,21 @@ export
1616

1717
import Base: push!, start, next, done, length, eltype, show
1818

19-
type Curve2{T}
19+
struct Curve2{T}
2020
vertices::Vector{SVector{2,T}}
2121
end
22-
Curve2{T}(::Type{T}) = Curve2(SVector{2, T}[])
22+
Curve2(::Type{T}) where {T} = Curve2(SVector{2,T}[])
2323
show(io::IO, ::MIME"text/plain", c2::Curve2) = write(io, "$(typeof(c2))\n with $(length(c2.vertices)-1) vertices")
24-
show{TC<:Curve2}(io::IO, ::MIME"text/plain", c2s::Vector{TC}) = write(io, "$(typeof(c2s))\n $(length(c2s)) contour line(s)")
24+
show(io::IO, ::MIME"text/plain", c2s::Vector{TC}) where {TC <: Curve2} = write(io, "$(typeof(c2s))\n $(length(c2s)) contour line(s)")
2525

26-
type ContourLevel{T}
26+
struct ContourLevel{T}
2727
level::T
2828
lines::Vector{Curve2{T}}
2929
end
30-
ContourLevel{T<:AbstractFloat}(h::T) = ContourLevel(h, Curve2{T}[])
31-
ContourLevel{T}(h::T) = ContourLevel(Float64(h))
30+
ContourLevel(h::T) where {T <: AbstractFloat} = ContourLevel(h, Curve2{T}[])
31+
ContourLevel(h::T) where {T} = ContourLevel(Float64(h))
3232
show(io::IO, ::MIME"text/plain", cl::ContourLevel) = write(io, "$(typeof(cl))\n at $(level(cl)) with $(length(lines(cl))) line(s)")
33-
show{CL<:ContourLevel}(io::IO, ::MIME"text/plain", cls::Vector{CL}) = write(io, "$(typeof(cls))\n $(length(cls)) contour level(s)")
33+
show(io::IO, ::MIME"text/plain", cls::Vector{CL}) where {CL <: ContourLevel} = write(io, "$(typeof(cls))\n $(length(cls)) contour level(s)")
3434
"""
3535
`lines(c)` Extracts an iterable collection of isolines from a contour level.
3636
Use [`coordinates`](@ref) to get the coordinates of a line.
@@ -41,11 +41,11 @@ lines(cl::ContourLevel) = cl.lines
4141
"""
4242
level(cl::ContourLevel) = cl.level
4343

44-
immutable ContourCollection{Tlevel<:ContourLevel}
44+
struct ContourCollection{Tlevel<:ContourLevel}
4545
contours::Vector{Tlevel}
4646
end
4747
ContourCollection() = ContourCollection(Float64)
48-
ContourCollection{Tlevel}(::Type{Tlevel}) = ContourCollection(ContourLevel{Tlevel}[])
48+
ContourCollection(::Type{Tlevel}) where {Tlevel} = ContourCollection(ContourLevel{Tlevel}[])
4949
show(io::IO, ::MIME"text/plain", cc::ContourCollection) = write(io, "$(typeof(cc))\n with $(length(levels(cc))) level(s).")
5050

5151
"""
@@ -64,7 +64,7 @@ over the result.
6464
"""
6565
function contour(x, y, z, level::Number)
6666
# Todo: size checking on x,y,z
67-
trace_contour(x, y, z,level,get_level_cells(z,level))
67+
trace_contour(x, y, z, level, get_level_cells(z, level))
6868
end
6969

7070
"""
@@ -78,41 +78,41 @@ contours(::Any...) = error("This method exists only for documentation purposes")
7878
`contours(x,y,z,levels)` Trace the contour levels indicated by the `levels`
7979
argument.
8080
"""
81-
contours(x,y,z,levels) = ContourCollection([contour(x,y,z,l) for l in levels])
81+
contours(x, y, z, levels) = ContourCollection([contour(x, y, z, l) for l in levels])
8282

8383
"""
8484
`contours(x,y,z,Nlevels::Integer)` Trace `Nlevels` contour levels at heights
8585
chosen by the library (using the [`contourlevels`](@ref) function).
8686
"""
87-
function contours(x,y,z,Nlevels::Integer)
88-
contours(x,y,z,contourlevels(z,Nlevels))
87+
function contours(x, y, z, Nlevels::Integer)
88+
contours(x, y, z, contourlevels(z, Nlevels))
8989
end
9090

9191
"""
9292
`contours(x,y,z)` Trace 10 automatically chosen contour levels.
9393
"""
94-
contours(x,y,z) = contours(x,y,z,10)
94+
contours(x, y, z) = contours(x, y, z, 10)
9595

9696
"""
9797
`contourlevels(z,n)` Examines the values of `z` and chooses `n` evenly spaced
9898
levels to trace.
9999
"""
100-
function contourlevels(z,n)
101-
zmin,zmax = extrema(z)
102-
dz = (zmax-zmin) / (n+1)
103-
range(zmin+dz,dz,n)
100+
function contourlevels(z, n)
101+
zmin, zmax = extrema(z)
102+
dz = (zmax - zmin) / (n + 1)
103+
range(zmin + dz, dz, n)
104104
end
105105

106106
"""
107107
`coordinates(c)` Returns the coordinates of the vertices of the contour line as
108108
a tuple of lists.
109109
"""
110-
function coordinates{T}(c::Curve2{T})
110+
function coordinates(c::Curve2{T}) where {T}
111111
N = length(c.vertices)
112112
xlist = Vector{T}(N)
113113
ylist = Vector{T}(N)
114114

115-
for (i,v) in enumerate(c.vertices)
115+
for (i, v) in enumerate(c.vertices)
116116
xlist[i] = v[1]
117117
ylist[i] = v[2]
118118
end
@@ -153,14 +153,14 @@ const dirStr = ["N", "S", "NS", "E", "NE", "NS", "Invalid crossing",
153153
# the type of crossing that a cell contains. While most
154154
# cells will have only one crossing, cell type 5 and 10 will
155155
# have two crossings.
156-
type Cell
156+
struct Cell
157157
crossings::Vector{UInt8}
158158
end
159159

160160
function get_next_edge!(cell::Cell, entry_edge::UInt8)
161-
for (i,edge) in enumerate(cell.crossings)
161+
for (i, edge) in enumerate(cell.crossings)
162162
if edge & entry_edge != 0
163-
@compat next_edge = edge entry_edge
163+
next_edge = edge entry_edge
164164
deleteat!(cell.crossings, i)
165165

166166
return next_edge
@@ -178,12 +178,12 @@ function get_level_cells(z, h::Number)
178178

179179
local case::Int8
180180

181-
for xi in 1:xi_max-1
182-
for yi in 1:yi_max-1
183-
case = 1(z[xi,yi] > h) |
184-
2(z[xi+1,yi] > h) |
185-
4(z[xi+1,yi+1] > h) |
186-
8(z[xi,yi+1] > h)
181+
for xi in 1:xi_max - 1
182+
for yi in 1:yi_max - 1
183+
case = 1(z[xi, yi] > h) |
184+
2(z[xi + 1, yi] > h) |
185+
4(z[xi + 1, yi + 1] > h) |
186+
8(z[xi, yi + 1] > h)
187187

188188
# Contour does not go through these cells
189189
if case == 0 || case == 15
@@ -193,19 +193,19 @@ function get_level_cells(z, h::Number)
193193
# Process ambiguous cells (case 5 and 10) using
194194
# a bilinear interpolation of the cell-center value.
195195
if case == 5
196-
if 0.25(z[xi,yi] + z[xi,yi+1] + z[xi+1,yi] + z[xi+1,yi+1]) >= h
197-
cells[(xi,yi)] = Cell([NW, SE])
196+
if 0.25(z[xi, yi] + z[xi, yi + 1] + z[xi + 1, yi] + z[xi + 1, yi + 1]) >= h
197+
cells[(xi, yi)] = Cell([NW, SE])
198198
else
199-
cells[(xi,yi)] = Cell([NE, SW])
199+
cells[(xi, yi)] = Cell([NE, SW])
200200
end
201201
elseif case == 10
202-
if 0.25(z[xi,yi] + z[xi,yi+1] + z[xi+1,yi] + z[xi+1,yi+1]) >= h
203-
cells[(xi,yi)] = Cell([NE, SW])
202+
if 0.25(z[xi, yi] + z[xi, yi + 1] + z[xi + 1, yi] + z[xi + 1, yi + 1]) >= h
203+
cells[(xi, yi)] = Cell([NE, SW])
204204
else
205-
cells[(xi,yi)] = Cell([NW, SE])
205+
cells[(xi, yi)] = Cell([NW, SE])
206206
end
207207
else
208-
cells[(xi,yi)] = Cell([edge_LUT[case]])
208+
cells[(xi, yi)] = Cell([edge_LUT[case]])
209209
end
210210
end
211211
end
@@ -217,7 +217,7 @@ end
217217

218218
const fwd, rev = (UInt8(0)), (UInt8(1))
219219

220-
function add_vertex!{T}(curve::Curve2{T}, pos::(Tuple{T,T}), dir::UInt8)
220+
function add_vertex!(curve::Curve2{T}, pos::(Tuple{T,T}), dir::UInt8) where {T}
221221
if dir == fwd
222222
push!(curve.vertices, SVector{2,T}(pos...))
223223
else
@@ -228,19 +228,19 @@ end
228228
# Given the row and column indices of the lower left
229229
# vertex, add the location where the contour level
230230
# crosses the specified edge.
231-
function interpolate{T<:AbstractFloat}(x, y, z::Matrix{T}, h::Number, xi::Int, yi::Int, edge::UInt8)
231+
function interpolate(x, y, z::Matrix{T}, h::Number, xi::Int, yi::Int, edge::UInt8) where {T <: AbstractFloat}
232232
if edge == W
233-
y_interp = y[yi] + (y[yi+1] - y[yi])*(h - z[xi,yi])/(z[xi,yi+1] - z[xi,yi])
233+
y_interp = y[yi] + (y[yi + 1] - y[yi]) * (h - z[xi, yi]) / (z[xi, yi + 1] - z[xi, yi])
234234
x_interp = x[xi]
235235
elseif edge == E
236-
y_interp = y[yi] + (y[yi+1] - y[yi])*(h - z[xi+1,yi])/(z[xi+1,yi+1] - z[xi+1,yi])
236+
y_interp = y[yi] + (y[yi + 1] - y[yi]) * (h - z[xi + 1, yi]) / (z[xi + 1, yi + 1] - z[xi + 1, yi])
237237
x_interp = x[xi + 1]
238238
elseif edge == N
239239
y_interp = y[yi + 1]
240-
x_interp = x[xi] + (x[xi+1] - x[xi])*(h - z[xi,yi+1])/(z[xi+1,yi+1] - z[xi,yi+1])
240+
x_interp = x[xi] + (x[xi + 1] - x[xi]) * (h - z[xi, yi + 1]) / (z[xi + 1, yi + 1] - z[xi, yi + 1])
241241
elseif edge == S
242242
y_interp = y[yi]
243-
x_interp = x[xi] + (x[xi+1] - x[xi])*(h - z[xi,yi])/(z[xi+1,yi] - z[xi,yi])
243+
x_interp = x[xi] + (x[xi + 1] - x[xi]) * (h - z[xi, yi]) / (z[xi + 1, yi] - z[xi, yi])
244244
end
245245

246246
return x_interp, y_interp
@@ -259,10 +259,10 @@ function chase!(cells, curve, x, y, z, h, xi_start, yi_start, entry_edge, xi_max
259259
loopback_edge = entry_edge
260260

261261
while true
262-
cell = cells[(xi,yi)]
262+
cell = cells[(xi, yi)]
263263
exit_edge = get_next_edge!(cell, entry_edge)
264264
if length(cell.crossings) == 0
265-
delete!(cells, (xi,yi))
265+
delete!(cells, (xi, yi))
266266
end
267267

268268
add_vertex!(curve, interpolate(x, y, z, h, xi, yi, exit_edge), dir)
@@ -280,7 +280,7 @@ function chase!(cells, curve, x, y, z, h, xi_start, yi_start, entry_edge, xi_max
280280
xi -= 1
281281
entry_edge = E
282282
end
283-
!((xi,yi,entry_edge) != (xi_start,yi_start, loopback_edge) &&
283+
!((xi, yi, entry_edge) != (xi_start, yi_start, loopback_edge) &&
284284
0 < yi < yi_max && 0 < xi < xi_max) && break
285285
end
286286

@@ -308,11 +308,11 @@ function trace_contour(x, y, z, h::Number, cells::Dict{(Tuple{Int,Int}),Cell})
308308
# It then tries to trace the contour in the opposite direction.
309309

310310
while length(cells) > 0
311-
contour = Curve2(promote_type(map(eltype, (x,y,z))...))
311+
contour = Curve2(promote_type(map(eltype, (x, y, z))...))
312312

313313
# Pick initial box
314314
(xi_0, yi_0), cell = first(cells)
315-
(xi,yi) = (xi_0,yi_0)
315+
(xi, yi) = (xi_0, yi_0)
316316

317317
# Pick a starting edge
318318
crossing = first(cell.crossings)

test/interface.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ function setup()
77

88
xs = sort!(rand(nx))
99
ys = sort!(rand(ny))
10-
zs = rand(nx,ny)
10+
zs = rand(nx, ny)
1111

1212
xs, ys, zs
1313
end
1414

1515
xs, ys, zs = setup()
1616

17-
cs = @inferred contours(xs,ys,zs)
17+
cs = @inferred contours(xs, ys, zs)
1818
for c in levels(cs)
1919
for l in lines(c)
20-
x,y = coordinates(l)
20+
x, y = coordinates(l)
2121
@assert typeof(x) == typeof(y) == Vector{Float64}
2222
end
2323
end

0 commit comments

Comments
 (0)