Skip to content

Commit 492df71

Browse files
committed
define the new interface on algorithm types implemented in GO
1 parent fc5bd5a commit 492df71

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/GeometryOps.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import GeometryOpsCore
66
import GeometryOpsCore:
77
TraitTarget,
88
Manifold, Planar, Spherical, Geodesic, AutoManifold, WrongManifoldException,
9+
manifold, best_manifold,
910
Algorithm, AutoAlgorithm, ManifoldIndependentAlgorithm, SingleManifoldAlgorithm, NoAlgorithm,
1011
BoolsAsTypes, True, False, booltype, istrue,
1112
TaskFunctors,

src/types.jl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,26 @@ are present.
5252
"""
5353
abstract type CLibraryPlanarAlgorithm <: GeometryOpsCore.SingleManifoldAlgorithm{Planar} end
5454

55-
5655
function (::Type{T})(; params...) where {T <: CLibraryPlanarAlgorithm}
5756
nt = NamedTuple(params)
5857
return T(Planar(), nt)
5958
end
60-
(T::Type{<: CLibraryPlanarAlgorithm})(params::NamedTuple) = T(Planar(), params)
59+
(T::Type{<: CLibraryPlanarAlgorithm})(::Planar, params::NamedTuple) = T(params)
60+
61+
manifold(alg::CLibraryPlanarAlgorithm) = Planar()
62+
best_manifold(alg::CLibraryPlanarAlgorithm, input) = Planar()
63+
64+
function rebuild(alg::T, m::Planar) where {T <: CLibraryPlanarAlgorithm}
65+
return T(m, alg.params)
66+
end
6167

68+
function rebuild(alg::T, m::AutoManifold) where {T <: CLibraryPlanarAlgorithm}
69+
return T(Planar(), alg.params)
70+
end
71+
72+
function rebuild(alg::T, m::M) where {T <: CLibraryPlanarAlgorithm, M <: Manifold}
73+
throw(GeometryOpsCore.WrongManifoldException{M, Planar, T}("The algorithm `$(typeof(alg))` is only compatible with planar manifolds."))
74+
end
6275

6376
# These are definitions for convenience, so we don't have to type out
6477
# `alg.params` every time.
@@ -105,7 +118,6 @@ This uses the [LibGEOS.jl](https://github.com/JuliaGeometry/LibGEOS.jl) package,
105118
which is a Julia wrapper around the C library GEOS (https://trac.osgeo.org/geos).
106119
"""
107120
struct GEOS <: CLibraryPlanarAlgorithm # SingleManifoldAlgorithm{Planar}
108-
manifold::Planar
109121
params::NamedTuple
110122
end
111123

@@ -130,7 +142,6 @@ This uses the [TGGeometry.jl](https://github.com/JuliaGeo/TGGeometry.jl) package
130142
which is a Julia wrapper around the `tg` C library (https://github.com/tidwall/tg).
131143
"""
132144
struct TG <: CLibraryPlanarAlgorithm
133-
manifold::Planar
134145
params::NamedTuple
135146
end
136147

@@ -144,13 +155,22 @@ to use the appropriate PROJ function via `Proj.jl` for the operation.
144155
145156
## Extended help
146157
147-
This is the default algorithm for [`reproject`](@ref), and is also the default algorithm for
158+
This is the default algorithm for [`reproject`](@ref), and will also be the default algorithm for
159+
operations on geodesics like [`area`](@ref) and [`arclength`](@ref).
148160
"""
149161
struct PROJ{M <: Manifold} <: Algorithm{M}
150162
manifold::M
151163
params::NamedTuple
152164
end
153165

166+
PROJ() = PROJ(Planar(), NamedTuple())
167+
PROJ(; params...) = PROJ(Planar(), NamedTuple(params))
168+
PROJ(m::Manifold) = PROJ(m, NamedTuple())
169+
170+
manifold(alg::PROJ) = alg.manifold
171+
rebuild(alg::PROJ, m::Manifold) = PROJ(m, alg.params)
172+
rebuild(alg::PROJ, params::NamedTuple) = PROJ(alg.manifold, params)
173+
154174
# We repeat these functions here because PROJ does not subtype `CLibraryPlanarAlgorithm`.
155175

156176
Base.get(alg::PROJ, key, value) = Base.get(alg.params, key, value)

0 commit comments

Comments
 (0)