Skip to content

Commit f65032a

Browse files
authoredJun 3, 2024
Fix the implementation of the 'Haversine' distance (#860)
·
v0.54.2v0.44.0
1 parent e071b55 commit f65032a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎src/distances.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ end
5555

5656
function evaluate(d::Haversine, p₁::Point{Dim,<:LatLon}, p₂::Point{Dim,<:LatLon}) where {Dim}
5757
uᵣ = unit(d.radius)
58-
u = uᵣ === NoUnits ? u"m" : uᵣ
58+
# add default unit if necessary
59+
u = uᵣ === NoUnits ? u"m" : NoUnits
5960
latlon₁ = coords(p₁)
6061
latlon₂ = coords(p₂)
6162
v₁ = SVector(latlon₁.lon, latlon₁.lat)

‎test/distances.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
p4 = Point(cart2)
3333
@test evaluate(Haversine(), p1, p2) T(111194.92664455874) * u"m"
3434
@test evaluate(Haversine(), p3, p4) T(111194.92664455874) * u"m"
35+
@test evaluate(Haversine(6371000u"m"), p1, p2) T(111194.92664455874) * u"m"
36+
@test evaluate(Haversine(6371000u"m"), p3, p4) T(111194.92664455874) * u"m"
37+
@test evaluate(Haversine(6371u"km"), p1, p2) T(111.19492664455874) * u"km"
38+
@test evaluate(Haversine(6371u"km"), p3, p4) T(111.19492664455874) * u"km"
3539
@test evaluate(SphericalAngle(), p1, p2) deg2rad(T(1) * u"°")
3640
@test evaluate(SphericalAngle(), p3, p4) deg2rad(T(1) * u"°")
3741
end

0 commit comments

Comments
 (0)
Please sign in to comment.