1
1
module Contour
2
2
3
- using StaticArrays
4
-
5
3
include (" interpolate.jl" )
6
4
7
5
export
@@ -17,17 +15,17 @@ export
17
15
import Base: push!, length, eltype, show
18
16
19
17
struct Curve2{T}
20
- vertices:: Vector{NTuple{2,T} }
18
+ vertices:: Vector{T }
21
19
end
22
- Curve2 (:: Type{T} ) where {T} = Curve2 (SVector{ 2 ,T} [])
20
+ Curve2 (:: Type{T} ) where {T} = Curve2 (T [])
23
21
show (io:: IO , :: MIME"text/plain" , c2:: Curve2 ) = write (io, " $(typeof (c2)) \n with $(length (c2. vertices)- 1 ) vertices" )
24
22
show (io:: IO , :: MIME"text/plain" , c2s:: Vector{Curve2{T}} ) where {T} = write (io, " $(typeof (c2s)) \n $(length (c2s)) contour line(s)" )
25
23
26
- struct ContourLevel{T}
27
- level:: T
24
+ struct ContourLevel{T, L }
25
+ level:: L
28
26
lines:: Vector{Curve2{T}}
29
27
end
30
- ContourLevel (h:: T ) where {T <: AbstractFloat } = ContourLevel (h, Curve2{T }[])
28
+ ContourLevel (h:: T ) where {T <: AbstractFloat } = ContourLevel (h, Curve2{NTuple{ 2 ,T} }[])
31
29
ContourLevel (h:: T ) where {T} = ContourLevel (Float64 (h))
32
30
show (io:: IO , :: MIME"text/plain" , cl:: ContourLevel ) = write (io, " $(typeof (cl)) \n at $(level (cl)) with $(length (lines (cl))) line(s)" )
33
31
show (io:: IO , :: MIME"text/plain" , cls:: Vector{ContourLevel{T}} ) where {T} = write (io, " $(typeof (cls)) \n $(length (cls)) contour level(s)" )
@@ -62,11 +60,12 @@ argument `level`.
62
60
You'll usually call [`lines`](@ref) on the output of `contour`, and then iterate
63
61
over the result.
64
62
"""
65
- function contour (x, y, z, level:: Number )
63
+ function contour (x, y, z, level:: Number ; VT = nothing )
66
64
if ! (axes (x) == (axes (z,1 ),) && axes (y) == (axes (z,2 ),) || axes (x) == axes (y) == axes (z))
67
65
throw (ArgumentError (" Incompatible input axes in `Contour.contour`." ))
68
66
end
69
- trace_contour (x, y, z, level, get_level_cells (z, level))
67
+ VT = VT === nothing ? NTuple{2 ,promote_type (map (eltype, (x, y, z))... )} : VT
68
+ trace_contour (x, y, z, level, get_level_cells (z, level), VT)
70
69
end
71
70
72
71
"""
@@ -111,8 +110,9 @@ a tuple of lists.
111
110
"""
112
111
function coordinates (c:: Curve2{T} ) where {T}
113
112
N = length (c. vertices)
114
- xlist = Vector {T} (undef, N)
115
- ylist = Vector {T} (undef, N)
113
+ E = eltype (T)
114
+ xlist = Vector {E} (undef, N)
115
+ ylist = Vector {E} (undef, N)
116
116
117
117
for (i, v) in enumerate (c. vertices)
118
118
xlist[i] = v[1 ]
@@ -264,17 +264,15 @@ function chase!(cells, curve, x, y, z, h, start, entry_edge, xi_range, yi_range,
264
264
end
265
265
266
266
267
- function trace_contour (x, y, z, h:: Number , cells:: Dict )
267
+ function trace_contour (x, y, z, h:: Number , cells:: Dict , VT )
268
268
269
- contours = ContourLevel (h)
269
+ contours = ContourLevel (h, Curve2{VT}[] )
270
270
271
271
x_ax, y_ax = axes (z)
272
272
xi_range = first (x_ax): last (x_ax)- 1
273
273
yi_range = first (y_ax): last (y_ax)- 1
274
274
275
275
276
- VT = NTuple{2 ,promote_type (map (eltype, (x, y, z))... )}
277
-
278
276
# When tracing out contours, this algorithm picks an arbitrary
279
277
# starting cell, then first follows the contour in one direction
280
278
# until it either ends up where it started # or at one of the boundaries.
0 commit comments