Skip to content

Commit d59c588

Browse files
committed
Move algorithm examples to Julia code block in comment
1 parent ad1e21a commit d59c588

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

GeometryOpsCore/src/types/algorithm.jl

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ Algorithms are:
1212
* May be manifold agnostic (like simplification) or restrictive (like GEOS only works on planar, PROJ algorithm for arclength and area only works on geodesic)
1313
* May or may not carry manifolds around, but manifold should always be accessible from manifold(alg) - it's not necessary that fixed manifold args can skip carrying the manifold around, eg in the case of Proj{Geodesic}.
1414
15+
16+
## Single manifold vs manifold independent algorithms
17+
18+
Some algorithms only work on a single manifold (shoelace area only works on `Planar`)
19+
and others work on any manifold (`simplify`, `segmentize`). They are allowed to dispatch
20+
on the manifold type but store that manifold as a field, and the fundamental algorithm is the
21+
same. For example the segmentize algorithm is the same (distance along line) but the implementation
22+
varies slightly depending on the manifold (planar, spherical, geodesic, etc).
23+
24+
Here's a simple example of two algorithms, one only on planar and one manifold independent:
25+
26+
```julia
27+
28+
struct MyExternalArbitraryPackageAlgorithm <: SingleManifoldAlgorithm{Planar}
29+
kw1::Int
30+
kw2::String
31+
end # this already has the methods specified
32+
33+
struct MyIndependentAlgorithm{M <: Manifold} <: ManifoldIndependentAlgorithm{M}
34+
m::M
35+
kw1::Int
36+
kw2::String
37+
end
38+
39+
MyIndependentAlgorithm(m::Manifold; kw1 = 1, kw2 = "hello") = MyIndependentAlgorithm(m, kw1, kw2)
40+
```
1541
=#
1642

1743
export Algorithm, AutoAlgorithm, ManifoldIndependentAlgorithm, SingleManifoldAlgorithm, NoAlgorithm
@@ -50,18 +76,3 @@ function (Alg::Type{<: ManifoldIndependentAlgorithm{M}})(m::Manifold; kwargs...)
5076
# throw a WrongManifoldException and be done with it
5177
throw(WrongManifoldException{typeof(m), M, Alg}())
5278
end
53-
54-
# for example
55-
56-
struct MyExternalArbitraryPackageAlgorithm <: SingleManifoldAlgorithm{Planar}
57-
kw1::Int
58-
kw2::String
59-
end # this already has the methods specified
60-
61-
struct MyIndependentAlgorithm{M <: Manifold} <: ManifoldIndependentAlgorithm{M}
62-
m::M
63-
kw1::Int
64-
kw2::String
65-
end
66-
67-
MyIndependentAlgorithm(m::Manifold; kw1 = 1, kw2 = "hello") = MyIndependentAlgorithm(m, kw1, kw2)

GeometryOpsCore/src/types/operation.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,26 @@ but if we ever implement e.g. RelateNG in GeometryOps, we can add that in.
3939

4040
abstract type Operation{Alg <: Algorithm} end
4141

42-
# example
43-
# struct XPlusOneOperation{M <: Manifold} <: Operation{NoAlgorithm{M}}
44-
# m::M # the manifold always needs to be stored, since it's not a singleton
45-
# x::Int
46-
# end
42+
#=
43+
Here's an example of how this might work:
4744
45+
```julia
46+
struct XPlusOneOperation{M <: Manifold} <: Operation{NoAlgorithm{M}}
47+
m::M # the manifold always needs to be stored, since it's not a singleton
48+
x::Int
49+
end
50+
```
4851
49-
# struct Area{Alg<: Algorithm} <: Operation{Alg}
50-
# alg::Alg
51-
# end
52+
```julia
53+
struct Area{Alg<: Algorithm} <: Operation{Alg}
54+
alg::Alg
55+
end
5256
53-
# Area() = Area(NoAlgorithm(Planar()))
57+
Area() = Area(NoAlgorithm(Planar()))
58+
59+
function (op::Area{Alg})(data; threaded = _False(), init = 0.0) where {Alg <: Algorithm}
60+
return GO.area(op.alg, data; threaded, init)
61+
end
62+
```
5463
55-
# function (op::Area{Alg})(data; threaded = _False(), init = 0.0) where {Alg <: Algorithm}
56-
# return GO.area(op.alg, data; threaded, init)
57-
# end
64+
=#

0 commit comments

Comments
 (0)