From 40ee0c19c8800f9f004f09093fe9b6583eeb223b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Fri, 22 Nov 2024 09:31:25 -0300 Subject: [PATCH] Refactor isequal on globe manifold (#1145) --- src/geometries/primitives/point.jl | 12 ++++++------ src/predicates/ordering.jl | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/geometries/primitives/point.jl b/src/geometries/primitives/point.jl index 0fe20f7ba..681f79ab5 100644 --- a/src/geometries/primitives/point.jl +++ b/src/geometries/primitives/point.jl @@ -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 @@ -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 @@ -167,5 +169,3 @@ _manifold(coords::CRS) = 𝔼{CoordRefSystems.ndims(coords)} _manifold(::LatLon) = 🌐 _manifold(::GeocentricLatLon) = 🌐 _manifold(::AuthalicLatLon) = 🌐 - -_lat(P) = convert(LatLon, P.coords).lat diff --git a/src/predicates/ordering.jl b/src/predicates/ordering.jl index b427dc3dd..b60944f49 100644 --- a/src/predicates/ordering.jl +++ b/src/predicates/ordering.jl @@ -49,3 +49,9 @@ See x ≥ zero(x), A - B) ⪰(A::Point{🌐}, B::Point{🌐}) = _lat(A) ≥ _lat(B) + +# ----------------- +# HELPER FUNCTIONS +# ----------------- + +_lat(point) = convert(LatLon, coords(point)).lat