3
\$\begingroup\$

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;
  }

};
\$\endgroup\$
  • 1
    \$\begingroup\$ Where does assert() come from? Did you miss #include <cassert>? If so, that's not a good form of run-time error handling. \$\endgroup\$ – Toby Speight Jan 25 '18 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.