From 6f0f27ccc08702d7cee1e3504a3a5e00754709a5 Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Fri, 8 May 2020 00:29:56 -0400 Subject: [PATCH] cleanup indexing calls --- src/Contour.jl | 4 ++-- src/interpolate.jl | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Contour.jl b/src/Contour.jl index bf8c874..134b48b 100644 --- a/src/Contour.jl +++ b/src/Contour.jl @@ -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) @@ -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) diff --git a/src/interpolate.jl b/src/interpolate.jl index 091f786..ead6cc2 100644 --- a/src/interpolate.jl +++ b/src/interpolate.jl @@ -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] @@ -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] @@ -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]