Skip to content

Commit cabb6fe

Browse files
authored
Merge pull request #207 from marinlauber/fix-interp
interp for Cartesian Coordinates
2 parents b582df3 + e659eac commit cabb6fe

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/util.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ end
235235
"""
236236
interp(x::SVector, arr::AbstractArray)
237237
238-
Linear interpolation from array `arr` at index-coordinate `x`.
238+
Linear interpolation from array `arr` at Cartesian-coordinate `x`.
239239
Note: This routine works for any number of dimensions.
240240
"""
241241
function interp(x::SVector{D}, arr::AbstractArray{T,D}) where {D,T}
242242
# Index below the interpolation coordinate and the difference
243-
i = floor.(Int,x); y = x.-i
243+
x = x .+ 1.5f0; i = floor.(Int,x); y = x.-i
244244

245245
# CartesianIndices around x
246246
I = CartesianIndex(i...); R = I:I+oneunit(I)

test/maintests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ using ReadVTK, WriteVTK
8181
@test GPUArrays.@allowscalar all(u[:,:,1,3] .≈ tan(-1π/16)) && all(u[:,:,2,3] .≈ tan(0)) && all(u[:,:,end,3].-tan(6π/16).<1e-6)
8282

8383
# test interpolation
84-
a = zeros(5,5,2) |> f; b = zeros(5,5) |> f
85-
apply!((i,x)->x[i]+1.5,a); apply!(x->x[1]+1.5,b) # offset for start of grid
84+
a = zeros(8,8,2) |> f; b = zeros(8,8) |> f
85+
apply!((i,x)->x[i],a); apply!(x->x[1],b) # offset for start of grid
8686
@test GPUArrays.@allowscalar all(WaterLily.interp(SVector(2.5,1),a) .≈ [2.5,1.])
8787
@test GPUArrays.@allowscalar all(WaterLily.interp(SVector(3.5,3),a) .≈ [3.5,3.])
8888
@test GPUArrays.@allowscalar WaterLily.interp(SVector(2.5,1),b) 2.5

0 commit comments

Comments
 (0)