Define a class for latitude and longitude in C++ using boost::units and spheroidal coordinates
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
I am trying to write a class that defines latitude and longitude in C++ using boost::units
and normalized spheroidal coordinates. I want to throw an exception if the class is constructed outside the bounds of the normalized spheroidal coordinates. Incidentally I thought about using boost::geometry
but when I read this forum discussion it looked like converting between using boost::units
and boost::geometry
was not straightforward, so I am just making the below and am wondering if this is a good path to go down.
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/base_units/angle/radian.hpp>
#include <boost/units/base_units/angle/degree.hpp>
#include <boost/math/constants/constants.hpp>
namespace units = boost::units;
namespace si = units::si;
namespace constants = boost::math::constants;
class Latitude
private:
units::quantity<si::plane_angle> angle;
public:
Latitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::half_pi<double>() * si::radians));
assert (angle >= (-constants::half_pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
class Longitude
private:
units::quantity<si::plane_angle> angle;
public:
Longitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::pi<double>() * si::radians));
assert (angle >= (-constants::pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
c++ validation coordinate-system boost
add a comment |Â
up vote
3
down vote
favorite
I am trying to write a class that defines latitude and longitude in C++ using boost::units
and normalized spheroidal coordinates. I want to throw an exception if the class is constructed outside the bounds of the normalized spheroidal coordinates. Incidentally I thought about using boost::geometry
but when I read this forum discussion it looked like converting between using boost::units
and boost::geometry
was not straightforward, so I am just making the below and am wondering if this is a good path to go down.
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/base_units/angle/radian.hpp>
#include <boost/units/base_units/angle/degree.hpp>
#include <boost/math/constants/constants.hpp>
namespace units = boost::units;
namespace si = units::si;
namespace constants = boost::math::constants;
class Latitude
private:
units::quantity<si::plane_angle> angle;
public:
Latitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::half_pi<double>() * si::radians));
assert (angle >= (-constants::half_pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
class Longitude
private:
units::quantity<si::plane_angle> angle;
public:
Longitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::pi<double>() * si::radians));
assert (angle >= (-constants::pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
c++ validation coordinate-system boost
1
Where doesassert()
come from? Did you miss#include <cassert>
? If so, that's not a good form of run-time error handling.
â Toby Speight
Jan 25 at 10:04
@TobySpeight great point, thanks.
â nimble_ninja
Jan 25 at 13:21
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am trying to write a class that defines latitude and longitude in C++ using boost::units
and normalized spheroidal coordinates. I want to throw an exception if the class is constructed outside the bounds of the normalized spheroidal coordinates. Incidentally I thought about using boost::geometry
but when I read this forum discussion it looked like converting between using boost::units
and boost::geometry
was not straightforward, so I am just making the below and am wondering if this is a good path to go down.
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/base_units/angle/radian.hpp>
#include <boost/units/base_units/angle/degree.hpp>
#include <boost/math/constants/constants.hpp>
namespace units = boost::units;
namespace si = units::si;
namespace constants = boost::math::constants;
class Latitude
private:
units::quantity<si::plane_angle> angle;
public:
Latitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::half_pi<double>() * si::radians));
assert (angle >= (-constants::half_pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
class Longitude
private:
units::quantity<si::plane_angle> angle;
public:
Longitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::pi<double>() * si::radians));
assert (angle >= (-constants::pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
c++ validation coordinate-system boost
I am trying to write a class that defines latitude and longitude in C++ using boost::units
and normalized spheroidal coordinates. I want to throw an exception if the class is constructed outside the bounds of the normalized spheroidal coordinates. Incidentally I thought about using boost::geometry
but when I read this forum discussion it looked like converting between using boost::units
and boost::geometry
was not straightforward, so I am just making the below and am wondering if this is a good path to go down.
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/base_units/angle/radian.hpp>
#include <boost/units/base_units/angle/degree.hpp>
#include <boost/math/constants/constants.hpp>
namespace units = boost::units;
namespace si = units::si;
namespace constants = boost::math::constants;
class Latitude
private:
units::quantity<si::plane_angle> angle;
public:
Latitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::half_pi<double>() * si::radians));
assert (angle >= (-constants::half_pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
class Longitude
private:
units::quantity<si::plane_angle> angle;
public:
Longitude(units::quantity<si::plane_angle> angle) : angle(angle)
assert (angle <= ( constants::pi<double>() * si::radians));
assert (angle >= (-constants::pi<double>() * si::radians));
const units::quantity<si::plane_angle> value()
return angle;
;
c++ validation coordinate-system boost
edited Jan 24 at 22:10
200_success
123k14143401
123k14143401
asked Jan 24 at 21:21
nimble_ninja
161
161
1
Where doesassert()
come from? Did you miss#include <cassert>
? If so, that's not a good form of run-time error handling.
â Toby Speight
Jan 25 at 10:04
@TobySpeight great point, thanks.
â nimble_ninja
Jan 25 at 13:21
add a comment |Â
1
Where doesassert()
come from? Did you miss#include <cassert>
? If so, that's not a good form of run-time error handling.
â Toby Speight
Jan 25 at 10:04
@TobySpeight great point, thanks.
â nimble_ninja
Jan 25 at 13:21
1
1
Where does
assert()
come from? Did you miss #include <cassert>
? If so, that's not a good form of run-time error handling.â Toby Speight
Jan 25 at 10:04
Where does
assert()
come from? Did you miss #include <cassert>
? If so, that's not a good form of run-time error handling.â Toby Speight
Jan 25 at 10:04
@TobySpeight great point, thanks.
â nimble_ninja
Jan 25 at 13:21
@TobySpeight great point, thanks.
â nimble_ninja
Jan 25 at 13:21
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f185906%2fdefine-a-class-for-latitude-and-longitude-in-c-using-boostunits-and-spheroid%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Where does
assert()
come from? Did you miss#include <cassert>
? If so, that's not a good form of run-time error handling.â Toby Speight
Jan 25 at 10:04
@TobySpeight great point, thanks.
â nimble_ninja
Jan 25 at 13:21