Commit 4879391b authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'fuzzycompare' into 'master'

Fuzzy Compare

See merge request !110
parents b9ee21c9 1e1c7a7c
Pipeline #152485 passed with stages
in 17 minutes and 53 seconds
...@@ -3,6 +3,7 @@ TRIBITS_SUBPACKAGE(core) ...@@ -3,6 +3,7 @@ TRIBITS_SUBPACKAGE(core)
TRIBITS_CONFIGURE_FILE(visibility.hh) TRIBITS_CONFIGURE_FILE(visibility.hh)
SET(HEADERS SET(HEADERS
fuzzy.hh
json.hh json.hh
system.hh system.hh
stringfunctions.i.hh stringfunctions.i.hh
...@@ -10,6 +11,7 @@ stringfunctions.hh ...@@ -10,6 +11,7 @@ stringfunctions.hh
value.hh value.hh
) )
SET(SOURCES SET(SOURCES
fuzzy.cc
system.cc system.cc
stringfunctions.cc stringfunctions.cc
value.cc value.cc
......
#include "radixcore/fuzzy.hh"
namespace radix
{
bool fuzzy_compare(double p1, double p2)
{
return (std::abs(p1 - p2) * 1000000000000. <=
std::min(std::abs(p1), std::abs(p2)));
}
bool fuzzy_compare(float p1, float p2)
{
return (std::abs(p1 - p2) * 100000.f <= std::min(std::abs(p1), std::abs(p2)));
}
} // namespace radix
#ifndef RADIX_RADIXCORE_FUZZY_HH_
#define RADIX_RADIXCORE_FUZZY_HH_
#include <algorithm>
#include <cmath>
#include "radixcore/visibility.hh"
namespace radix
{
RADIX_PUBLIC bool fuzzy_compare(double p1, double p2);
RADIX_PUBLIC bool fuzzy_compare(float p1, float p2);
} // namespace radix
#endif /** RADIX_RADIXCORE_FUZZY_HH_ */
#include "radixgeo/coordinate.hh" #include "radixgeo/coordinate.hh"
#include "radixcore/fuzzy.hh"
#include "radixmath/util.hh" #include "radixmath/util.hh"
namespace radix namespace radix
...@@ -27,6 +28,13 @@ double Coordinate::distanceTo(const Coordinate &point) const ...@@ -27,6 +28,13 @@ double Coordinate::distanceTo(const Coordinate &point) const
point.longitude(), EARTH_RADIUS_MEAN); point.longitude(), EARTH_RADIUS_MEAN);
} }
bool Coordinate::operator==(const Coordinate &orig) const
{
return (fuzzy_compare(m_latitude, orig.latitude()) &&
fuzzy_compare(m_longitude, orig.longitude()) &&
fuzzy_compare(m_altitude, orig.altitude()));
}
double Coordinate::longitude() const { return m_longitude; } double Coordinate::longitude() const { return m_longitude; }
void Coordinate::setLongitude(double newLongitude) void Coordinate::setLongitude(double newLongitude)
......
...@@ -21,6 +21,8 @@ class RADIX_PUBLIC Coordinate ...@@ -21,6 +21,8 @@ class RADIX_PUBLIC Coordinate
void setAltitude(double newAltitude); void setAltitude(double newAltitude);
double distanceTo(const Coordinate& point) const; double distanceTo(const Coordinate& point) const;
bool operator==(const Coordinate& orig) const;
}; };
} // namespace radix } // namespace radix
......
...@@ -16,4 +16,7 @@ TEST(Radixgeo, Coordinate) ...@@ -16,4 +16,7 @@ TEST(Radixgeo, Coordinate)
EXPECT_EQ(20, c1.latitude()); EXPECT_EQ(20, c1.latitude());
c1.setLongitude(34); c1.setLongitude(34);
EXPECT_EQ(34, c1.longitude()); EXPECT_EQ(34, c1.longitude());
EXPECT_FALSE(c1 == c2);
Coordinate c3 = c1;
EXPECT_TRUE(c1 == c3);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment