LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
Public Member Functions | Friends | Related Functions | List of all members
lsst::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...
 
constexpr double asMilliarcseconds () const noexcept
 Return an Angle's value in milliarcseconds. 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
 
Angleoperator+= (double const &d) noexcept
 Increase this angle by the given number of radians. More...
 
Angleoperator+= (int const &d) noexcept
 
Angleoperator-= (double const &d) noexcept
 Decrease this angle by the given number of radians. More...
 
Angleoperator-= (int const &d) noexcept
 
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
 
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
 
constexpr bool operator< (const Angle &rhs) const noexcept
 
constexpr bool operator> (const Angle &rhs) const noexcept
 
std::size_t hash_value () const noexcept
 Return a hash of this object. 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 a, double d) noexcept
 Product of an angle and a scalar. 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...
 

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 127 of file Angle.h.

Constructor & Destructor Documentation

◆ Angle() [1/4]

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

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 136 of file Angle.h.

136 : _val(val * units._val) {}

◆ Angle() [2/4]

constexpr lsst::geom::Angle::Angle ( )
inlineconstexprnoexcept

Construct the zero angle.

Definition at line 139 of file Angle.h.

139 : _val(0) {}

◆ Angle() [3/4]

constexpr lsst::geom::Angle::Angle ( Angle const &  other)
constexprdefaultnoexcept

Copy constructor.

◆ Angle() [4/4]

constexpr lsst::geom::Angle::Angle ( Angle &&  other)
constexprdefaultnoexcept

Move constructor.

◆ ~Angle()

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

Member Function Documentation

◆ asAngularUnits()

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

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 163 of file Angle.h.

163 { return _val / units._val; }

◆ asArcminutes()

constexpr double lsst::geom::Angle::asArcminutes ( ) const
inlineconstexprnoexcept

Return an Angle's value in arcminutes.

Definition at line 175 of file Angle.h.

175 { return asAngularUnits(arcminutes); }

◆ asArcseconds()

constexpr double lsst::geom::Angle::asArcseconds ( ) const
inlineconstexprnoexcept

Return an Angle's value in arcseconds.

Definition at line 178 of file Angle.h.

178 { return asAngularUnits(arcseconds); }

◆ asDegrees()

constexpr double lsst::geom::Angle::asDegrees ( ) const
inlineconstexprnoexcept

Return an Angle's value in degrees.

Definition at line 169 of file Angle.h.

169 { return asAngularUnits(degrees); }

◆ asHours()

constexpr double lsst::geom::Angle::asHours ( ) const
inlineconstexprnoexcept

Return an Angle's value in hours.

Definition at line 172 of file Angle.h.

172 { return asAngularUnits(hours); }

◆ asMilliarcseconds()

constexpr double lsst::geom::Angle::asMilliarcseconds ( ) const
inlineconstexprnoexcept

Return an Angle's value in milliarcseconds.

Definition at line 181 of file Angle.h.

181 { return asAngularUnits(milliarcseconds); }

◆ asRadians()

constexpr double lsst::geom::Angle::asRadians ( ) const
inlineconstexprnoexcept

Return an Angle's value in radians.

Definition at line 166 of file Angle.h.

166 { return asAngularUnits(radians); }

◆ hash_value()

std::size_t lsst::geom::Angle::hash_value ( ) const
inlinenoexcept

Return a hash of this object.

Definition at line 278 of file Angle.h.

278 { return std::hash<double>()(_val); }

◆ operator double()

constexpr lsst::geom::Angle::operator double ( ) const
inlineconstexprnoexcept

Convert an Angle to a double in radians.

Definition at line 156 of file Angle.h.

156 { return _val; }

◆ operator!=()

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

Definition at line 265 of file Angle.h.

◆ operator*=() [1/2]

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

Multiply this angle by the given factor.

Definition at line 243 of file Angle.h.

260 { return _val OP rhs._val; }

◆ operator*=() [2/2]

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

Definition at line 244 of file Angle.h.

260 { return _val OP rhs._val; }

◆ operator+=() [1/2]

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

Increase this angle by the given number of radians.

Definition at line 248 of file Angle.h.

260 { return _val OP rhs._val; }

◆ operator+=() [2/2]

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

Definition at line 249 of file Angle.h.

260 { return _val OP rhs._val; }

◆ operator-=() [1/2]

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

Decrease this angle by the given number of radians.

Definition at line 253 of file Angle.h.

260 { return _val OP rhs._val; }

◆ operator-=() [2/2]

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

Definition at line 254 of file Angle.h.

260 { return _val OP rhs._val; }

◆ operator<()

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

Definition at line 271 of file Angle.h.

◆ operator<=()

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

Compare the sizes of two Angles (without wrapping).

Definition at line 269 of file Angle.h.

◆ operator=() [1/2]

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

Move assignment.

◆ operator=() [2/2]

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

Copy assignment.

◆ operator==()

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

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

Definition at line 264 of file Angle.h.

◆ operator>()

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

Definition at line 272 of file Angle.h.

◆ operator>=()

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

Definition at line 270 of file Angle.h.

◆ separation()

Angle lsst::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 449 of file Angle.h.

449 { return (*this - other).wrapCtr(); }

◆ wrap()

Angle lsst::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 403 of file Angle.h.

403  {
404  double wrapped = std::fmod(_val, TWOPI);
405  // wrapped is in the range (-TWOPI, TWOPI)
406  if (wrapped < 0.0) wrapped += TWOPI;
407  // if wrapped is small enough, adding 2 pi gives 2 pi
408  if (wrapped >= TWOPI) wrapped = 0.0;
409  return wrapped * radians;
410 }

◆ wrapCtr()

Angle lsst::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 412 of file Angle.h.

412  {
413  double wrapped = std::fmod(_val, TWOPI);
414  // wrapped is in the range [-TWOPI, TWOPI]
415  if (wrapped < -PI) {
416  wrapped += TWOPI;
417  if (wrapped >= PI) {
418  // handle roundoff error, however unlikely
419  wrapped = -PI;
420  }
421  } else if (wrapped >= PI) {
422  wrapped -= TWOPI;
423  if (wrapped < -PI) {
424  // handle roundoff error, however unlikely
425  wrapped = -PI;
426  }
427  }
428  return wrapped * radians;
429 }

◆ wrapNear()

Angle lsst::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 431 of file Angle.h.

431  {
432  // compute (this - refAng).wrapCtr() + refAng
433  // which is correct except for roundoff error at the edges
434  double const refAngRad = refAng.asRadians();
435  double wrapped = (*this - refAng).wrapCtr().asRadians() + refAngRad;
436 
437  // roundoff can cause slightly out-of-range values; fix those as bast we can;
438  // note that both conditionals are wanted, since either or both may execute
439  // (though if/else could be used if the lower limit was squishy for radians)
440  if (wrapped - refAngRad >= PI) {
441  wrapped -= TWOPI;
442  }
443  if (wrapped - refAngRad < -PI) {
444  wrapped += TWOPI;
445  }
446  return wrapped * radians;
447 }

Friends And Related Function Documentation

◆ AngleUnit

friend class AngleUnit
friend

Definition at line 128 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 322 of file Angle.h.

341 { return Angle(-static_cast<double>(angle)); }

◆ operator*() [2/3]

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

Product of an angle and a scalar.

Definition at line 329 of file Angle.h.

341 { return Angle(-static_cast<double>(angle)); }

◆ 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 395 of file Angle.h.

395  {
396  static_assert(std::is_arithmetic<T>::value,
397  "Only numeric types may be multiplied by an AngleUnit to create an Angle!");
398  return Angle(lhs * rhs._val);
399 }

◆ operator+()

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

Sum of two angles.

Definition at line 308 of file Angle.h.

341 { return Angle(-static_cast<double>(angle)); }

◆ operator-() [1/2]

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

Difference of two angles.

Definition at line 314 of file Angle.h.

341 { return Angle(-static_cast<double>(angle)); }

◆ operator-() [2/2]

constexpr Angle operator- ( Angle  angle)
related

An angle in the opposite sense.

Definition at line 341 of file Angle.h.

341 { return Angle(-static_cast<double>(angle)); }

◆ operator/() [1/2]

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

Ratio of an angle and a scalar.

Definition at line 356 of file Angle.h.

356 { return Angle(static_cast<double>(a) / d); }

◆ operator/() [2/2]

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

Ratio of an angle and a scalar.

Definition at line 349 of file Angle.h.

349 { return Angle(static_cast<double>(a) / d); }

◆ 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 29 of file Angle.cc.

29 { return s << static_cast<double>(a) << " rad"; }

The documentation for this class was generated from the following file:
lsst::geom::degrees
constexpr AngleUnit degrees
constant with units of degrees
Definition: Angle.h:109
lsst::geom::PI
constexpr double PI
The ratio of a circle's circumference to diameter.
Definition: Angle.h:39
lsst::geom::Angle::wrapCtr
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
Definition: Angle.h:412
lsst::geom::arcseconds
constexpr AngleUnit arcseconds
constant with units of arcseconds
Definition: Angle.h:112
lsst::geom::Angle::Angle
constexpr Angle() noexcept
Construct the zero angle.
Definition: Angle.h:139
val
ImageT val
Definition: CR.cc:146
angle
table::Key< double > angle
Definition: FunctionLibrary.cc:22
lsst::geom::hours
constexpr AngleUnit hours
constant with units of hours
Definition: Angle.h:110
lsst::geom::Angle::asRadians
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
Definition: Angle.h:166
std::is_arithmetic
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::geom::milliarcseconds
constexpr AngleUnit milliarcseconds
constant with units of milliarcseconds
Definition: Angle.h:115
lsst::geom::TWOPI
constexpr double TWOPI
Definition: Angle.h:40
lsst::geom::Angle::asAngularUnits
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
Definition: Angle.h:163
lsst::geom::arcminutes
constexpr AngleUnit arcminutes
constant with units of arcminutes
Definition: Angle.h:111
std::fmod
T fmod(T... args)
a
table::Key< int > a
Definition: TransmissionCurve.cc:466
lsst::geom::radians
constexpr AngleUnit radians
constant with units of radians
Definition: Angle.h:108
std::hash