Define a class for latitude and longitude in C++ using boost::units and spheroidal coordinates

The name of the pictureThe name of the pictureThe name of the pictureClash 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;


;






share|improve this question

















  • 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
















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;


;






share|improve this question

















  • 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












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;


;






share|improve this question













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;


;








share|improve this question












share|improve this question




share|improve this question








edited Jan 24 at 22:10









200_success

123k14143401




123k14143401









asked Jan 24 at 21:21









nimble_ninja

161




161







  • 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












  • 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







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















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?