Skip to content

Commit

Permalink
Merge pull request #76 from tpapp/tp/add-vertices
Browse files Browse the repository at this point in the history
Add the accessor `vertices` to the API.
  • Loading branch information
sjkelly authored Apr 2, 2024
2 parents 0160a41 + 5632f5c commit 8b21f57
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
version:
- '1.0'
- '1.6'
- 'nightly'
- '1' # latest stable version
os:
- ubuntu-latest
#- macOS-latest
Expand Down
7 changes: 7 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ level
levels
lines
coordinates
vertices
```

# Utilities
Expand Down
5 changes: 3 additions & 2 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down
16 changes: 12 additions & 4 deletions src/Contour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export
level,
levels,
lines,
coordinates
coordinates,
vertices

import Base: push!, length, eltype, show

Expand All @@ -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
"""
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8b21f57

Please sign in to comment.