Skip to content

Commit 84efe55

Browse files
authored
Remove 'boundary' option in favor of using 'TransformedGeometry' explicitly (#1119)
1 parent c4235fb commit 84efe55

File tree

3 files changed

+34
-89
lines changed

3 files changed

+34
-89
lines changed

src/transforms/morphological.jl

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,33 @@
33
# ------------------------------------------------------------------
44

55
"""
6-
Morphological(fun; boundary=false)
6+
Morphological(fun)
77
88
Morphological transform given by a function `fun`
99
that maps the coordinates of a geometry or a domain
1010
to new coordinates (`coords -> newcoords`).
1111
12-
Optionally, the transform samples the `boundary` of
13-
polytopes, if this option is `true`, to handle distortions
14-
that occur in manifold conversions.
15-
16-
# Examples
12+
## Examples
1713
1814
```julia
1915
ball = Ball((0, 0), 1)
2016
ball |> Morphological(c -> Cartesian(c.x + c.y, c.y, c.x - c.y))
2117
22-
triangle = Triangle(latlon(0, 0), latlon(0, 45), latlon(45, 0))
23-
triangle |> Morphological(c -> LatLonAlt(c.lat, c.lon, 0.0m), boundary=true)
18+
triangle = Triangle(Point(LatLon(0, 0)), Point(LatLon(0, 45)), Point(LatLon(45, 0)))
19+
triangle |> Morphological(c -> LatLonAlt(c.lat, c.lon, 0.0m))
2420
```
21+
22+
### Notes
23+
24+
* By default, only the vertices of the polytopes are transformed,
25+
disregarding distortions that occur in manifold conversions.
26+
To handle this case, use [`TransformedGeometry`](@ref).
2527
"""
26-
struct Morphological{Boundary,F<:Function} <: CoordinateTransform
28+
struct Morphological{F<:Function} <: CoordinateTransform
2729
fun::F
28-
Morphological{Boundary}(fun::F) where {Boundary,F<:Function} = new{Boundary,F}(fun)
2930
end
3031

31-
Morphological(fun; boundary=false) = Morphological{boundary}(fun)
32-
33-
parameters(t::Morphological{Boundary}) where {Boundary} = (fun=t.fun, boundary=Boundary)
32+
parameters(t::Morphological) = (; fun=t.fun)
3433

3534
applycoord(t::Morphological, p::Point) = Point(t.fun(coords(p)))
3635

@@ -42,24 +41,8 @@ applycoord(::Morphological, v::Vec) = v
4241

4342
applycoord(t::Morphological, g::Primitive) = TransformedGeometry(g, t)
4443

45-
applycoord(t::Morphological{true}, g::Polytope) = TransformedGeometry(g, t)
46-
4744
applycoord(t::Morphological, g::RegularGrid) = TransformedGrid(g, t)
4845

4946
applycoord(t::Morphological, g::RectilinearGrid) = TransformedGrid(g, t)
5047

5148
applycoord(t::Morphological, g::StructuredGrid) = TransformedGrid(g, t)
52-
53-
# -----------
54-
# IO METHODS
55-
# -----------
56-
57-
Base.show(io::IO, t::Morphological{Boundary}) where {Boundary} =
58-
print(io, "Morphological(fun: $(t.fun), boundary: $Boundary)")
59-
60-
function Base.show(io::IO, ::MIME"text/plain", t::Morphological{Boundary}) where {Boundary}
61-
summary(io, t)
62-
println(io)
63-
println(io, "├─ fun: $(t.fun)")
64-
print(io, "└─ boundary: $Boundary")
65-
end

src/transforms/proj.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# ------------------------------------------------------------------
44

55
"""
6-
Proj(CRS; boundary=false)
7-
Proj(code; boundary=false)
6+
Proj(CRS)
7+
Proj(code)
88
99
Convert the coordinates of geometry or domain to a given
1010
coordinate reference system `CRS` or EPSG/ESRI `code`.
@@ -21,18 +21,23 @@ Proj(WebMercator)
2121
Proj(Mercator{WGS84Latest})
2222
Proj(EPSG{3395})
2323
Proj(ESRI{54017})
24-
Proj(Robinson, boundary=true)
2524
```
25+
26+
### Notes
27+
28+
* By default, only the vertices of the polytopes are transformed,
29+
disregarding distortions that occur in manifold conversions.
30+
To handle this case, use [`TransformedGeometry`](@ref).
2631
"""
27-
struct Proj{CRS,Boundary} <: CoordinateTransform end
32+
struct Proj{CRS} <: CoordinateTransform end
2833

29-
Proj(CRS; boundary=false) = Proj{CRS,boundary}()
34+
Proj(CRS) = Proj{CRS}()
3035

31-
Proj(code::Type{<:EPSG}; kwargs...) = Proj(CoordRefSystems.get(code); kwargs...)
36+
Proj(code::Type{<:EPSG}) = Proj(CoordRefSystems.get(code))
3237

33-
Proj(code::Type{<:ESRI}; kwargs...) = Proj(CoordRefSystems.get(code); kwargs...)
38+
Proj(code::Type{<:ESRI}) = Proj(CoordRefSystems.get(code))
3439

35-
parameters(::Proj{CRS,Boundary}) where {CRS,Boundary} = (CRS=CRS, boundary=Boundary)
40+
parameters(::Proj{CRS}) where {CRS} = (; CRS)
3641

3742
# avoid constructing a new geometry or domain when the CRS is the same
3843
function apply(t::Proj{CRS}, g::GeometryOrDomain) where {CRS}
@@ -60,10 +65,6 @@ applycoord(t::Proj{<:Projected}, g::Primitive{<:🌐}) = TransformedGeometry(g,
6065

6166
applycoord(t::Proj{<:Geographic}, g::Primitive{<:𝔼}) = TransformedGeometry(g, t)
6267

63-
applycoord(t::Proj{<:Projected,true}, g::Polytope{K,<:🌐}) where {K} = TransformedGeometry(g, t)
64-
65-
applycoord(t::Proj{<:Geographic,true}, g::Polytope{K,<:𝔼}) where {K} = TransformedGeometry(g, t)
66-
6768
applycoord(t::Proj, g::RegularGrid) = TransformedGrid(g, t)
6869

6970
applycoord(t::Proj, g::RectilinearGrid) = TransformedGrid(g, t)
@@ -74,13 +75,12 @@ applycoord(t::Proj, g::StructuredGrid) = TransformedGrid(g, t)
7475
# IO METHODS
7576
# -----------
7677

77-
Base.show(io::IO, ::Proj{CRS,Boundary}) where {CRS,Boundary} = print(io, "Proj(CRS: $CRS, boundary: $Boundary)")
78+
Base.show(io::IO, ::Proj{CRS}) where {CRS} = print(io, "Proj(CRS: $CRS)")
7879

79-
function Base.show(io::IO, ::MIME"text/plain", t::Proj{CRS,Boundary}) where {CRS,Boundary}
80+
function Base.show(io::IO, ::MIME"text/plain", t::Proj{CRS}) where {CRS}
8081
summary(io, t)
8182
println(io)
82-
println(io, "├─ CRS: $CRS")
83-
print(io, "└─ boundary: $Boundary")
83+
print(io, "└─ CRS: $CRS")
8484
end
8585

8686
# -----------------

test/transforms.jl

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,15 +1251,14 @@ end
12511251
@test !isaffine(Proj(Polar))
12521252
@test !TB.isrevertible(Proj(Polar))
12531253
@test !TB.isinvertible(Proj(Polar))
1254-
@test TB.parameters(Proj(Polar)) == (CRS=Polar, boundary=false)
1255-
@test TB.parameters(Proj(EPSG{3395})) == (CRS=Mercator{WGS84Latest}, boundary=false)
1256-
@test TB.parameters(Proj(ESRI{54017})) == (CRS=Behrmann{WGS84Latest}, boundary=false)
1254+
@test TB.parameters(Proj(Polar)) == (; CRS=Polar)
1255+
@test TB.parameters(Proj(EPSG{3395})) == (; CRS=Mercator{WGS84Latest})
1256+
@test TB.parameters(Proj(ESRI{54017})) == (; CRS=Behrmann{WGS84Latest})
12571257
f = Proj(Mercator)
1258-
@test sprint(show, f) == "Proj(CRS: CoordRefSystems.Mercator, boundary: false)"
1258+
@test sprint(show, f) == "Proj(CRS: CoordRefSystems.Mercator)"
12591259
@test sprint(show, MIME"text/plain"(), f) == """
12601260
Proj transform
1261-
├─ CRS: CoordRefSystems.Mercator
1262-
└─ boundary: false"""
1261+
└─ CRS: CoordRefSystems.Mercator"""
12631262

12641263
# ----
12651264
# VEC
@@ -1458,39 +1457,14 @@ end
14581457
f = Proj(crs(merc(0, 0)))
14591458
r, c = TB.apply(f, d)
14601459
@test r === d
1461-
1462-
# ----------------
1463-
# BOUNDARY OPTION
1464-
# ----------------
1465-
1466-
f = Proj(Mercator, boundary=false)
1467-
g = Triangle(latlon(0, 0), latlon(0, 45), latlon(45, 0))
1468-
r, c = TB.apply(f, g)
1469-
@test r isa Triangle
1470-
f = Proj(Mercator, boundary=true)
1471-
r, c = TB.apply(f, g)
1472-
@test r isa TransformedGeometry
1473-
1474-
f = Proj(LatLon, boundary=false)
1475-
g = Triangle(merc(0, 0), merc(1, 0), merc(1, 1))
1476-
r, c = TB.apply(f, g)
1477-
@test r isa Triangle
1478-
f = Proj(LatLon, boundary=true)
1479-
r, c = TB.apply(f, g)
1480-
@test r isa TransformedGeometry
14811460
end
14821461

14831462
@testitem "Morphological" setup = [Setup] begin
14841463
f = Morphological(c -> c)
14851464
@test !isaffine(f)
14861465
@test !TB.isrevertible(f)
14871466
@test !TB.isinvertible(f)
1488-
@test TB.parameters(f) == (fun=f.fun, boundary=false)
1489-
@test sprint(show, f) == "Morphological(fun: $(f.fun), boundary: false)"
1490-
@test sprint(show, MIME"text/plain"(), f) == """
1491-
Morphological transform
1492-
├─ fun: $(f.fun)
1493-
└─ boundary: false"""
1467+
@test TB.parameters(f) == (; fun=f.fun)
14941468

14951469
# ----
14961470
# VEC
@@ -1616,18 +1590,6 @@ end
16161590
d = SimpleMesh(p, c)
16171591
r, c = TB.apply(f, d)
16181592
@test r SimpleMesh(f.(vertices(d)), topology(d))
1619-
1620-
# ----------------
1621-
# BOUNDARY OPTION
1622-
# ----------------
1623-
1624-
f = Morphological(c -> Cartesian(c.x, c.y, zero(c.x)), boundary=false)
1625-
g = Triangle(cart(0, 0), cart(1, 0), cart(1, 1))
1626-
r, c = TB.apply(f, g)
1627-
@test r isa Triangle
1628-
f = Morphological(c -> Cartesian(c.x, c.y, zero(c.x)), boundary=true)
1629-
r, c = TB.apply(f, g)
1630-
@test r isa TransformedGeometry
16311593
end
16321594

16331595
@testitem "LengthUnit" setup = [Setup] begin

0 commit comments

Comments
 (0)