Skip to content

Commit

Permalink
Refactor isequal on globe manifold (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm authored Nov 22, 2024
1 parent 9a7e160 commit 40ee0c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/geometries/primitives/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Base.convert(::Type{Point{M,CRS}}, p::Point{M,CRS}) where {M,CRS} = p

# promotion
function Base.promote(A::Point, B::Point)
a, b = promote(coords(A), coords(B))
a, b = promote(A.coords, B.coords)
Point(a), Point(b)
end

Expand All @@ -61,10 +61,12 @@ function ==(A::Point, B::Point)
to(A′) == to(B′)
end

function ==(A::Point{🌐,<:LatLon}, B::Point{🌐,<:LatLon})
function ==(A::Point{🌐}, B::Point{🌐})
A′, B′ = promote(A, B)
lat₁, lon₁ = A′.coords.lat, A′.coords.lon
lat₂, lon₂ = B′.coords.lat, B′.coords.lon
latlon₁ = convert(LatLon, A′.coords)
latlon₂ = convert(LatLon, B′.coords)
lat₁, lon₁ = latlon₁.lat, latlon₁.lon
lat₂, lon₂ = latlon₂.lat, latlon₂.lon
lat₁ == lat₂ && lon₁ == lon₂ || (abs(lon₁) == 180u"°" && lon₁ == -lon₂)
end

Expand Down Expand Up @@ -167,5 +169,3 @@ _manifold(coords::CRS) = 𝔼{CoordRefSystems.ndims(coords)}
_manifold(::LatLon) = 🌐
_manifold(::GeocentricLatLon) = 🌐
_manifold(::AuthalicLatLon) = 🌐

_lat(P) = convert(LatLon, P.coords).lat
6 changes: 6 additions & 0 deletions src/predicates/ordering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ See <https://en.wikipedia.org/wiki/Partially_ordered_set#Orders_on_the_Cartesian
"""
(A::Point, B::Point) = all(x -> x zero(x), A - B)
(A::Point{🌐}, B::Point{🌐}) = _lat(A) _lat(B)

# -----------------
# HELPER FUNCTIONS
# -----------------

_lat(point) = convert(LatLon, coords(point)).lat

0 comments on commit 40ee0c1

Please sign in to comment.