comparison src/Grids/grid.jl @ 1386:4d628c83987e refactor/grids/cartesian_indexing

Add method `getindex(::Grid,::CartesianIndex)` with a default implementation
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 26 Jul 2023 21:36:50 +0200
parents 08f06bfacd5c
children dba1e8c95bbb
comparison
equal deleted inserted replaced
1384:851d1e4ab3de 1386:4d628c83987e
19 """ 19 """
20 abstract type Grid{T,D} end 20 abstract type Grid{T,D} end
21 21
22 Base.ndims(::Grid{T,D}) where {T,D} = D 22 Base.ndims(::Grid{T,D}) where {T,D} = D
23 Base.eltype(::Type{<:Grid{T}}) where T = T 23 Base.eltype(::Type{<:Grid{T}}) where T = T
24
25 Base.getindex(g::Grid, I::CartesianIndex) = g[Tuple(I)...]
24 26
25 """ 27 """
26 coordinate_size(g) 28 coordinate_size(g)
27 29
28 The lenght of the coordinate vector of `Grid` `g`. 30 The lenght of the coordinate vector of `Grid` `g`.