Skip to content

Commit 8b21f57

Browse files
authored
Merge pull request #76 from tpapp/tp/add-vertices
Add the accessor `vertices` to the API.
2 parents 0160a41 + 5632f5c commit 8b21f57

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
version:
1818
- '1.0'
1919
- '1.6'
20-
- 'nightly'
20+
- '1' # latest stable version
2121
os:
2222
- ubuntu-latest
2323
#- macOS-latest

Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ version = "0.6.2"
44

55
[compat]
66
julia = "0.7, 1"
7+
Aqua = "0.8"
8+
JET = "0.0.1, 0.4, 0.8"
9+
LinearAlgebra = "1"
10+
OffsetArrays = "1"
11+
StaticArrays = "1"
12+
StatsBase = "0.34"
13+
Test = "1"
714

815
[extras]
916
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

docs/src/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ level
1212
levels
1313
lines
1414
coordinates
15+
vertices
1516
```
1617

1718
# Utilities

docs/src/tutorial.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ This contour level only had one line. An isoline is represented as a sequence of
9797
vertices, which either starts and ends at the boundaries of the data set, or
9898
closes on itself, in which case the first and last points are equal.
9999

100-
The ``x``- and ``y``-coordinates of an isoline are extracted using the
101-
[`coordinates`](@ref) function:
100+
The ``x``- and ``y``-coordinates of an isoline can be extracted using the
101+
[`coordinates`](@ref) or [`vertices`](@ref) functions:
102102

103103
```@example
104104
using Contour # hide
@@ -109,6 +109,7 @@ c = contours(x,y,z) # hide
109109
cl = first(levels(c)) # hide
110110
l = first(lines(cl))
111111
xs, ys = coordinates(l)
112+
x_y_pairs = vertices(l)
112113
nothing # hide
113114
```
114115

src/Contour.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export
1010
level,
1111
levels,
1212
lines,
13-
coordinates
13+
coordinates,
14+
vertices
1415

1516
import Base: push!, length, eltype, show
1617

@@ -36,7 +37,7 @@ show(io::IO, ::MIME"text/plain", cl::ContourLevel) = write(io, "$(typeof(cl))\n
3637
show(io::IO, ::MIME"text/plain", cls::Vector{ContourLevel{T}}) where {T} = write(io, "$(typeof(cls))\n $(length(cls)) contour level(s)")
3738
"""
3839
`lines(c)` Extracts an iterable collection of isolines from a contour level.
39-
Use [`coordinates`](@ref) to get the coordinates of a line.
40+
Use [`coordinates`](@ref) or [`vertices`](@ref) to get the coordinates of a line.
4041
"""
4142
lines(cl::ContourLevel) = cl.lines
4243
"""
@@ -53,8 +54,8 @@ show(io::IO, ::MIME"text/plain", cc::ContourCollection) = write(io, "$(typeof(cc
5354

5455
"""
5556
Turns the output of [`contours`](@ref) into an iterable with each of the traced
56-
contour levels. Each of the objects support [`level`](@ref) and
57-
[`coordinates`](@ref).
57+
contour levels. Each of the objects support [`level`](@ref),
58+
[`coordinates`](@ref), and [`vertices`](@ref).
5859
"""
5960
levels(cc::ContourCollection) = cc.contours
6061

@@ -135,6 +136,13 @@ function coordinates(c::Curve2{T}) where {T}
135136
xlist, ylist
136137
end
137138

139+
"""
140+
`vertices(c)`
141+
142+
Returns the vertices of a contour line as a vector of 2-element tuples.
143+
"""
144+
vertices(c::Curve2) = c.vertices
145+
138146
# The marching squares algorithm defines 16 cell types
139147
# based on the edges that a contour line enters and exits
140148
# through. The edges of the cells are identified using

test/interface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ for c in levels(cs)
1919
for l in lines(c)
2020
x, y = coordinates(l)
2121
@assert typeof(x) == typeof(y) == Vector{Float64}
22+
xy = vertices(l)
23+
@test xy isa Vector{Tuple{Float64,Float64}}
2224
end
2325
end
2426

0 commit comments

Comments
 (0)