Skip to content

Commit 8073e59

Browse files
authored
Merge pull request #74 from JuliaGeometry/sjk/int1
add support for Integer arrays without conversion
2 parents 4949c06 + f473c43 commit 8073e59

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/Contour.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ function contour(x, y, z, level::Number; VT=nothing)
7272
if !(axes(x) == (axes(z,1),) && axes(y) == (axes(z,2),) || axes(x) == axes(y) == axes(z))
7373
throw(ArgumentError("Incompatible input axes in `Contour.contour`."))
7474
end
75-
VT = VT === nothing ? NTuple{2,promote_type(map(eltype, (x, y, z))...)} : VT
75+
ET = promote_type(map(eltype, (x, y, z))...)
76+
ET = ET <: Integer ? Float64 : ET
77+
VT = VT === nothing ? NTuple{2,ET} : VT
7678
trace_contour(x, y, z, level, get_level_cells(z, level), VT)
7779
end
7880

@@ -84,23 +86,27 @@ You'll usually call [`levels`](@ref) on the output of `contours`.
8486
function contours end
8587

8688
"""
87-
`contours(x,y,z,levels)` Trace the contour levels indicated by the `levels`
88-
argument.
89+
contours(x,y,z,levels;[VT])
90+
Trace the contour levels indicated by the `levels` argument.
91+
The extracted vertex type maybe be specified by the `VT` keyword.
8992
"""
90-
contours(x, y, z, levels) = ContourCollection([contour(x, y, z, l) for l in levels])
93+
contours(x, y, z, levels; VT=nothing) = ContourCollection([contour(x, y, z, l; VT=VT) for l in levels])
9194

9295
"""
93-
`contours(x,y,z,Nlevels::Integer)` Trace `Nlevels` contour levels at heights
96+
contours(x,y,z,Nlevels::Integer;[VT])
97+
98+
Trace `Nlevels` contour levels at heights
9499
chosen by the library (using the [`contourlevels`](@ref) function).
100+
The extracted vertex type maybe be specified by the `VT` keyword.
95101
"""
96-
function contours(x, y, z, Nlevels::Integer)
97-
contours(x, y, z, contourlevels(z, Nlevels))
102+
function contours(x, y, z, Nlevels::Integer;VT=nothing)
103+
contours(x, y, z, contourlevels(z, Nlevels); VT=VT)
98104
end
99105

100106
"""
101-
`contours(x,y,z)` Trace 10 automatically chosen contour levels.
107+
`contours(x,y,z;[VT])` Trace 10 automatically chosen contour levels.
102108
"""
103-
contours(x, y, z) = contours(x, y, z, 10)
109+
contours(x, y, z; VT=nothing) = contours(x, y, z, 10; VT=VT)
104110

105111
"""
106112
`contourlevels(z,n)` Examines the values of `z` and chooses `n` evenly spaced

test/verify_vertices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,8 @@ y = randn(N)
259259
H = fit(Histogram, (x, y), closed = :left)
260260
contours(midpoints.(H.edges)..., H.weights)
261261

262+
# Integer support/Conversion
263+
contours(-5:5, -5:5, (-5:5)*(-5:5)')
264+
contours(-5:5, -5:5, (-5:5)*(-5:5)', VT=NTuple{2,Float16})
265+
262266
end

0 commit comments

Comments
 (0)