@@ -63,7 +63,9 @@ You'll usually call [`lines`](@ref) on the output of `contour`, and then iterate
6363over the result.
6464"""
6565function contour (x, y, z, level:: Number )
66- # Todo: size checking on x,y,z
66+ if ! (axes (x) == (axes (z,1 ),) && axes (y) == (axes (z,2 ),) || axes (x) == axes (y) == axes (z))
67+ throw (ArgumentError (" Incompatible input axes in `Contour.contour`." ))
68+ end
6769 trace_contour (x, y, z, level, get_level_cells (z, level))
6870end
6971
@@ -207,10 +209,10 @@ end
207209
208210function get_level_cells (z, h:: Number )
209211 cells = Dict {Tuple{Int,Int},UInt8} ()
210- xi_max, yi_max = size (z)
212+ x_ax, y_ax = axes (z)
211213
212- @inbounds for xi in 1 : xi_max - 1
213- for yi in 1 : yi_max - 1
214+ @inbounds for xi in first (x_ax) : last (x_ax) - 1
215+ for yi in first (y_ax) : last (y_ax) - 1
214216 elts = (z[xi, yi], z[xi + 1 , yi], z[xi + 1 , yi + 1 ], z[xi, yi + 1 ])
215217 case = _get_case (elts, h)
216218
237239
238240# Given a cell and a starting edge, we follow the contour line until we either
239241# hit the boundary of the input data, or we form a closed contour.
240- function chase! (cells, curve, x, y, z, h, start, entry_edge, xi_max, yi_max , :: Type{VT} ) where VT
242+ function chase! (cells, curve, x, y, z, h, start, entry_edge, xi_range, yi_range , :: Type{VT} ) where VT
241243
242244 ind = start
243245
@@ -255,7 +257,7 @@ function chase!(cells, curve, x, y, z, h, start, entry_edge, xi_max, yi_max, ::T
255257 ind, entry_edge = advance_edge (ind, exit_edge)
256258
257259 ! ((ind[1 ], ind[2 ], entry_edge) != (start[1 ], start[2 ], loopback_edge) &&
258- 0 < ind[2 ] < yi_max && 0 < ind[1 ] < xi_max ) && break
260+ ind[2 ] ∈ yi_range && ind[1 ] ∈ xi_range ) && break
259261 end
260262
261263 return ind
@@ -266,7 +268,10 @@ function trace_contour(x, y, z, h::Number, cells::Dict)
266268
267269 contours = ContourLevel (h)
268270
269- (xi_max, yi_max) = size (z):: Tuple{Int,Int}
271+ x_ax, y_ax = axes (z)
272+ xi_range = first (x_ax): last (x_ax)- 1
273+ yi_range = first (y_ax): last (y_ax)- 1
274+
270275
271276 VT = SVector{2 ,promote_type (map (eltype, (x, y, z))... )}
272277
@@ -289,7 +294,7 @@ function trace_contour(x, y, z, h::Number, cells::Dict)
289294 push! (contour_arr, interpolate (x, y, z, h, ind, starting_edge, VT))
290295
291296 # Start trace in forward direction
292- ind_end = chase! (cells, contour_arr, x, y, z, h, ind, starting_edge, xi_max, yi_max , VT)
297+ ind_end = chase! (cells, contour_arr, x, y, z, h, ind, starting_edge, xi_range, yi_range , VT)
293298
294299 if ind == ind_end
295300 push! (contours. lines, Curve2 (contour_arr))
@@ -298,9 +303,9 @@ function trace_contour(x, y, z, h::Number, cells::Dict)
298303
299304 ind, starting_edge = advance_edge (ind, starting_edge)
300305
301- if 0 < ind[2 ] < yi_max && 0 < ind[1 ] < xi_max
306+ if ind[2 ] ∈ yi_range && ind[1 ] ∈ xi_range
302307 # Start trace in reverse direction
303- chase! (cells, reverse! (contour_arr), x, y, z, h, ind, starting_edge, xi_max, yi_max , VT)
308+ chase! (cells, reverse! (contour_arr), x, y, z, h, ind, starting_edge, xi_range, yi_range , VT)
304309 end
305310
306311 push! (contours. lines, Curve2 (contour_arr))
0 commit comments