LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Friends | Related Symbols | 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).
 
constexpr Angle () noexcept
 Construct the zero angle.
 
 Angle (sphgeom::Angle const &sgAngle) noexcept
 Convert from a sphgeom::Angle instance.
 
constexpr Angle (Angle const &other) noexcept=default
 Copy constructor.
 
constexpr Angle (Angle &&other) noexcept=default
 Move constructor.
 
Angleoperator= (Angle const &other) noexcept=default
 Copy assignment.
 
Angleoperator= (Angle &&other) noexcept=default
 Move assignment.
 
 ~Angle ()=default
 
constexpr operator double () const noexcept
 Convert an Angle to a double in radians.
 
 operator sphgeom::Angle () const noexcept
 Convert to a sphgeom::Angle instance.
 
constexpr double asAngularUnits (AngleUnit const &units) const noexcept
 Return an Angle's value in the specified units.
 
constexpr double asRadians () const noexcept
 Return an Angle's value in radians.
 
constexpr double asDegrees () const noexcept
 Return an Angle's value in degrees.
 
constexpr double asHours () const noexcept
 Return an Angle's value in hours.
 
constexpr double asArcminutes () const noexcept
 Return an Angle's value in arcminutes.
 
constexpr double asArcseconds () const noexcept
 Return an Angle's value in arcseconds.
 
constexpr double asMilliarcseconds () const noexcept
 Return an Angle's value in milliarcseconds.
 
Angle wrap () const noexcept
 Wrap this angle to the range [0, 2π).
 
Angle wrapCtr () const noexcept
 Wrap this angle to the range [-π, π).
 
Angle wrapNear (Angle const &refAng) const noexcept
 Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
 
Angle separation (Angle const &other) const noexcept
 The signed difference between two Angles.
 
Angleoperator*= (double const &d) noexcept
 Multiply this angle by the given factor.
 
Angleoperator*= (int const &d) noexcept
 
Angleoperator+= (double const &d) noexcept
 Increase this angle by the given number of radians.
 
Angleoperator+= (int const &d) noexcept
 
Angleoperator-= (double const &d) noexcept
 Decrease this angle by the given number of radians.
 
Angleoperator-= (int const &d) noexcept
 
constexpr bool operator== (const Angle &rhs) const noexcept
 Test if two Angles represent the same angle (without wrapping).
 
constexpr bool operator!= (const Angle &rhs) const noexcept
 
constexpr bool operator<= (const Angle &rhs) const noexcept
 Compare the sizes of two Angles (without wrapping).
 
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.
 

Friends

class AngleUnit
 

Related Symbols

(Note that these are not member symbols.)

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

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

Constructor & Destructor Documentation

◆ Angle() [1/5]

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

137: _val(val * units._val) {}
ImageT val
Definition CR.cc:146

◆ Angle() [2/5]

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

Construct the zero angle.

Definition at line 140 of file Angle.h.

140: _val(0) {}

◆ Angle() [3/5]

lsst::geom::Angle::Angle ( sphgeom::Angle const & sgAngle)
inlineexplicitnoexcept

Convert from a sphgeom::Angle instance.

Definition at line 143 of file Angle.h.

143: Angle(sgAngle.asRadians()) {}
constexpr Angle() noexcept
Construct the zero angle.
Definition Angle.h:140

◆ Angle() [4/5]

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

Copy constructor.

◆ Angle() [5/5]

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

170{ return _val / units._val; }

◆ asArcminutes()

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

Return an Angle's value in arcminutes.

Definition at line 182 of file Angle.h.

182{ return asAngularUnits(arcminutes); }
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
Definition Angle.h:170
AngleUnit constexpr arcminutes
constant with units of arcminutes
Definition Angle.h:112

◆ asArcseconds()

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

Return an Angle's value in arcseconds.

Definition at line 185 of file Angle.h.

185{ return asAngularUnits(arcseconds); }

◆ asDegrees()

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

Return an Angle's value in degrees.

Definition at line 176 of file Angle.h.

176{ return asAngularUnits(degrees); }

◆ asHours()

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

Return an Angle's value in hours.

Definition at line 179 of file Angle.h.

179{ return asAngularUnits(hours); }
AngleUnit constexpr hours
constant with units of hours
Definition Angle.h:111

◆ asMilliarcseconds()

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

Return an Angle's value in milliarcseconds.

Definition at line 188 of file Angle.h.

AngleUnit constexpr milliarcseconds
constant with units of milliarcseconds
Definition Angle.h:116

◆ asRadians()

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

