Skip to content

Commit

Permalink
Correctly implement interface for wrapper geometry. (#169)
Browse files Browse the repository at this point in the history
* Correctly implement interface for wrapper geometry.

* Test for correct implementations.

* Direct call of two/three argument methods.
  • Loading branch information
evetion authored Oct 12, 2024
1 parent 34dafb7 commit e6cacdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

2 comments on commit e6cacdc

@evetion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 1.3.7 already exists

Please sign in to comment.