Mercurial > repos > public > sbplib_julia
changeset 1092:c4ea28d904f5 refactor/grids
Fix grid indexing with CartesianIndex
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 27 Apr 2022 10:25:53 +0200 |
parents | 9b40aeac4269 |
children | 703eaa3e50c4 9275d95e2d90 |
files | src/Grids/EquidistantGrid.jl test/Grids/EquidistantGrid_test.jl |
diffstat | 2 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl Tue Apr 26 14:28:42 2022 +0200 +++ b/src/Grids/EquidistantGrid.jl Wed Apr 27 10:25:53 2022 +0200 @@ -44,6 +44,7 @@ function EquidistantGrid(size, limit_lower, limit_upper) return EquidistantGrid{length(size), eltype(limit_lower)}(size, limit_lower, limit_upper) end +# TBD: Should it be an AbstractArray? """ EquidistantGrid{T}() @@ -67,11 +68,14 @@ Base.size(g::EquidistantGrid) = g.size -function Base.getindex(g::EquidistantGrid, I...) +function Base.getindex(g::EquidistantGrid, I::Vararg{Int}) h = spacing(g) return g.limit_lower .+ (I.-1).*h end +Base.getindex(g::EquidistantGrid, I::CartesianIndex) = g[Tuple(I)...] +# TBD: Can this method be removed if `EquidistantGrid` is an AbstractArray? + """ dimension(grid::EquidistantGrid)