Mercurial > repos > public > sbplib_julia
changeset 1333:79a2193da5c1 refactor/grids
Implement coordinate_size() and component_type() types
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 03 May 2023 15:39:34 +0200 |
parents | ad31c1022e42 |
children | 47e309eac131 |
files | src/Grids/grid.jl test/Grids/grid_test.jl |
diffstat | 2 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/grid.jl Wed May 03 15:31:53 2023 +0200 +++ b/src/Grids/grid.jl Wed May 03 15:39:34 2023 +0200 @@ -19,8 +19,12 @@ Base.ndims(::Grid{T,D}) where {T,D} = D Base.eltype(::Type{<:Grid{T}}) where T = T -coordinate_size(::Grid{T}) where T = _ncomponents(T) # TBD: Name of this function?! -component_type(::Grid{T}) where T = eltype(T) + +coordinate_size(::Type{<:Grid{T}}) where T = _ncomponents(T) +coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?! + +component_type(::Type{<:Grid{T}}) where T = eltype(T) +component_type(g::Grid) = component_type(typeof(g)) """ refine(g::Grid, r)
--- a/test/Grids/grid_test.jl Wed May 03 15:31:53 2023 +0200 +++ b/test/Grids/grid_test.jl Wed May 03 15:39:34 2023 +0200 @@ -14,6 +14,8 @@ @test coordinate_size(DummyGrid{Int, 1}()) == 1 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3 + @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3 + @testset "component_type" begin @test component_type(DummyGrid{Int,1}()) == Int @test component_type(DummyGrid{Float64,1}()) == Float64 @@ -22,6 +24,9 @@ @test component_type(DummyGrid{SVector{3,Int},2}()) == Int @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64 @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational + + @test component_type(DummyGrid{Float64,1}) == Float64 + @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64 end end