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 missing tests #178

Merged
merged 1 commit into from
Sep 23, 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
18 changes: 18 additions & 0 deletions src/crs/geographic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ end
# avoid converting coordinates with the same datum as the first argument
Base.convert(::Type{LatLon{Datum}}, coords::LatLon{Datum}) where {Datum} = coords

function Base.convert(::Type{LatLonAlt{Datumₜ}}, coords::LatLonAlt{Datumₛ}) where {Datumₜ,Datumₛ}
cartₛ = convert(Cartesian{Datumₛ}, coords)
cartₜ = convert(Cartesian{Datumₜ}, cartₛ)
convert(LatLonAlt{Datumₜ}, cartₜ)
end

# avoid converting coordinates with the same datum as the first argument
Base.convert(::Type{LatLonAlt{Datum}}, coords::LatLonAlt{Datum}) where {Datum} = coords

function Base.convert(::Type{GeocentricLatLon{Datumₜ}}, coords::GeocentricLatLon{Datumₛ}) where {Datumₜ,Datumₛ}
cartₛ = convert(Cartesian{Datumₛ}, coords)
cartₜ = convert(Cartesian{Datumₜ}, cartₛ)
Expand All @@ -517,6 +526,15 @@ end
# avoid converting coordinates with the same datum as the first argument
Base.convert(::Type{GeocentricLatLon{Datum}}, coords::GeocentricLatLon{Datum}) where {Datum} = coords

function Base.convert(::Type{GeocentricLatLonAlt{Datumₜ}}, coords::GeocentricLatLonAlt{Datumₛ}) where {Datumₜ,Datumₛ}
cartₛ = convert(Cartesian{Datumₛ}, coords)
cartₜ = convert(Cartesian{Datumₜ}, cartₛ)
convert(GeocentricLatLonAlt{Datumₜ}, cartₜ)
end

# avoid converting coordinates with the same datum as the first argument
Base.convert(::Type{GeocentricLatLonAlt{Datum}}, coords::GeocentricLatLonAlt{Datum}) where {Datum} = coords

# ----------
# FALLBACKS
# ----------
Expand Down
204 changes: 195 additions & 9 deletions test/crs/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@
@inferred convert(LatLon, c2)
end

# altitude can only be calculated accurately using Float64
if T === Float64
# altitude can only be calculated accurately using Float64
@testset "LatLonAlt <> Cartesian" begin
c1 = LatLonAlt(T(30), T(40), T(0))
c2 = convert(Cartesian, c1)
Expand Down Expand Up @@ -456,6 +456,78 @@
@inferred convert(Cartesian, c1)
@inferred convert(LatLonAlt, c2)
end

@testset "LatLonAlt: Datum conversion" begin
# WGS84 (G1762) to ITRF2008
c1 = LatLonAlt{WGS84{1762}}(T(30), T(40), T(1))
c2 = convert(LatLonAlt{ITRF{2008}}, c1)
@test allapprox(c2, LatLonAlt{ITRF{2008}}(T(30), T(40), T(1.0000261394307017)))
c3 = convert(LatLonAlt{WGS84{1762}}, c2)
@test allapprox(c3, c1)

c1 = LatLonAlt{WGS84{1762}}(T(35), T(45), T(1))
c2 = convert(LatLonAlt{ITRF{2008}}, c1)
@test allapprox(c2, LatLonAlt{ITRF{2008}}(T(35), T(45), T(1.0000344086438417)))
c3 = convert(LatLonAlt{WGS84{1762}}, c2)
@test allapprox(c3, c1)

# ITRF2008 to ITRF2020
c1 = LatLonAlt{ITRF{2008}}(T(30), T(40), T(1))
c2 = convert(LatLonAlt{ITRF{2020}}, c1)
@test allapprox(c2, LatLonAlt{ITRF{2020}}(T(29.999999988422587), T(39.99999998545356), T(0.9975402476266026)))
c3 = convert(LatLonAlt{ITRF{2008}}, c2)
@test allapprox(c3, c1)

c1 = LatLonAlt{ITRF{2008}}(T(35), T(45), T(1))
c2 = convert(LatLonAlt{ITRF{2020}}, c1)
@test allapprox(c2, LatLonAlt{ITRF{2020}}(T(34.99999999095351), T(44.99999998605742), T(0.9973427625373006)))
c3 = convert(LatLonAlt{ITRF{2008}}, c2)
@test allapprox(c3, c1)

c1 = LatLonAlt{WGS84{1762}}(T(30), T(40), T(1))
c2 = LatLonAlt{ITRF{2008}}(T(30), T(40), T(1))
@inferred convert(LatLonAlt{ITRF{2008}}, c1)
@inferred convert(LatLonAlt{ITRF{2020}}, c2)
end

@testset "GeocentricLatLonAlt: Datum conversion" begin
# WGS84 (G1762) to ITRF2008
c1 = GeocentricLatLonAlt{WGS84{1762}}(T(30), T(40), T(1))
c2 = convert(GeocentricLatLonAlt{ITRF{2008}}, c1)
@test allapprox(c2, GeocentricLatLonAlt{ITRF{2008}}(T(30), T(40), T(1.0000264029949903)))
c3 = convert(GeocentricLatLonAlt{WGS84{1762}}, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLonAlt{WGS84{1762}}(T(35), T(45), T(1))
c2 = convert(GeocentricLatLonAlt{ITRF{2008}}, c1)
@test allapprox(c2, GeocentricLatLonAlt{ITRF{2008}}(T(35), T(45), T(1.0000347206369042)))
c3 = convert(GeocentricLatLonAlt{WGS84{1762}}, c2)
@test allapprox(c3, c1)

# ITRF2008 to ITRF2020
c1 = GeocentricLatLonAlt{ITRF{2008}}(T(30), T(40), T(1))
c2 = convert(GeocentricLatLonAlt{ITRF{2020}}, c1)
@test allapprox(
c2,
GeocentricLatLonAlt{ITRF{2020}}(T(29.999999988422587), T(39.99999998545356), T(0.997536551207304))
)
c3 = convert(GeocentricLatLonAlt{ITRF{2008}}, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLonAlt{ITRF{2008}}(T(35), T(45), T(1))
c2 = convert(GeocentricLatLonAlt{ITRF{2020}}, c1)
@test allapprox(
c2,
GeocentricLatLonAlt{ITRF{2020}}(T(34.99999999095351), T(44.99999998605742), T(0.9973396398127079))
)
c3 = convert(GeocentricLatLonAlt{ITRF{2008}}, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLonAlt{WGS84{1762}}(T(30), T(40), T(1))
c2 = GeocentricLatLonAlt{ITRF{2008}}(T(30), T(40), T(1))
@inferred convert(GeocentricLatLonAlt{ITRF{2008}}, c1)
@inferred convert(GeocentricLatLonAlt{ITRF{2020}}, c2)
end
end

@testset "LatLon: Datum conversion" begin
Expand Down Expand Up @@ -866,16 +938,37 @@
@inferred convert(LatLon{WGS84{0}}, c5)
end

@testset "LatLonAlt: Datum conversion" begin
# TODO
end

@testset "GeocentricLatLon: Datum conversion" begin
# TODO
end
# WGS84 (G1762) to ITRF2008
c1 = GeocentricLatLon{WGS84{1762}}(T(30), T(40))
c2 = convert(GeocentricLatLon{ITRF{2008}}, c1)
@test allapprox(c2, GeocentricLatLon{ITRF{2008}}(T(30), T(40)))
c3 = convert(GeocentricLatLon{WGS84{1762}}, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLon{WGS84{1762}}(T(35), T(45))
c2 = convert(GeocentricLatLon{ITRF{2008}}, c1)
@test allapprox(c2, GeocentricLatLon{ITRF{2008}}(T(35), T(45)))
c3 = convert(GeocentricLatLon{WGS84{1762}}, c2)
@test allapprox(c3, c1)

# ITRF2008 to ITRF2020
c1 = GeocentricLatLon{ITRF{2008}}(T(30), T(40))
c2 = convert(GeocentricLatLon{ITRF{2020}}, c1)
@test allapprox(c2, GeocentricLatLon{ITRF{2020}}(T(29.999999988624147), T(39.99999998542911)))
c3 = convert(GeocentricLatLon{ITRF{2008}}, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLon{ITRF{2008}}(T(35), T(45))
c2 = convert(GeocentricLatLon{ITRF{2020}}, c1)
@test allapprox(c2, GeocentricLatLon{ITRF{2020}}(T(34.999999991156464), T(44.99999998602658)))
c3 = convert(GeocentricLatLon{ITRF{2008}}, c2)
@test allapprox(c3, c1)

@testset "GeocentricLatLonAlt: Datum conversion" begin
# TODO
c1 = GeocentricLatLon{WGS84{1762}}(T(30), T(40))
c2 = GeocentricLatLon{ITRF{2008}}(T(30), T(40))
@inferred convert(GeocentricLatLon{ITRF{2008}}, c1)
@inferred convert(GeocentricLatLon{ITRF{2020}}, c2)
end
end

Expand Down Expand Up @@ -1378,6 +1471,99 @@
@inferred convert(LatLon{ITRF{2008}}, c2)
end

@testset "LatLonAlt <> Projected" begin
c1 = LatLonAlt(T(45), T(90), T(0))
c2 = convert(Mercator, c1)
@test allapprox(c2, Mercator(T(10018754.171394622), T(5591295.9185533915)))
c3 = convert(LatLonAlt, c2)
@test allapprox(c3, c1)

c1 = LatLonAlt(T(45), T(90), T(0))
c2 = convert(WinkelTripel, c1)
@test allapprox(c2, WinkelTripel(T(7044801.6979576545), T(5231448.051548355)))
c3 = convert(LatLonAlt, c2)
@test allapprox(c3, c1)

ShiftedMercator = CoordRefSystems.shift(Mercator{WGS84Latest}, lonₒ=15.0°, xₒ=200.0m, yₒ=200.0m)
c1 = LatLonAlt(T(45), T(90), T(0))
c2 = convert(ShiftedMercator, c1)
@test allapprox(c2, ShiftedMercator(T(8349161.809495518), T(5591495.9185533915)))
c3 = convert(LatLonAlt, c2)
@test allapprox(c3, c1)

# type stability
c1 = LatLonAlt(T(45), T(90), T(0))
c2 = Mercator(T(10018754.171394622), T(5591295.9185533915))
c3 = WinkelTripel(T(7044801.6979576545), T(5231448.051548355))
c4 = ShiftedMercator(T(8349161.809495518), T(5591495.9185533915))
@inferred convert(Mercator, c1)
@inferred convert(LatLonAlt, c2)
@inferred convert(LatLonAlt, c3)
@inferred convert(LatLonAlt, c4)
end

@testset "GeocentricLatLon <> Projected" begin
c1 = GeocentricLatLon(T(45), T(90))
c2 = convert(Mercator, c1)
@test allapprox(c2, Mercator(T(10018754.171394622), T(5621538.488121794)))
c3 = convert(GeocentricLatLon, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLon(T(45), T(90))
c2 = convert(WinkelTripel, c1)
@test allapprox(c2, WinkelTripel(T(7034650.123120441), T(5253308.640402036)))
c3 = convert(GeocentricLatLon, c2)
@test allapprox(c3, c1)

ShiftedMercator = CoordRefSystems.shift(Mercator{WGS84Latest}, lonₒ=15.0°, xₒ=200.0m, yₒ=200.0m)
c1 = GeocentricLatLon(T(45), T(90))
c2 = convert(ShiftedMercator, c1)
@test allapprox(c2, ShiftedMercator(T(8349161.809495518), T(5621738.488121794)))
c3 = convert(GeocentricLatLon, c2)
@test allapprox(c3, c1)

# type stability
c1 = GeocentricLatLon(T(45), T(90))
c2 = Mercator(T(10018754.171394622), T(5621538.488121794))
c3 = WinkelTripel(T(7034650.123120441), T(5253308.640402036))
c4 = ShiftedMercator(T(8349161.809495518), T(5621738.488121794))
@inferred convert(Mercator, c1)
@inferred convert(GeocentricLatLon, c2)
@inferred convert(GeocentricLatLon, c3)
@inferred convert(GeocentricLatLon, c4)
end

@testset "GeocentricLatLonAlt <> Projected" begin
c1 = GeocentricLatLonAlt(T(45), T(90), T(0))
c2 = convert(Mercator, c1)
@test allapprox(c2, Mercator(T(10018754.171394622), T(5621538.488121794)))
c3 = convert(GeocentricLatLonAlt, c2)
@test allapprox(c3, c1)

c1 = GeocentricLatLonAlt(T(45), T(90), T(0))
c2 = convert(WinkelTripel, c1)
@test allapprox(c2, WinkelTripel(T(7034650.123120441), T(5253308.640402036)))
c3 = convert(GeocentricLatLonAlt, c2)
@test allapprox(c3, c1)

ShiftedMercator = CoordRefSystems.shift(Mercator{WGS84Latest}, lonₒ=15.0°, xₒ=200.0m, yₒ=200.0m)
c1 = GeocentricLatLonAlt(T(45), T(90), T(0))
c2 = convert(ShiftedMercator, c1)
@test allapprox(c2, ShiftedMercator(T(8349161.809495518), T(5621738.488121794)))
c3 = convert(GeocentricLatLonAlt, c2)
@test allapprox(c3, c1)

# type stability
c1 = GeocentricLatLonAlt(T(45), T(90), T(0))
c2 = Mercator(T(10018754.171394622), T(5621538.488121794))
c3 = WinkelTripel(T(7034650.123120441), T(5253308.640402036))
c4 = ShiftedMercator(T(8349161.809495518), T(5621738.488121794))
@inferred convert(Mercator, c1)
@inferred convert(GeocentricLatLonAlt, c2)
@inferred convert(GeocentricLatLonAlt, c3)
@inferred convert(GeocentricLatLonAlt, c4)
end

@testset "Cartesian <> Projected" begin
ShiftedMercator = CoordRefSystems.shift(Mercator{WGS84Latest}, lonₒ=15.0°, xₒ=200.0m, yₒ=200.0m)

Expand Down
4 changes: 4 additions & 0 deletions test/crs/crsapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,12 @@
@test convert(Cartesian, c) === c
c = LatLon(T(45), T(90))
@test convert(LatLon, c) === c
c = LatLonAlt(T(45), T(90), T(1))
@test convert(LatLonAlt, c) === c
c = GeocentricLatLon(T(45), T(90))
@test convert(GeocentricLatLon, c) === c
c = GeocentricLatLonAlt(T(45), T(90), T(1))
@test convert(GeocentricLatLonAlt, c) === c
c = OrthoNorth(T(1), T(1))
@test convert(OrthoNorth, c) === c

Expand Down
8 changes: 8 additions & 0 deletions test/crs/mactype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
c2 = convert(C, c1)
@test c2 isa C

C = GeocentricLatLonAlt{WGS84Latest,Deg{T},Met{T}}
c1 = GeocentricLatLonAlt(1.0, 1.0, 1.0)
c2 = convert(C, c1)
@test c2 isa C
c1 = GeocentricLatLonAlt(1.0f0, 1.0f0, 1.0f0)
c2 = convert(C, c1)
@test c2 isa C

C = AuthalicLatLon{WGS84Latest,Deg{T}}
c1 = AuthalicLatLon(1.0, 1.0)
c2 = convert(C, c1)
Expand Down
3 changes: 3 additions & 0 deletions test/crs/rand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
randtest(GeocentricLatLon{WGS84Latest})
randtest(GeocentricLatLon)

randtest(GeocentricLatLonAlt{WGS84Latest})
randtest(GeocentricLatLonAlt)

randtest(AuthalicLatLon{WGS84Latest})
randtest(AuthalicLatLon)
end
Expand Down
Loading