1 #if !defined(LSST_AFW_GEOM_ANGLE_H)
2 #define LSST_AFW_GEOM_ANGLE_H
10 #include "boost/math/constants/constants.hpp"
19 #pragma clang diagnostic push
20 #pragma clang diagnostic ignored "-Wunused-variable"
21 double constexpr
PI = boost::math::constants::pi<double>();
23 double constexpr
TWOPI = boost::math::constants::pi<double>() * 2.0;
24 double constexpr
HALFPI = boost::math::constants::pi<double>() * 0.5;
25 double constexpr
ONE_OVER_PI = 1.0 / boost::math::constants::pi<double>();
27 double const SQRTPI = sqrt(boost::math::constants::pi<double>());
28 double const INVSQRTPI = 1.0 / sqrt(boost::math::constants::pi<double>());
29 double constexpr
ROOT2 = boost::math::constants::root_two<double>();
30 #pragma clang diagnostic pop
34 inline constexpr
double degToRad(
double x) noexcept {
return x *
PI / 180.; }
35 inline constexpr
double radToDeg(
double x) noexcept {
return x * 180. /
PI; }
36 inline constexpr
double radToArcsec(
double x) noexcept {
return x * 3600. * 180. /
PI; }
37 inline constexpr
double radToMas(
double x) noexcept {
return x * 1000. * 3600. * 180. /
PI; }
38 inline constexpr
double arcsecToRad(
double x) noexcept {
return (
x / 3600.) *
PI / 180.; }
39 inline constexpr
double masToRad(
double x) noexcept {
return (
x / (1000. * 3600.)) *
PI / 180.; }
85 return (
_val == rhs._val);
118 constexpr
Angle(
Angle const& other) noexcept =
default;
121 constexpr
Angle(
Angle&& other) noexcept = default;
124 Angle& operator=(
Angle const& other) noexcept = default;
127 Angle& operator=(
Angle&& other) noexcept = default;
130 constexpr operator
double() const noexcept {
return _val; }
207 #define ANGLE_OPUP_TYPE(OP, TYPE) \
208 Angle& operator OP(TYPE const& d) noexcept { \
221 ANGLE_OPUP_TYPE(+=,
int)
224 ANGLE_OPUP_TYPE(-=,
double)
226 ANGLE_OPUP_TYPE(-=,
int)
229 #undef ANGLE_OPUP_TYPE
231 #define ANGLE_COMP(OP) \
232 constexpr bool operator OP(const Angle& rhs) const noexcept { return _val OP rhs._val; }
256 #define ANGLE_OP(OP) \
257 inline constexpr Angle operator OP(Angle a, Angle d) noexcept { \
258 return Angle(static_cast<double>(a) OP static_cast<double>(d)); \
263 #define ANGLE_OP_TYPE(OP, TYPE) \
264 inline constexpr Angle operator OP(Angle a, TYPE d) noexcept { \
265 return Angle(static_cast<double>(a) OP d); \
268 inline constexpr Angle operator OP(TYPE d, Angle a) noexcept { \
269 return Angle(d OP static_cast<double>(a)); \
328 template <
typename T>
329 constexpr
double operator/(T
const lhs,
Angle rhs) noexcept =
delete;
348 template <
typename T>
350 return std::is_base_of<Angle, T>::value;
363 template <
typename T>
365 static_assert(std::is_arithmetic<T>::value,
366 "Only numeric types may be multiplied by an AngleUnit to create an Angle!");
367 return Angle(lhs * rhs._val);
375 if (wrapped < 0.0) wrapped +=
TWOPI;
377 if (wrapped >=
TWOPI) wrapped = 0.0;
390 }
else if (wrapped >=
PI) {
403 double const refAngRad = refAng.
asRadians();
404 double wrapped = (*
this - refAng).wrapCtr().asRadians() + refAngRad;
407 if (wrapped - refAngRad >=
PI) {
411 if (wrapped - refAngRad < -
PI) {
412 wrapped -= wrapped * 2.0 * std::numeric_limits<double>::epsilon();
421 #endif // if !defined(LSST_AFW_GEOM_ANGLE_H)
constexpr bool isAngle(T) noexcept
Allow a user to check if they have an angle.
AngleUnit constexpr arcminutes
constant with units of arcminutes
lsst::afw::geom::Angle Angle
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng < π.
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
constexpr double masToRad(double x) noexcept
AngleUnit constexpr radians
constant with units of radians
AngleUnit constexpr degrees
constant with units of degrees
constexpr double asArcseconds() const noexcept
Return an Angle's value in arcseconds.
A class used to convert scalar POD types such as double to Angle.
double constexpr ONE_OVER_PI
double constexpr PI
The ratio of a circle's circumference to diameter.
constexpr Angle(double val, AngleUnit units=radians) noexcept
Construct an Angle with the specified value (interpreted in the given units).
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
A class representing an angle.
constexpr Angle operator/(Angle a, int d) noexcept
Ratio of an angle and a scalar.
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
constexpr AngleUnit(double val)
Define a new angle unit.
constexpr bool operator==(AngleUnit const &rhs) const noexcept
Test if two units are the same.
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
AngleUnit constexpr hours
constant with units of hours
constexpr double degToRad(double x) noexcept
constexpr Angle() noexcept
Construct the zero angle.
AngleUnit constexpr arcseconds
constant with units of arcseconds
constexpr double radToArcsec(double x) noexcept
constexpr Angle operator*(Angle a, Angle d) noexcept
Product of two angles.
constexpr Angle operator-(Angle a, Angle d) noexcept
Difference of two angles.
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double radToDeg(double x) noexcept
Angle separation(Angle const &other) const noexcept
The signed difference between two Angles.
constexpr double arcsecToRad(double x) noexcept
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
constexpr double radToMas(double x) noexcept
#define ANGLE_OPUP_TYPE(OP, TYPE)
#define ANGLE_OP_TYPE(OP, TYPE)
constexpr double asHours() const noexcept
Return an Angle's value in hours.
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.