Skip to content

Commit

Permalink
make latlng::operator== robust within 100*epsilon
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Sep 5, 2024
1 parent 9ef1edd commit 50fa196
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/geo/latlng.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cmath>
#include <cstdint>
#include <array>
#include <iosfwd>
Expand All @@ -18,7 +19,10 @@ struct latlng {
}

friend bool operator==(latlng const& lhs, latlng const& rhs) noexcept {
return std::tie(lhs.lat_, lhs.lng_) == std::tie(rhs.lat_, rhs.lng_);
auto const lat_diff = std::abs(lhs.lat_ - rhs.lat_);
auto const lng_diff = std::abs(lhs.lng_ - rhs.lng_);
return lat_diff < 100 * std::numeric_limits<double>::epsilon() &&
lng_diff < 100 * std::numeric_limits<double>::epsilon();
}

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

0 comments on commit 50fa196

Please sign in to comment.