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.; }
67 explicit constexpr
AngleUnit(
double val) : _val(val) {}
84 return (_val == rhs._val);
111 explicit constexpr
Angle(
double val,
AngleUnit units = radians) noexcept : _val(val* units._val) {}
114 constexpr
Angle() noexcept : _val(0) {}
117 constexpr
Angle(
Angle const& other) noexcept =
default;
120 constexpr
Angle(
Angle&& other) noexcept =
default;
123 Angle& operator=(
Angle const& other) noexcept =
default;
126 Angle& operator=(
Angle&& other) noexcept =
default;
129 constexpr
operator double() const noexcept {
return _val; }
139 constexpr
double asRadians() const noexcept {
return asAngularUnits(radians); }
142 constexpr
double asDegrees() const noexcept {
return asAngularUnits(degrees); }
145 constexpr
double asHours() const noexcept {
return asAngularUnits(hours); }
148 constexpr
double asArcminutes() const noexcept {
return asAngularUnits(arcminutes); }
151 constexpr
double asArcseconds() const noexcept {
return asAngularUnits(arcseconds); }
165 Angle wrap()
const noexcept;
179 Angle wrapCtr()
const noexcept;
193 Angle wrapNear(
Angle const& refAng)
const noexcept;
203 Angle separation(
Angle const& other)
const noexcept;
205 #define ANGLE_OPUP_TYPE(OP, TYPE) \ 206 Angle& operator OP(TYPE const& d) noexcept { \ 219 ANGLE_OPUP_TYPE(+=,
int)
222 ANGLE_OPUP_TYPE(-=,
double)
224 ANGLE_OPUP_TYPE(-=,
int)
227 #undef ANGLE_OPUP_TYPE 229 #define ANGLE_COMP(OP) \ 230 constexpr bool operator OP(const Angle& rhs) const noexcept { return _val OP rhs._val; } 254 #define ANGLE_OP(OP) \ 255 inline constexpr Angle operator OP(Angle a, Angle d) noexcept { \ 256 return Angle(static_cast<double>(a) OP static_cast<double>(d)); \ 261 #define ANGLE_OP_TYPE(OP, TYPE) \ 262 inline constexpr Angle operator OP(Angle a, TYPE d) noexcept { \ 263 return Angle(static_cast<double>(a) OP d); \ 266 inline constexpr Angle operator OP(TYPE d, Angle a) noexcept { \ 267 return Angle(d OP static_cast<double>(a)); \ 326 template <
typename T>
327 constexpr
double operator/(T
const lhs,
Angle rhs) noexcept =
delete;
346 template <
typename T>
348 return std::is_base_of<Angle, T>::value;
361 template <
typename T>
363 static_assert(std::is_arithmetic<T>::value,
364 "Only numeric types may be multiplied by an AngleUnit to create an Angle!");
365 return Angle(lhs * rhs._val);
371 double wrapped = std::fmod(_val, TWOPI);
373 if (wrapped < 0.0) wrapped +=
TWOPI;
375 if (wrapped >= TWOPI) wrapped = 0.0;
380 double wrapped = std::fmod(_val, TWOPI);
388 }
else if (wrapped >= PI) {
401 double const refAngRad = refAng.
asRadians();
402 double wrapped = (*
this - refAng).wrapCtr().asRadians() + refAngRad;
407 if (wrapped - refAngRad >= PI) {
410 if (wrapped - refAngRad < -PI) {
420 #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
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
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.
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
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.