Skip to content

Commit 0a14add

Browse files
make latlng::operator== robust within 100*epsilon
1 parent 9ef1edd commit 0a14add

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/geo/latlng.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#pragma once
22

3+
#include <cmath>
34
#include <cstdint>
45
#include <array>
56
#include <iosfwd>
7+
#include <limits>
68
#include <tuple>
79

810
namespace geo {
@@ -18,7 +20,10 @@ struct latlng {
1820
}
1921

2022
friend bool operator==(latlng const& lhs, latlng const& rhs) noexcept {
21-
return std::tie(lhs.lat_, lhs.lng_) == std::tie(rhs.lat_, rhs.lng_);
23+
auto const lat_diff = std::abs(lhs.lat_ - rhs.lat_);
24+
auto const lng_diff = std::abs(lhs.lng_ - rhs.lng_);
25+
return lat_diff < 100 * std::numeric_limits<double>::epsilon() &&
26+
lng_diff < 100 * std::numeric_limits<double>::epsilon();
2227
}
2328

2429
std::array<double, 2> lnglat() const noexcept { return {lng_, lat_}; }

0 commit comments

Comments
 (0)