File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,15 +35,22 @@ class LatLng {
3535 LatLng& operator =(const LatLng & other) = default ;
3636
3737 bool operator ==(const LatLng & other) const {
38- return isCoordinateEqual (lat, other.lat ) &&
39- isCoordinateEqual (lng, other.lng );
38+ return isCoordinateEqual (lat, other.lat ) &&
39+ isLngEqual (lng, other.lng );
4040 }
4141
4242
4343private:
4444 bool isCoordinateEqual (double first, double second) const {
4545 return std::fabs (first - second) < 1e-12 ;
4646 }
47+
48+ // Longitude wraps: 180° and -180° are the same meridian.
49+ bool isLngEqual (double a, double b) const {
50+ double diff = std::fabs (std::fmod (a - b, 360.0 ));
51+ if (diff > 180.0 ) diff = 360.0 - diff;
52+ return diff < 1e-12 ;
53+ }
4754};
4855
4956#endif // GEOMETRY_LIBRARY_LATLNG
Original file line number Diff line number Diff line change 1+ #include < gtest/gtest.h>
2+
3+ #include " LatLng.hpp"
4+
5+ TEST (LatLng, operator_equal) {
6+ // Basic equality and inequality
7+ EXPECT_TRUE (LatLng ( 0 , 0 ) == LatLng ( 0 , 0 ));
8+ EXPECT_FALSE (LatLng ( 0 , 0 ) == LatLng ( 1 , 0 ));
9+ EXPECT_FALSE (LatLng ( 0 , 0 ) == LatLng ( 0 , 1 ));
10+ EXPECT_FALSE (LatLng ( 1 , 0 ) == LatLng (-1 , 0 ));
11+
12+ // ±180° is the same meridian
13+ EXPECT_TRUE (LatLng ( 0 , 180 ) == LatLng ( 0 , -180 ));
14+ EXPECT_TRUE (LatLng ( 45 , 180 ) == LatLng ( 45 , -180 ));
15+ EXPECT_TRUE (LatLng (-45 , 180 ) == LatLng (-45 , -180 ));
16+ }
Original file line number Diff line number Diff line change 11/* * Including all tests */
2+ #include " LatLng/operator_equal.hpp"
3+
24#include " MathUtil/mod.hpp"
35
46#include " SphericalUtil/interpolate.hpp"
You can’t perform that action at this time.
0 commit comments