JuliaEarth/CoordRefSystems.jl

Cartesian isapprox should do vector comparison instead of elementwise comparison

ettersi opened this issue · 0 comments

isapprox(::Cartesian, ::Cartesian) currently fails for points with lon ≈ ±90° (e.g. Memphis, Tennessee).

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.

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₂))
end

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.