Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
1e1c7a7c
Commit
1e1c7a7c
authored
Jun 29, 2021
by
LEFEBVREJP email
Browse files
Fuzzy Compare
parent
b9ee21c9
Changes
6
Show whitespace changes
Inline
Side-by-side
radixcore/CMakeLists.txt
View file @
1e1c7a7c
...
...
@@ -3,6 +3,7 @@ TRIBITS_SUBPACKAGE(core)
TRIBITS_CONFIGURE_FILE
(
visibility.hh
)
SET
(
HEADERS
fuzzy.hh
json.hh
system.hh
stringfunctions.i.hh
...
...
@@ -10,6 +11,7 @@ stringfunctions.hh
value.hh
)
SET
(
SOURCES
fuzzy.cc
system.cc
stringfunctions.cc
value.cc
...
...
radixcore/fuzzy.cc
0 → 100644
View file @
1e1c7a7c
#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
radixcore/fuzzy.hh
0 → 100644
View file @
1e1c7a7c
#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_ */
radixgeo/coordinate.cc
View file @
1e1c7a7c
#include "radixgeo/coordinate.hh"
#include "radixcore/fuzzy.hh"
#include "radixmath/util.hh"
namespace
radix
...
...
@@ -27,6 +28,13 @@ double Coordinate::distanceTo(const Coordinate &point) const
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
;
}
void
Coordinate
::
setLongitude
(
double
newLongitude
)
...
...
radixgeo/coordinate.hh
View file @
1e1c7a7c
...
...
@@ -21,6 +21,8 @@ class RADIX_PUBLIC Coordinate
void
setAltitude
(
double
newAltitude
);
double
distanceTo
(
const
Coordinate
&
point
)
const
;
bool
operator
==
(
const
Coordinate
&
orig
)
const
;
};
}
// namespace radix
...
...
radixgeo/tests/tstCoordinate.cc
View file @
1e1c7a7c
...
...
@@ -16,4 +16,7 @@ TEST(Radixgeo, Coordinate)
EXPECT_EQ
(
20
,
c1
.
latitude
());
c1
.
setLongitude
(
34
);
EXPECT_EQ
(
34
,
c1
.
longitude
());
EXPECT_FALSE
(
c1
==
c2
);
Coordinate
c3
=
c1
;
EXPECT_TRUE
(
c1
==
c3
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment