1 #if !defined(LSST_AFW_GEOM_ANGLE_H) 2 #define LSST_AFW_GEOM_ANGLE_H 9 #include "boost/math/constants/constants.hpp" 18 #pragma clang diagnostic push 19 #pragma clang diagnostic ignored "-Wunused-variable" 20 double constexpr
PI = boost::math::constants::pi<double>();
22 double constexpr
TWOPI = boost::math::constants::pi<double>() * 2.0;
23 double constexpr
HALFPI = boost::math::constants::pi<double>() * 0.5;
24 double constexpr
ONE_OVER_PI = 1.0 / boost::math::constants::pi<double>();
26 double const SQRTPI = sqrt(boost::math::constants::pi<double>());
27 double const INVSQRTPI = 1.0 / sqrt(boost::math::constants::pi<double>());
28 double constexpr
ROOT2 = boost::math::constants::root_two<double>();
29 #pragma clang diagnostic pop 33 inline constexpr
double degToRad(
double x) noexcept {
return x * PI / 180.; }
34 inline constexpr
double radToDeg(
double x) noexcept {
return x * 180. /
PI; }
35 inline constexpr
double radToArcsec(
double x) noexcept {
return x * 3600. * 180. /
PI; }
36 inline constexpr
double radToMas(
double x) noexcept {
return x * 1000. * 3600. * 180. /
PI; }
37 inline constexpr
double arcsecToRad(
double x) noexcept {
return (
x / 3600.) * PI / 180.; }
38 inline constexpr
double masToRad(
double x) noexcept {
return (
x / (1000. * 3600.)) * PI / 180.; }
84 return (_val == rhs._val);
114 constexpr
Angle() noexcept : _val(0) {}
120 constexpr
Angle(
Angle&& other) noexcept =
default;
123 Angle& operator=(
Angle const& other) noexcept =
default;
126 Angle& operator=(
Angle&& other) noexcept =
default;
131 constexpr
operator double() const noexcept {
return _val; }
141 constexpr
double asRadians() const noexcept {
return asAngularUnits(radians); }
144 constexpr
double asDegrees() const noexcept {
return asAngularUnits(degrees); }
147 constexpr
double asHours() const noexcept {
return asAngularUnits(hours); }
150 constexpr
double asArcminutes() const noexcept {
return asAngularUnits(arcminutes); }
153 constexpr
double asArcseconds() const noexcept {
return asAngularUnits(arcseconds); }
181 Angle wrapCtr()
const noexcept;
195 Angle wrapNear(
Angle const& refAng)
const noexcept;
205 Angle separation(
Angle const& other)
const noexcept;
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>
363 template <
typename T>
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;
409 if (wrapped - refAngRad >= PI) {
412 if (wrapped - refAngRad < -PI) {
422 #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
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
constexpr double masToRad(double x) noexcept
AngleUnit constexpr radians
constant with units of radians
AngleUnit constexpr degrees
constant with units of degrees
table::Key< double > angle
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.
A base class for image defects.
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
Difference of two angles.
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double radToDeg(double x) noexcept
ItemVariant const * other
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.