Repository: JuliaEarth/CoordRefSystems.jl (julia)

Issue:
Cartesian isapprox should do vector comparison instead of elementwise comparison
`isapprox(::Cartesian, ::Cartesian)` currently fails for points with `lon ≈ ±90°` (e.g. [Memphis, Tennessee](https://maps.app.goo.gl/zwZz7Tz5KLL4zzaE9)). 

```julia
julia> r = convert(Cartesian, LatLon(0,0)).x
6.378137e6 m

julia> convert(Cartesian, LatLon(0, 90)) ≈ Cartesian{WGS84Latest}(0u"m", r, 0u"m")
false
```

The problem is that `isapprox(::Cartesian, ::Cartesian)` currently compares every entry one by one for approximate equality. 

https://github.com/JuliaEarth/CoordRefSystems.jl/blob/14940f9ab20cf320729af1668a3629778d1b5be5/src/crs/basic.jl#L61-L65

Instead, it should do a vector comparison, `isapprox(x::Cartesian, y::Cartesian) = norm(x - y) / max(norm(x), norm(y))`, analogous to [how `Base` does it](https://github.com/JuliaLang/julia/blob/6737a1de25a835870641d8d1f3c507ee60e24cc0/stdlib/LinearAlgebra/src/generic.jl#L1811-L1823).

Pull request description:
Fix #53

Patch:
diff --git a/src/crs/basic.jl b/src/crs/basic.jl
index 1c7e7c59..100e1008 100644
--- a/src/crs/basic.jl
+++ b/src/crs/basic.jl
@@ -59,9 +59,10 @@ function Base.getproperty(coords::Cartesian, name::Symbol)
 end
 
 function Base.isapprox(coords₁::C, coords₂::C; kwargs...) where {C<:Cartesian}
-  tup₁ = _coords(coords₁)
-  tup₂ = _coords(coords₂)
-  all(isapprox(c₁, c₂; kwargs...) for (c₁, c₂) in zip(tup₁, tup₂))
+  # https://github.com/JuliaEarth/CoordRefSystems.jl/issues/53
+  c₁ = _coords(coords₁) |> SVector
+  c₂ = _coords(coords₂) |> SVector
+  isapprox(c₁, c₂; kwargs...)
 end
 
 function Base.summary(io::IO, coords::Cartesian)


Test patch:
diff --git a/test/misc.jl b/test/misc.jl
new file mode 100644
index 00000000..25f60720
--- /dev/null
+++ b/test/misc.jl
@@ -0,0 +1,7 @@
+@testset "Miscellaneous" begin
+  # https://github.com/JuliaEarth/CoordRefSystems.jl/issues/53
+  c1 = convert(Cartesian, LatLon(0, 0))
+  c2 = convert(Cartesian, LatLon(0, 90))
+  c3 = Cartesian{WGS84Latest}(0u"m", c1.x, 0u"m")
+  @test c2 ≈ c3
+end
diff --git a/test/runtests.jl b/test/runtests.jl
index 4725d9d8..300babdd 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -2,7 +2,7 @@ using CoordRefSystems
 using Unitful
 using Test
 
-testfiles = ["ellipsoids.jl", "datums.jl", "crs.jl", "codes.jl"]
+testfiles = ["ellipsoids.jl", "datums.jl", "crs.jl", "codes.jl", "misc.jl"]
 
 # --------------------------------
 # RUN TESTS WITH SINGLE PRECISION