21 #ifndef LSST_GEOM_ANGLE_H 22 #define LSST_GEOM_ANGLE_H 26 #include <type_traits> 28 #include "boost/math/constants/constants.hpp" 36 #pragma clang diagnostic push 37 #pragma clang diagnostic ignored "-Wunused-variable" 38 double constexpr
PI = boost::math::constants::pi<double>();
40 double constexpr
TWOPI = boost::math::constants::pi<double>() * 2.0;
41 double constexpr
HALFPI = boost::math::constants::pi<double>() * 0.5;
42 double constexpr
ONE_OVER_PI = 1.0 / boost::math::constants::pi<double>();
44 double const SQRTPI = sqrt(boost::math::constants::pi<double>());
45 double const INVSQRTPI = 1.0 / sqrt(boost::math::constants::pi<double>());
46 double constexpr
ROOT2 = boost::math::constants::root_two<double>();
47 #pragma clang diagnostic pop 51 inline constexpr
double degToRad(
double x) noexcept {
return x * PI / 180.; }
52 inline constexpr
double radToDeg(
double x) noexcept {
return x * 180. /
PI; }
53 inline constexpr
double radToArcsec(
double x) noexcept {
return x * 3600. * 180. /
PI; }
54 inline constexpr
double radToMas(
double x) noexcept {
return x * 1000. * 3600. * 180. /
PI; }
55 inline constexpr
double arcsecToRad(
double x) noexcept {
return (
x / 3600.) * PI / 180.; }
56 inline constexpr
double masToRad(
double x) noexcept {
return (
x / (1000. * 3600.)) * PI / 180.; }
102 return (_val == rhs._val);
136 constexpr
Angle() noexcept : _val(0) {}
142 constexpr
Angle(
Angle&& other) noexcept =
default;
145 Angle& operator=(
Angle const& other) noexcept =
default;
148 Angle& operator=(
Angle&& other) noexcept =
default;
153 constexpr
operator double() const noexcept {
return _val; }
163 constexpr
double asRadians() const noexcept {
return asAngularUnits(radians); }
166 constexpr
double asDegrees() const noexcept {
return asAngularUnits(degrees); }
169 constexpr
double asHours() const noexcept {
return asAngularUnits(hours); }
172 constexpr
double asArcminutes() const noexcept {
return asAngularUnits(arcminutes); }
175 constexpr
double asArcseconds() const noexcept {
return asAngularUnits(arcseconds); }
206 Angle wrapCtr()
const noexcept;
220 Angle wrapNear(
Angle const& refAng)
const noexcept;
230 Angle separation(
Angle const& other)
const noexcept;
232 #define ANGLE_OPUP_TYPE(OP, TYPE) \ 233 Angle& operator OP(TYPE const& d) noexcept { \ 246 ANGLE_OPUP_TYPE(+=,
int)
249 ANGLE_OPUP_TYPE(-=,
double)
251 ANGLE_OPUP_TYPE(-=,
int)
254 #undef ANGLE_OPUP_TYPE 256 #define ANGLE_COMP(OP) \ 257 constexpr bool operator OP(const Angle& rhs) const noexcept { return _val OP rhs._val; } 281 #define ANGLE_OP(OP) \ 282 inline constexpr Angle operator OP(Angle a, Angle d) noexcept { \ 283 return Angle(static_cast<double>(a) OP static_cast<double>(d)); \ 288 #define ANGLE_OP_TYPE(OP, TYPE) \ 289 inline constexpr Angle operator OP(Angle a, TYPE d) noexcept { \ 290 return Angle(static_cast<double>(a) OP d); \ 293 inline constexpr Angle operator OP(TYPE d, Angle a) noexcept { \ 294 return Angle(d OP static_cast<double>(a)); \ 353 template <
typename T>
354 constexpr
double operator/(T
const lhs,
Angle rhs) noexcept =
delete;
373 template <
typename T>
388 template <
typename T>
391 "Only numeric types may be multiplied by an AngleUnit to create an Angle!");
392 return Angle(lhs * rhs._val);
400 if (wrapped < 0.0) wrapped +=
TWOPI;
402 if (wrapped >= TWOPI) wrapped = 0.0;
415 }
else if (wrapped >= PI) {
428 double const refAngRad = refAng.
asRadians();
429 double wrapped = (*
this - refAng).wrapCtr().asRadians() + refAngRad;
434 if (wrapped - refAngRad >= PI) {
437 if (wrapped - refAngRad < -PI) {
448 #endif // if !defined(LSST_GEOM_ANGLE_H) constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
AngleUnit constexpr arcminutes
constant with units of arcminutes
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
AngleUnit constexpr hours
constant with units of hours
constexpr double radToDeg(double x) noexcept
#define ANGLE_OP_TYPE(OP, TYPE)
Angle separation(Angle const &other) const noexcept
The signed difference between two Angles.
AngleUnit constexpr radians
constant with units of radians
A class representing an angle.
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr double radToArcsec(double x) noexcept
double constexpr ONE_OVER_PI
constexpr Angle operator-(Angle a, Angle d) noexcept
Difference of two angles.
AngleUnit constexpr degrees
constant with units of degrees
A base class for image defects.
constexpr double asHours() const noexcept
Return an Angle's value in hours.
AngleUnit constexpr arcseconds
constant with units of arcseconds
constexpr Angle() noexcept
Construct the zero angle.
constexpr double degToRad(double x) noexcept
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
constexpr double asArcseconds() const noexcept
Return an Angle's value in arcseconds.
constexpr Angle(double val, AngleUnit units=radians) noexcept
Construct an Angle with the specified value (interpreted in the given units).
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
constexpr double asMilliarcseconds() const noexcept
Return an Angle's value in milliarcseconds.
constexpr Angle operator/(Angle a, int d) noexcept
Ratio of an angle and a scalar.
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.
constexpr double radToMas(double x) noexcept
ItemVariant const * other
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
constexpr AngleUnit(double val)
Define a new angle unit.
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
AngleUnit constexpr milliarcseconds
constant with units of milliarcseconds
constexpr bool isAngle(T) noexcept
Allow a user to check if they have an angle.
constexpr double masToRad(double x) noexcept
constexpr double arcsecToRad(double x) noexcept
double constexpr PI
The ratio of a circle's circumference to diameter.
A class used to convert scalar POD types such as double to Angle.
#define ANGLE_OPUP_TYPE(OP, TYPE)