Return an Angle's value in radians.

Definition at line 173 of file Angle.h.

173{ return asAngularUnits(radians); }

◆ hash_value()

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

Return a hash of this object.

Definition at line 285 of file Angle.h.

285{ 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 160 of file Angle.h.

160{ return _val; }

◆ operator sphgeom::Angle()

lsst::geom::Angle::operator sphgeom::Angle ( ) const
inlinenoexcept

Convert to a sphgeom::Angle instance.

Definition at line 163 of file Angle.h.

163{ return sphgeom::Angle::fromRadians(_val); }
static Angle fromRadians(double a)
Definition Angle.h:58

◆ operator!=()

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

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

◆ operator*=() [2/2]

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

Definition at line 251 of file Angle.h.

◆ operator+=() [1/2]

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

Increase this angle by the given number of radians.

Definition at line 255 of file Angle.h.

◆ operator+=() [2/2]

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

Definition at line 256 of file Angle.h.

◆ operator-=() [1/2]

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

Decrease this angle by the given number of radians.

Definition at line 260 of file Angle.h.

◆ operator-=() [2/2]

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

Definition at line 261 of file Angle.h.

◆ operator<()

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

Definition at line 278 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 276 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 271 of file Angle.h.

◆ operator>()

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

Definition at line 279 of file Angle.h.

◆ operator>=()

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

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

456{ 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 410 of file Angle.h.

410 {
411 double wrapped = std::fmod(_val, TWOPI);
412 // wrapped is in the range (-TWOPI, TWOPI)
413 if (wrapped < 0.0) wrapped += TWOPI;
414 // if wrapped is small enough, adding 2 pi gives 2 pi
415 if (wrapped >= TWOPI) wrapped = 0.0;
416 return wrapped * radians;
417}
T fmod(T... args)
double constexpr TWOPI
Definition Angle.h:41
AngleUnit constexpr radians
constant with units of radians
Definition Angle.h:109

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

419 {
420 double wrapped = std::fmod(_val, TWOPI);
421 // wrapped is in the range [-TWOPI, TWOPI]
422 if (wrapped < -PI) {
423 wrapped += TWOPI;
424 if (wrapped >= PI) {
425 // handle roundoff error, however unlikely
426 wrapped = -PI;
427 }
428 } else if (wrapped >= PI) {
429 wrapped -= TWOPI;
430 if (wrapped < -PI) {
431 // handle roundoff error, however unlikely
432 wrapped = -PI;
433 }
434 }
435 return wrapped * radians;
436}
double constexpr PI
The ratio of a circle's circumference to diameter.
Definition Angle.h:40

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

438 {
439 // compute (this - refAng).wrapCtr() + refAng
440 // which is correct except for roundoff error at the edges
441 double const refAngRad = refAng.asRadians();
442 double wrapped = (*this - refAng).wrapCtr().asRadians() + refAngRad;
443
444 // roundoff can cause slightly out-of-range values; fix those as bast we can;
445 // note that both conditionals are wanted, since either or both may execute
446 // (though if/else could be used if the lower limit was squishy for radians)
447 if (wrapped - refAngRad >= PI) {
448 wrapped -= TWOPI;
449 }
450 if (wrapped - refAngRad < -PI) {
451 wrapped += TWOPI;
452 }
453 return wrapped * radians;
454}
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
Definition Angle.h:419
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
Definition Angle.h:173

Friends And Related Symbol Documentation

◆ AngleUnit

friend class AngleUnit
friend

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

◆ operator*() [2/3]

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

Product of an angle and a scalar.

Definition at line 336 of file Angle.h.

◆ operator*() [3/3]

template<typename T >
constexpr Angle operator* ( T 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 402 of file Angle.h.

402 {
403 static_assert(std::is_arithmetic<T>::value,
404 "Only numeric types may be multiplied by an AngleUnit to create an Angle!");
405 return Angle(lhs * rhs._val);
406}

◆ operator+()

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

Sum of two angles.

Definition at line 315 of file Angle.h.

◆ operator-() [1/2]

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

Difference of two angles.

Definition at line 321 of file Angle.h.

◆ operator-() [2/2]

constexpr Angle operator- ( Angle angle)
related

An angle in the opposite sense.

Definition at line 348 of file Angle.h.

348{ return Angle(-static_cast<double>(angle)); }
table::Key< double > angle

◆ operator/() [1/2]

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

Ratio of an angle and a scalar.

Definition at line 363 of file Angle.h.

363{ 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 356 of file Angle.h.

356{ 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: