Skip to content
Snippets Groups Projects
Commit bf59eae2 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Formally defined radixgeo::Coordinate type.

parent 7911242f
Branches ewm6854-ConfigService-remove
No related tags found
1 merge request!109RadixGeo::Coordinate
Pipeline #152430 passed with warnings with stages
in 18 minutes and 24 seconds
......@@ -2,10 +2,12 @@ TRIBITS_SUBPACKAGE(geo)
SET(SOURCE
coordinate.cc
coordinateconversion.cc
)
SET(HEADERS
coordinate.hh
coordinateconversion.hh
)
......
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_PACKAGES radixcore radixbug
LIB_REQUIRED_PACKAGES radixmath radixcore radixbug
LIB_OPTIONAL_PACKAGES
TEST_REQUIRED_PACKAGES testframework
TEST_OPTIONAL_PACKAGES
......
#include "radixgeo/coordinate.hh"
#include "radixmath/util.hh"
namespace radix
{
Coordinate::Coordinate()
: m_latitude(0.)
, m_longitude(0.)
, m_altitude(0.)
{
}
Coordinate::Coordinate(double latitude, double longitude, double altitude)
: m_latitude(latitude)
, m_longitude(longitude)
, m_altitude(altitude)
{
}
double Coordinate::altitude() const { return m_altitude; }
void Coordinate::setAltitude(double newAltitude) { m_altitude = newAltitude; }
double Coordinate::distanceTo(const Coordinate &point) const
{
return greatCircleDistance(m_latitude, m_longitude, point.latitude(),
point.longitude(), EARTH_RADIUS_MEAN);
}
double Coordinate::longitude() const { return m_longitude; }
void Coordinate::setLongitude(double newLongitude)
{
m_longitude = newLongitude;
}
double Coordinate::latitude() const { return m_latitude; }
void Coordinate::setLatitude(double newLatitude) { m_latitude = newLatitude; }
} // namespace radix
#ifndef RADIX_RADIXGEO_COORDINATE_HH_
#define RADIX_RADIXGEO_COORDINATE_HH_
#include "radixcore/visibility.hh"
namespace radix
{
class RADIX_PUBLIC Coordinate
{
double m_latitude = 0.0;
double m_longitude = 0.0;
double m_altitude = 0.0;
public:
Coordinate();
Coordinate(double latitude, double longitude, double altitude);
double latitude() const;
void setLatitude(double newLatitude);
double longitude() const;
void setLongitude(double newLongitude);
double altitude() const;
void setAltitude(double newAltitude);
double distanceTo(const Coordinate& point) const;
};
} // namespace radix
#endif /** RADIX_RADIXGEO_COORDINATE_HH_ */
INCLUDE(GoogleTest)
ADD_GOOGLE_TEST(tstCoordinateConversion.cc NP 1)
ADD_GOOGLE_TEST(tstCoordinate.cc NP 1)
#include "gtest/gtest.h"
#include "radixgeo/coordinate.hh"
using namespace radix;
TEST(Radixgeo, Coordinate)
{
Coordinate c1(0, -90, 0);
Coordinate c2(0, -91, 0);
EXPECT_DOUBLE_EQ(111198.41730306273, c1.distanceTo(c2));
// Much of this is captured in radixmath::greatCircleDistance
c1.setAltitude(1);
EXPECT_EQ(1, c1.altitude());
c1.setLatitude(20);
EXPECT_EQ(20, c1.latitude());
c1.setLongitude(34);
EXPECT_EQ(34, c1.longitude());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment