From e6cacdc3dd746a35a897832ed9d3b131518846b1 Mon Sep 17 00:00:00 2001 From: Maarten Pronk Date: Sat, 12 Oct 2024 12:36:54 +0200 Subject: [PATCH] Correctly implement interface for wrapper geometry. (#169) * Correctly implement interface for wrapper geometry. * Test for correct implementations. * Direct call of two/three argument methods. --- src/utils.jl | 8 +++++++- src/wrappers.jl | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 23d70ff..e359e43 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -8,15 +8,21 @@ function testgeometry(geom) type = geomtrait(geom) @assert !isnothing(type) "$geom doesn't implement `geomtrait`." + @assert hasmethod(ncoord, (typeof(type), typeof(geom))) "$geom does not correctly implement two argument `ncoord`" + if type == PointTrait() n = ncoord(geom) + @assert n == ncoord(type, geom) "$geom does not correctly implement three argument `getcoord`" if n >= 1 # point could be empty - getcoord(geom, 1) # point always needs at least 2 + c = getcoord(geom, 1) # point always needs at least 2 + @assert c == getcoord(type, geom, 1) "$geom does not correctly implement three argument `getcoord`" end else n = ngeom(geom) + @assert n == ngeom(type, geom) "$geom does not correctly implement two argument `ngeom`" if n >= 1 # geometry could be empty g2 = getgeom(geom, 1) + @assert g2 == getgeom(type, geom, 1) "$geom does not correctly implement three argument `getgeom`" subtype = subtrait(type) if !isnothing(subtype) issub = geomtrait(g2) isa subtype diff --git a/src/wrappers.jl b/src/wrappers.jl index cf8091d..5ddfac0 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -61,9 +61,9 @@ measures. abstract type WrapperGeometry{Z,M,T,C} end isgeometry(::Type{<:WrapperGeometry}) = true -is3d(::WrapperGeometry{Z}) where Z = Z -ismeasured(::WrapperGeometry{<:Any,M}) where M = M -ncoord(::WrapperGeometry{Z, M}) where {Z, M} = 2 + Z + M +is3d(::AbstractGeometryTrait, ::WrapperGeometry{Z}) where Z = Z +ismeasured(::AbstractGeometryTrait, ::WrapperGeometry{<:Any,M}) where M = M +ncoord(::AbstractGeometryTrait, ::WrapperGeometry{Z, M}) where {Z, M} = 2 + Z + M Base.parent(geom::WrapperGeometry) = geom.geom