diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7632a5e..e69d65b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,7 +17,7 @@ jobs: version: - '1.0' - '1.6' - - 'nightly' + - '1' # latest stable version os: - ubuntu-latest #- macOS-latest diff --git a/Project.toml b/Project.toml index 7cc00f7..a2f6807 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,13 @@ version = "0.6.2" [compat] julia = "0.7, 1" +Aqua = "0.8" +JET = "0.0.1, 0.4, 0.8" +LinearAlgebra = "1" +OffsetArrays = "1" +StaticArrays = "1" +StatsBase = "0.34" +Test = "1" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" diff --git a/docs/src/reference.md b/docs/src/reference.md index 67db5ae..85b3493 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -12,6 +12,7 @@ level levels lines coordinates +vertices ``` # Utilities diff --git a/docs/src/tutorial.md b/docs/src/tutorial.md index 97a414b..04d4e36 100644 --- a/docs/src/tutorial.md +++ b/docs/src/tutorial.md @@ -97,8 +97,8 @@ This contour level only had one line. An isoline is represented as a sequence of vertices, which either starts and ends at the boundaries of the data set, or closes on itself, in which case the first and last points are equal. -The ``x``- and ``y``-coordinates of an isoline are extracted using the -[`coordinates`](@ref) function: +The ``x``- and ``y``-coordinates of an isoline can be extracted using the +[`coordinates`](@ref) or [`vertices`](@ref) functions: ```@example using Contour # hide @@ -109,6 +109,7 @@ c = contours(x,y,z) # hide cl = first(levels(c)) # hide l = first(lines(cl)) xs, ys = coordinates(l) +x_y_pairs = vertices(l) nothing # hide ``` diff --git a/src/Contour.jl b/src/Contour.jl index 71f6ab7..6faa41e 100644 --- a/src/Contour.jl +++ b/src/Contour.jl @@ -10,7 +10,8 @@ export level, levels, lines, - coordinates + coordinates, + vertices import Base: push!, length, eltype, show @@ -36,7 +37,7 @@ show(io::IO, ::MIME"text/plain", cl::ContourLevel) = write(io, "$(typeof(cl))\n show(io::IO, ::MIME"text/plain", cls::Vector{ContourLevel{T}}) where {T} = write(io, "$(typeof(cls))\n $(length(cls)) contour level(s)") """ `lines(c)` Extracts an iterable collection of isolines from a contour level. -Use [`coordinates`](@ref) to get the coordinates of a line. +Use [`coordinates`](@ref) or [`vertices`](@ref) to get the coordinates of a line. """ lines(cl::ContourLevel) = cl.lines """ @@ -53,8 +54,8 @@ show(io::IO, ::MIME"text/plain", cc::ContourCollection) = write(io, "$(typeof(cc """ Turns the output of [`contours`](@ref) into an iterable with each of the traced -contour levels. Each of the objects support [`level`](@ref) and -[`coordinates`](@ref). +contour levels. Each of the objects support [`level`](@ref), +[`coordinates`](@ref), and [`vertices`](@ref). """ levels(cc::ContourCollection) = cc.contours @@ -135,6 +136,13 @@ function coordinates(c::Curve2{T}) where {T} xlist, ylist end +""" +`vertices(c)` + +Returns the vertices of a contour line as a vector of 2-element tuples. +""" +vertices(c::Curve2) = c.vertices + # The marching squares algorithm defines 16 cell types # based on the edges that a contour line enters and exits # through. The edges of the cells are identified using diff --git a/test/interface.jl b/test/interface.jl index 9346a37..7444483 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -19,6 +19,8 @@ for c in levels(cs) for l in lines(c) x, y = coordinates(l) @assert typeof(x) == typeof(y) == Vector{Float64} + xy = vertices(l) + @test xy isa Vector{Tuple{Float64,Float64}} end end