Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly implement interface for wrapper geometry. #169

Merged
merged 3 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading