21#ifndef LSST_GEOM_ANGLE_H
22#define LSST_GEOM_ANGLE_H
29#include "boost/math/constants/constants.hpp"
37#pragma clang diagnostic push
38#pragma clang diagnostic ignored "-Wunused-variable"
40double constexpr PI = boost::math::constants::pi<double>();
41double constexpr TWOPI = boost::math::constants::pi<double>() * 2.0;
42double constexpr HALFPI = boost::math::constants::pi<double>() * 0.5;
43double constexpr ONE_OVER_PI = 1.0 / boost::math::constants::pi<double>();
45double const SQRTPI = sqrt(boost::math::constants::pi<double>());
46double const INVSQRTPI = 1.0 / sqrt(boost::math::constants::pi<double>());
47double constexpr ROOT2 = boost::math::constants::root_two<double>();
48#pragma clang diagnostic pop
52inline constexpr double degToRad(
double x)
noexcept {
return x *
PI / 180.; }
53inline constexpr double radToDeg(
double x)
noexcept {
return x * 180. /
PI; }
54inline constexpr double radToArcsec(
double x)
noexcept {
return x * 3600. * 180. /
PI; }
55inline constexpr double radToMas(
double x)
noexcept {
return x * 1000. * 3600. * 180. /
PI; }
56inline constexpr double arcsecToRad(
double x)
noexcept {
return (
x / 3600.) *
PI / 180.; }
57inline constexpr double masToRad(
double x)
noexcept {
return (
x / (1000. * 3600.)) *
PI / 180.; }
106 return (_val == rhs._val);
140 constexpr Angle() noexcept : _val(0) {}
160 constexpr operator double() const noexcept {
return _val; }
242#define ANGLE_OPUP_TYPE(OP, TYPE) \
243 Angle& operator OP(TYPE const& d) noexcept { \
264#undef ANGLE_OPUP_TYPE
266#define ANGLE_COMP(OP) \
267 constexpr bool operator OP(const Angle& rhs) const noexcept { return _val OP rhs._val; }
294#define ANGLE_OP(OP) \
295 inline constexpr Angle operator OP(Angle a, Angle d) noexcept { \
296 return Angle(static_cast<double>(a) OP static_cast<double>(d)); \
301#define ANGLE_OP_TYPE(OP, TYPE) \
302 inline constexpr Angle operator OP(Angle a, TYPE d) noexcept { \
303 return Angle(static_cast<double>(a) OP d); \
306 inline constexpr Angle operator OP(TYPE d, Angle a) noexcept { \
307 return Angle(d OP static_cast<double>(a)); \
404 "Only numeric types may be multiplied by an AngleUnit to create an Angle!");
405 return Angle(lhs * rhs._val);
413 if (wrapped < 0.0) wrapped +=
TWOPI;
415 if (wrapped >=
TWOPI) wrapped = 0.0;
428 }
else if (wrapped >=
PI) {
441 double const refAngRad = refAng.
asRadians();
442 double wrapped = (*
this - refAng).wrapCtr().asRadians() + refAngRad;
447 if (wrapped - refAngRad >=
PI) {
450 if (wrapped - refAngRad < -
PI) {
465 using result_type = size_t;
472 using result_type = size_t;
table::Key< double > angle
A class representing an angle.
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr Angle(Angle const &other) noexcept=default
Copy constructor.
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double asHours() const noexcept
Return an Angle's value in hours.
Angle separation(Angle const &other) const noexcept
The signed difference between two Angles.
constexpr Angle(double val, AngleUnit units=radians) noexcept
Construct an Angle with the specified value (interpreted in the given units).
std::size_t hash_value() const noexcept
Return a hash of this object.
constexpr Angle() noexcept
Construct the zero angle.
constexpr Angle operator/(Angle a, double d) noexcept
Ratio of an angle and a scalar.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
constexpr double asMilliarcseconds() const noexcept
Return an Angle's value in milliarcseconds.
constexpr double asArcseconds() const noexcept
Return an Angle's value in arcseconds.
constexpr Angle operator/(Angle a, int d) noexcept
Ratio of an angle and a scalar.
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
Angle & operator=(Angle const &other) noexcept=default
Copy assignment.
Angle & operator=(Angle &&other) noexcept=default
Move assignment.
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
constexpr Angle operator-(Angle angle)
An angle in the opposite sense.
constexpr Angle(Angle &&other) noexcept=default
Move constructor.
Angle(sphgeom::Angle const &sgAngle) noexcept
Convert from a sphgeom::Angle instance.
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
A class used to convert scalar POD types such as double to Angle.
constexpr AngleUnit(double val)
Define a new angle unit.
constexpr bool operator==(AngleUnit const &rhs) const noexcept
Test if two units are the same.
friend constexpr Angle operator*(T lhs, AngleUnit rhs) noexcept
Use AngleUnit to convert a POD (e.g. int, double) to an Angle; e.g. 180*degrees.
std::size_t hash_value() const noexcept
Return a hash of this object.
Angle represents an angle in radians.
static Angle fromRadians(double a)
#define ANGLE_OPUP_TYPE(OP, TYPE)
#define ANGLE_OP_TYPE(OP, TYPE)
constexpr Angle operator*(Angle a, Angle d) noexcept
Product of two angles.
constexpr double arcsecToRad(double x) noexcept
AngleUnit constexpr milliarcseconds
constant with units of milliarcseconds
constexpr double radToMas(double x) noexcept
double constexpr ONE_OVER_PI
constexpr Angle operator/(Angle a, int d) noexcept
Ratio of an angle and a scalar.
AngleUnit constexpr degrees
constant with units of degrees
AngleUnit constexpr arcseconds
constant with units of arcseconds
constexpr double radToDeg(double x) noexcept
constexpr double masToRad(double x) noexcept
constexpr double radToArcsec(double x) noexcept
AngleUnit constexpr arcminutes
constant with units of arcminutes
AngleUnit constexpr radians
constant with units of radians
constexpr double degToRad(double x) noexcept
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
double constexpr PI
The ratio of a circle's circumference to diameter.
constexpr bool isAngle(T) noexcept
Allow a user to check if they have an angle.
AngleUnit constexpr hours
constant with units of hours
This file declares a class for representing angles.