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

add prepared geometry wrapper #105

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/GeometryOps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Edge{T} = Tuple{TuplePoint{T},TuplePoint{T}} where T

include("primitives.jl")
include("utils.jl")
include("prepared.jl")

include("methods/angles.jl")
include("methods/area.jl")
Expand Down
56 changes: 56 additions & 0 deletions src/prepared.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
struct Prepared{Pa,Pr}
parent::Pa
preparations::Pr
end

Base.parent(x::Prepared) = x.parent
@inline getprep(p::Prepared, x::Symbol) = getpropery(p.preparations, x)
asinghvi17 marked this conversation as resolved.
Show resolved Hide resolved

GI.trait(p::Prepared) = GI.trait(parent(p))
GI.geomtrait(p::Prepared) = GI.geomtrait(parent(p))

GI.isgeometry(::Type{<:Prepared{T}}) where {T} = GI.isgeometry(T)
GI.isfeature(::Type{<:Prepared{T}}) where {T} = GI.isfeature(T)
GI.isfeaturecollection(::Type{<:Prepared{T}}) where {T} = GI.isfeaturecollection(T)

GI.geometry(x::Prepared) = GI.geometry(parent(x))
GI.properties(x::Prepared) = GI.properties(parent(x))

for f in (:extent, :crs)
@eval GI.$f(t::GI.AbstractTrait, x::Prepared) = GI.$f(t, parent(x))
end
for f in (:coordnames, :is3d, :ismeasured, :isempty, :coordinates, :getgeom)
@eval GI.$f(t::GI.AbstractGeometryTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end

for f in (:x, :y, :z, :m, :coordinates, :getcoord, :ngeom, :getgeom)
@eval GI.$f(t::GI.AbstractPointTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:npoint, :getpoint, :startpoint, :endpoint, :npoint, :issimple, :isclosed, :isring)
@eval GI.$f(t::GI.AbstractCurveTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:nring, :getring, :getexterior, :nhole, :gethole, :npoint, :getpoint, :startpoint, :endpoint)
@eval GI.$f(t::GI.AbstractPolygonTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:npoint, :getpoint, :issimple)
@eval GI.$f(t::GI.AbstractMultiPointTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
@eval GI.$f(t::GI.AbstractMultiCurveTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:nring, :getring, :npoint, :getpoint)
@eval GI.$f(t::GI.AbstractMultiPolygonTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end

getpoint(t::GI.AbstractPolyhedralSurfaceTrait, geom::Prepared) = GI.getpoint(t, parent(geom))
isclosed(t::GI.AbstractMultiCurveTrait, geom::Prepared) = GI.isclosed(t, parent(geom))

for f in (:getfeature, :coordinates)
@eval GI.$f(t::GI.AbstractFeatureTrait, geom::Prepared, args...) = $f(t, parent(geom), args...)
end

# Ambiguity
for T in (:LineTrait, :TriangleTrait, :PentagonTrait, :HexagonTrait, :RectangleTrait, :QuadTrait)
@eval GI.npoint(t::GI.$T, geom::Prepared) = GI.npoint(t, parent(geom))
end
for T in (:RectangleTrait, :QuadTrait, :PentagonTrait, :HexagonTrait, :TriangleTrait)
@eval GI.nring(t::GI.$T, geom::Prepared) = GI.nring(t, parent(geom))
end
Loading