LSSTApplications  12.1-5-gbdcc3ab+2,15.0+13,15.0+26,15.0-1-g19261fa+17,15.0-1-g60afb23+26,15.0-1-g615e0bb+18,15.0-1-g788a293+26,15.0-1-ga91101e+26,15.0-1-gae1598d+12,15.0-1-gd076f1f+24,15.0-1-gdf18595+5,15.0-1-gf4f1c34+12,15.0-11-g7db6e543+4,15.0-12-g3681e7a+4,15.0-15-gc15de322,15.0-16-g83b84f4,15.0-2-g100d730+19,15.0-2-g1f9c9cf+4,15.0-2-g8aea5f4+1,15.0-2-gf38729e+21,15.0-29-ga12a2b06e,15.0-3-g11fe1a0+14,15.0-3-g707930d+3,15.0-3-g9103c06+12,15.0-3-gd3cbb57+3,15.0-4-g2d82b59,15.0-4-g535e784+10,15.0-4-g92ca6c3+4,15.0-4-gf906033+2,15.0-5-g23e394c+14,15.0-5-g4be42a9,15.0-6-g69628aa,15.0-6-g86e3f3d+1,15.0-6-gfa9b38f+4,15.0-7-g949993c+3,15.0-8-g67a62d3+1,15.0-8-gcf05001+1,15.0-9-g1e7c341+1,w.2018.21
LSSTDataManagementBasePackage
Public Member Functions | Friends | Related Functions | List of all members
lsst::afw::geom::Angle Class Referencefinal

A class representing an angle. More...

#include <Angle.h>

Public Member Functions

constexpr Angle (double val, AngleUnit units=radians) noexcept
 Construct an Angle with the specified value (interpreted in the given units). More...
 
constexpr Angle () noexcept
 Construct the zero angle. More...
 
constexpr Angle (Angle const &other) noexcept=default
 Copy constructor. More...
 
constexpr Angle (Angle &&other) noexcept=default
 Move constructor. More...
 
Angleoperator= (Angle const &other) noexcept=default
 Copy assignment. More...
 
Angleoperator= (Angle &&other) noexcept=default
 Move assignment. More...
 
 ~Angle ()=default
 
constexpr operator double () const noexcept
 Convert an Angle to a double in radians. More...
 
constexpr double asAngularUnits (AngleUnit const &units) const noexcept
 Return an Angle's value in the specified units. More...
 
constexpr double asRadians () const noexcept
 Return an Angle's value in radians. More...
 
constexpr double asDegrees () const noexcept
 Return an Angle's value in degrees. More...
 
constexpr double asHours () const noexcept
 Return an Angle's value in hours. More...
 
constexpr double asArcminutes () const noexcept
 Return an Angle's value in arcminutes. More...
 
constexpr double asArcseconds () const noexcept
 Return an Angle's value in arcseconds. More...
 
Angle wrap () const noexcept
 Wrap this angle to the range [0, 2π). More...
 
Angle wrapCtr () const noexcept
 Wrap this angle to the range [-π, π). More...
 
Angle wrapNear (Angle const &refAng) const noexcept
 Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately. More...
 
Angle separation (Angle const &other) const noexcept
 The signed difference between two Angles. More...
 
Angleoperator*= (double const &d) noexcept
 Multiply this angle by the given factor. More...
 
Angleoperator*= (int const &d) noexcept
 Multiply this angle by the given factor. More...
 
Angleoperator+= (double const &d) noexcept
 Increase this angle by the given number of radians. More...
 
Angleoperator+= (int const &d) noexcept
 Increase this angle by the given number of radians. More...
 
Angleoperator-= (double const &d) noexcept
 Decrease this angle by the given number of radians. More...
 
Angleoperator-= (int const &d) noexcept
 Decrease this angle by the given number of radians. More...
 
constexpr bool operator== (const Angle &rhs) const noexcept
 Test if two Angles represent the same angle (without wrapping). More...
 
constexpr bool operator!= (const Angle &rhs) const noexcept
 Test if two Angles represent the same angle (without wrapping). More...
 
constexpr bool operator<= (const Angle &rhs) const noexcept
 Compare the sizes of two Angles (without wrapping). More...
 
constexpr bool operator>= (const Angle &rhs) const noexcept
 Compare the sizes of two Angles (without wrapping). More...
 
constexpr bool operator< (const Angle &rhs) const noexcept
 Compare the sizes of two Angles (without wrapping). More...
 
constexpr bool operator> (const Angle &rhs) const noexcept
 Compare the sizes of two Angles (without wrapping). More...
 

Friends

class AngleUnit
 

Related Functions

(Note that these are not member functions.)

constexpr Angle operator+ (Angle a, Angle d) noexcept
 Sum of two angles. More...
 
constexpr Angle operator- (Angle a, Angle d) noexcept
 Difference of two angles. More...
 
constexpr Angle operator* (Angle a, Angle d) noexcept
 Product of two angles. More...
 
constexpr Angle operator- (Angle angle)
 An angle in the opposite sense. More...
 
constexpr Angle operator/ (Angle a, int d) noexcept
 Ratio of an angle and a scalar. More...
 
constexpr Angle operator/ (Angle a, double d) noexcept
 Ratio of an angle and a scalar. More...
 
std::ostreamoperator<< (std::ostream &s, Angle a)
 Print an Angle to a stream. More...
 
template<typename T >
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. More...
 
constexpr Angle operator* (Angle a, double d) noexcept
 Product of an angle and a scalar. More...
 

Detailed Description

A class representing an angle.

Angles may be manipulated like doubles, and automatically converted to doubles, but they may not be constructed from doubles without calling a constructor or multiplying by an AngleUnit. Angles can be modified only by assignment; all other operations that transform an Angle return a new Angle instead.

Unless otherwise specified, all methods and associated operators shall not throw exceptions.

Definition at line 102 of file Angle.h.

Constructor & Destructor Documentation

◆ Angle() [1/4]

constexpr lsst::afw::geom::Angle::Angle ( double  val,
AngleUnit  units = radians 
)
inlineexplicitnoexcept

Construct an Angle with the specified value (interpreted in the given units).

Parameters
valthe size of the angle
unitsthe units in which val is measured

Definition at line 111 of file Angle.h.

111 : _val(val* units._val) {}
ImageT val
Definition: CR.cc:158

◆ Angle() [2/4]

constexpr lsst::afw::geom::Angle::Angle ( )
inlinenoexcept

Construct the zero angle.

Definition at line 114 of file Angle.h.

114 : _val(0) {}

◆ Angle() [3/4]

constexpr lsst::afw::geom::Angle::Angle ( Angle const &  other)
defaultnoexcept

Copy constructor.

◆ Angle() [4/4]

constexpr lsst::afw::geom::Angle::Angle ( Angle &&  other)
defaultnoexcept

Move constructor.

◆ ~Angle()

lsst::afw::geom::Angle::~Angle ( )
default

Member Function Documentation

◆ asAngularUnits()

constexpr double lsst::afw::geom::Angle::asAngularUnits ( AngleUnit const &  units) const
inlinenoexcept

Return an Angle's value in the specified units.

Parameters
unitsthe units in which the angle's value is desired (e.g. degrees).

Definition at line 138 of file Angle.h.

138 { return _val / units._val; }

◆ asArcminutes()

constexpr double lsst::afw::geom::Angle::asArcminutes ( ) const
inlinenoexcept

Return an Angle's value in arcminutes.

Definition at line 150 of file Angle.h.

150 { return asAngularUnits(arcminutes); }
AngleUnit constexpr arcminutes
constant with units of arcminutes
Definition: Angle.h:90
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle&#39;s value in the specified units.
Definition: Angle.h:138

◆ asArcseconds()

constexpr double lsst::afw::geom::Angle::asArcseconds ( ) const
inlinenoexcept

Return an Angle's value in arcseconds.

Definition at line 153 of file Angle.h.

153 { return asAngularUnits(arcseconds); }
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle&#39;s value in the specified units.
Definition: Angle.h:138
AngleUnit constexpr arcseconds
constant with units of arcseconds
Definition: Angle.h:91

◆ asDegrees()

constexpr double lsst::afw::geom::Angle::asDegrees ( ) const
inlinenoexcept

Return an Angle's value in degrees.

Definition at line 144 of file Angle.h.

144 { return asAngularUnits(degrees); }
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:88
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle&#39;s value in the specified units.
Definition: Angle.h:138

◆ asHours()

constexpr double lsst::afw::geom::Angle::asHours ( ) const
inlinenoexcept

Return an Angle's value in hours.

Definition at line 147 of file Angle.h.

147 { return asAngularUnits(hours); }
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle&#39;s value in the specified units.
Definition: Angle.h:138
AngleUnit constexpr hours
constant with units of hours
Definition: Angle.h:89

◆ asRadians()

constexpr double lsst::afw::geom::Angle::asRadians ( ) const
inlinenoexcept

Return an Angle's value in radians.

Definition at line 141 of file Angle.h.

141 { return asAngularUnits(radians); }
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle&#39;s value in the specified units.
Definition: Angle.h:138

◆ operator double()

constexpr lsst::afw::geom::Angle::operator double ( ) const
inlinenoexcept

Convert an Angle to a double in radians.

Definition at line 131 of file Angle.h.

131 { return _val; }

◆ operator!=()

constexpr bool lsst::afw::geom::Angle::operator!= ( const Angle rhs) const
inlinenoexcept

Test if two Angles represent the same angle (without wrapping).

Definition at line 237 of file Angle.h.

249 :
250  double _val;

◆ operator*=() [1/2]

Angle& lsst::afw::geom::Angle::operator*= ( double const &  d)
inlinenoexcept

Multiply this angle by the given factor.

Definition at line 215 of file Angle.h.

232 { return _val OP rhs._val; }

◆ operator*=() [2/2]

Angle& lsst::afw::geom::Angle::operator*= ( int const &  d)
inlinenoexcept

Multiply this angle by the given factor.

Definition at line 216 of file Angle.h.

232 { return _val OP rhs._val; }

◆ operator+=() [1/2]

Angle& lsst::afw::geom::Angle::operator+= ( double const &  d)
inlinenoexcept

Increase this angle by the given number of radians.

Definition at line 220 of file Angle.h.

232 { return _val OP rhs._val; }

◆ operator+=() [2/2]

Angle& lsst::afw::geom::Angle::operator+= ( int const &  d)
inlinenoexcept

Increase this angle by the given number of radians.

Definition at line 221 of file Angle.h.

232 { return _val OP rhs._val; }

◆ operator-=() [1/2]

Angle& lsst::afw::geom::Angle::operator-= ( double const &  d)
inlinenoexcept

Decrease this angle by the given number of radians.

Definition at line 225 of file Angle.h.

232 { return _val OP rhs._val; }

◆ operator-=() [2/2]

Angle& lsst::afw::geom::Angle::operator-= ( int const &  d)
inlinenoexcept

Decrease this angle by the given number of radians.

Definition at line 226 of file Angle.h.

232 { return _val OP rhs._val; }

◆ operator<()

constexpr bool lsst::afw::geom::Angle::operator< ( const Angle rhs) const
inlinenoexcept

Compare the sizes of two Angles (without wrapping).

Definition at line 243 of file Angle.h.

249 :
250  double _val;

◆ operator<=()

constexpr bool lsst::afw::geom::Angle::operator<= ( const Angle rhs) const
inlinenoexcept

Compare the sizes of two Angles (without wrapping).

Definition at line 241 of file Angle.h.

249 :
250  double _val;

◆ operator=() [1/2]

Angle& lsst::afw::geom::Angle::operator= ( Angle const &  other)
defaultnoexcept

Copy assignment.

◆ operator=() [2/2]

Angle& lsst::afw::geom::Angle::operator= ( Angle &&  other)
defaultnoexcept

Move assignment.

◆ operator==()

constexpr bool lsst::afw::geom::Angle::operator== ( const Angle rhs) const
inlinenoexcept

Test if two Angles represent the same angle (without wrapping).

Definition at line 236 of file Angle.h.

249 :
250  double _val;

◆ operator>()

constexpr bool lsst::afw::geom::Angle::operator> ( const Angle rhs) const
inlinenoexcept

Compare the sizes of two Angles (without wrapping).

Definition at line 244 of file Angle.h.

249 :
250  double _val;

◆ operator>=()

constexpr bool lsst::afw::geom::Angle::operator>= ( const Angle rhs) const
inlinenoexcept

Compare the sizes of two Angles (without wrapping).

Definition at line 242 of file Angle.h.

249 :
250  double _val;

◆ separation()

Angle lsst::afw::geom::Angle::separation ( Angle const &  other) const
inlinenoexcept

The signed difference between two Angles.

Parameters
otherthe angle to which this angle will be compared
Returns
*this - other, wrapped to the range [-π, π)
Exception Safety
Shall not throw exceptions.

Definition at line 418 of file Angle.h.

418 { return (*this - other).wrapCtr(); }
ItemVariant const * other
Definition: Schema.cc:55

◆ wrap()

Angle lsst::afw::geom::Angle::wrap ( ) const
inlinenoexcept

Wrap this angle to the range [0, 2π).

Returns
an angle in the normalized interval.
Exception Safety
Shall not throw exceptions.
Warning
The upper limit is only guaranteed for radians; the upper limit may be slightly squishy for other units, due to roundoff errors. Whether there are any violations is unknown; please update this comment if you can prove that the limits are or are not valid for all supported units.

Definition at line 372 of file Angle.h.

372  {
373  double wrapped = std::fmod(_val, TWOPI);
374  // wrapped is in the range (-TWOPI, TWOPI)
375  if (wrapped < 0.0) wrapped += TWOPI;
376  // if wrapped is small enough, adding 2 pi gives 2 pi
377  if (wrapped >= TWOPI) wrapped = 0.0;
378  return wrapped * radians;
379 }
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
T fmod(T... args)
double constexpr TWOPI
Definition: Angle.h:22

◆ wrapCtr()

Angle lsst::afw::geom::Angle::wrapCtr ( ) const
inlinenoexcept

Wrap this angle to the range [-π, π).

Returns
an angle in the normalized interval.
Exception Safety
Shall not throw exceptions.
Warning
Exact limits are only guaranteed for radians; limits for other units may be slightly squishy, due to roundoff errors. Whether there are any violations is unknown; please update this comment if you can prove that the limits are or are not valid for all supported units.

Definition at line 381 of file Angle.h.

381  {
382  double wrapped = std::fmod(_val, TWOPI);
383  // wrapped is in the range [-TWOPI, TWOPI]
384  if (wrapped < -PI) {
385  wrapped += TWOPI;
386  if (wrapped >= PI) {
387  // handle roundoff error, however unlikely
388  wrapped = -PI;
389  }
390  } else if (wrapped >= PI) {
391  wrapped -= TWOPI;
392  if (wrapped < -PI) {
393  // handle roundoff error, however unlikely
394  wrapped = -PI;
395  }
396  }
397  return wrapped * radians;
398 }
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
T fmod(T... args)
double constexpr PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:21
double constexpr TWOPI
Definition: Angle.h:22

◆ wrapNear()

Angle lsst::afw::geom::Angle::wrapNear ( Angle const &  refAng) const
inlinenoexcept

Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.

Parameters
refAngreference angle to match
Returns
an angle in the custom normalized interval.
Exception Safety
Shall not throw exceptions.
Warning
The only firm limit is -π ≤ x - refAng in radians. The upper limit in radians and both limits in other units are somewhat squishy, due to roundoff error.

Definition at line 400 of file Angle.h.

400  {
401  // compute (this - refAng).wrapCtr() + refAng
402  // which is correct except for roundoff error at the edges
403  double const refAngRad = refAng.asRadians();
404  double wrapped = (*this - refAng).wrapCtr().asRadians() + refAngRad;
405 
406  // roundoff can cause slightly out-of-range values; fix those as bast we can;
407  // note that both conditionals are wanted, since either or both may execute
408  // (though if/else could be used if the lower limit was squishy for radians)
409  if (wrapped - refAngRad >= PI) {
410  wrapped -= TWOPI;
411  }
412  if (wrapped - refAngRad < -PI) {
413  wrapped += TWOPI;
414  }
415  return wrapped * radians;
416 }
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
double constexpr PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:21
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
Definition: Angle.h:381
constexpr double asRadians() const noexcept
Return an Angle&#39;s value in radians.
Definition: Angle.h:141
double constexpr TWOPI
Definition: Angle.h:22

Friends And Related Function Documentation

◆ AngleUnit

friend class AngleUnit
friend

Definition at line 103 of file Angle.h.

◆ operator*() [1/3]

constexpr Angle operator* ( Angle  a,
Angle  d 
)
related

Product of two angles.

Warning
The result will be treated like an planar angle, not a solid angle.

Definition at line 291 of file Angle.h.

310 { return Angle(-static_cast<double>(angle)); }
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator*() [2/3]

constexpr Angle operator* ( Angle  a,
double  d 
)
related

Product of an angle and a scalar.

Definition at line 298 of file Angle.h.

310 { return Angle(-static_cast<double>(angle)); }
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator*() [3/3]

template<typename T >
constexpr Angle operator* ( lhs,
AngleUnit  rhs 
)
related

Use AngleUnit to convert a POD (e.g. int, double) to an Angle; e.g. 180*degrees.

Parameters
lhsthe value to convert
rhsthe conversion coefficient
Exception Safety
Shall not throw exceptions.

Definition at line 364 of file Angle.h.

364  {
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);
368 }
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator+()

constexpr Angle operator+ ( Angle  a,
Angle  d 
)
related

Sum of two angles.

Definition at line 277 of file Angle.h.

310 { return Angle(-static_cast<double>(angle)); }
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator-() [1/2]

constexpr Angle operator- ( Angle  a,
Angle  d 
)
related

Difference of two angles.

Definition at line 283 of file Angle.h.

310 { return Angle(-static_cast<double>(angle)); }
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator-() [2/2]

constexpr Angle operator- ( Angle  angle)
related

An angle in the opposite sense.

Definition at line 310 of file Angle.h.

310 { return Angle(-static_cast<double>(angle)); }
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator/() [1/2]

constexpr Angle operator/ ( Angle  a,
int  d 
)
related

Ratio of an angle and a scalar.

Definition at line 318 of file Angle.h.

318 { return Angle(static_cast<double>(a) / d); }
table::Key< int > a
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator/() [2/2]

constexpr Angle operator/ ( Angle  a,
double  d 
)
related

Ratio of an angle and a scalar.

Definition at line 325 of file Angle.h.

325 { return Angle(static_cast<double>(a) / d); }
table::Key< int > a
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:114

◆ operator<<()

std::ostream & operator<< ( std::ostream s,
Angle  a 
)
related

Print an Angle to a stream.

The exact details of the string representation are unspecified and subject to change, but the following may be regarded as typical: "0.567 rad".

Parameters
sThe output stream.
aThe angle.
Exception Safety
Provides basic exception guarantee.

Definition at line 10 of file Angle.cc.

10 { return s << static_cast<double>(a) << " rad"; }
table::Key< int > a

The documentation for this class was generated from the following file: