Skip to content

Commit

Permalink
cleanup indexing calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed May 8, 2020
1 parent 1f43642 commit 6f0f27c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Contour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function chase!(cells, curve, x, y, z, h, start, entry_edge, xi_max, yi_max, ::T
@inbounds while true
exit_edge = get_next_edge!(cells, ind, entry_edge)

push!(curve, interpolate(x, y, z, h, ind[1], ind[2], exit_edge, VT))
push!(curve, interpolate(x, y, z, h, ind, exit_edge, VT))

ind, entry_edge = advance_edge(ind, exit_edge)

Expand Down Expand Up @@ -286,7 +286,7 @@ function trace_contour(x, y, z, h::Number, cells::Dict)
starting_edge = 0x01 << trailing_zeros(crossing)

# Add the contour entry location for cell (xi_0,yi_0)
push!(contour_arr, interpolate(x, y, z, h, ind[1], ind[2], starting_edge, VT))
push!(contour_arr, interpolate(x, y, z, h, ind, starting_edge, VT))

# Start trace in forward direction
ind_end = chase!(cells, contour_arr, x, y, z, h, ind, starting_edge, xi_max, yi_max, VT)
Expand Down
11 changes: 7 additions & 4 deletions src/interpolate.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Given the row and column indices of the lower left
# vertex, add the location where the contour level
# crosses the specified edge.
function interpolate(x, y, z::AbstractMatrix, h::Number, xi, yi, edge::UInt8, ::Type{VT}) where {VT}
function interpolate(x, y, z::AbstractMatrix, h::Number, ind, edge::UInt8, ::Type{VT}) where {VT}
xi, yi = ind
@inbounds if edge == W
y_interp = y[yi] + (y[yi + 1] - y[yi]) * (h - z[xi, yi]) / (z[xi, yi + 1] - z[xi, yi])
x_interp = x[xi]
Expand All @@ -19,7 +20,8 @@ function interpolate(x, y, z::AbstractMatrix, h::Number, xi, yi, edge::UInt8, ::
return VT(x_interp, y_interp)
end

function interpolate(x::AbstractRange, y::AbstractRange, z::AbstractMatrix, h::Number, xi, yi, edge::UInt8, ::Type{VT}) where {VT}
function interpolate(x::AbstractRange, y::AbstractRange, z::AbstractMatrix, h::Number, ind, edge::UInt8, ::Type{VT}) where {VT}
xi, yi = ind
@inbounds if edge == W
y_interp = y[yi] + step(y) * (h - z[xi, yi]) / (z[xi, yi + 1] - z[xi, yi])
x_interp = x[xi]
Expand All @@ -37,8 +39,9 @@ function interpolate(x::AbstractRange, y::AbstractRange, z::AbstractMatrix, h::N
return VT(x_interp, y_interp)
end

function interpolate(x::AbstractMatrix, y::AbstractMatrix, z::AbstractMatrix, h::Number, xi, yi, edge::UInt8, ::Type{VT}) where {VT}
if edge == W
function interpolate(x::AbstractMatrix, y::AbstractMatrix, z::AbstractMatrix, h::Number, ind, edge::UInt8, ::Type{VT}) where {VT}
xi, yi = ind
@inbounds if edge == W
Δ = [y[xi, yi+1] - y[xi, yi ], x[xi, yi+1] - x[xi, yi ]].*(h - z[xi, yi ])/(z[xi, yi+1] - z[xi, yi ])
y_interp = y[xi,yi] + Δ[1]
x_interp = x[xi,yi] + Δ[2]
Expand Down

0 comments on commit 6f0f27c

Please sign in to comment.