LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
NormalizedAngle.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2014-2015 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #ifndef LSST_SPHGEOM_NORMALIZEDANGLE_H_
24 #define LSST_SPHGEOM_NORMALIZEDANGLE_H_
25 
28 
29 #include "Angle.h"
30 
31 
32 namespace lsst {
33 namespace sphgeom {
34 
35 // Forward declarations
36 class LonLat;
37 class Vector3d;
38 
42 public:
43  static NormalizedAngle nan() {
45  }
46 
47  static NormalizedAngle fromDegrees(double a) {
48  return NormalizedAngle(a * RAD_PER_DEG);
49  }
50 
51  static NormalizedAngle fromRadians(double a) {
52  return NormalizedAngle(a);
53  }
54 
63  NormalizedAngle const & b);
64 
67  static NormalizedAngle center(NormalizedAngle const & a,
68  NormalizedAngle const & b);
69 
72 
74  NormalizedAngle(NormalizedAngle const & a) : _a(a._a) {}
75 
77  explicit NormalizedAngle(Angle const & a) {
78  *this = NormalizedAngle(a.asRadians());
79  }
80 
83  explicit NormalizedAngle(double a) {
84  // For really large |a|, the error in this reduction can exceed 2*PI
85  // (because PI is only an approximation to π).
86  if (a < 0.0) {
87  _a = Angle(std::fmod(a, 2.0 * PI) + 2.0 * PI);
88  } else if (a > 2 * PI) {
89  _a = Angle(std::fmod(a, 2.0 * PI));
90  } else {
91  _a = Angle(a);
92  }
93  }
94 
97  NormalizedAngle(LonLat const &, LonLat const &);
98 
101  NormalizedAngle(Vector3d const &, Vector3d const &);
102 
106  operator Angle const & () const { return _a; }
107 
108  // Comparison operators
109  bool operator==(Angle const & a) const { return _a == a; }
110  bool operator!=(Angle const & a) const { return _a != a; }
111  bool operator<(Angle const & a) const { return _a < a; }
112  bool operator>(Angle const & a) const { return _a > a; }
113  bool operator<=(Angle const & a) const { return _a <= a; }
114  bool operator>=(Angle const & a) const { return _a >= a; }
115 
116  // Arithmetic operators
117  Angle operator-() const { return Angle(-_a); }
118  Angle operator+(Angle const & a) const { return _a + a; }
119  Angle operator-(Angle const & a) const { return _a - a; }
120  Angle operator*(double a) const { return _a * a; }
121  Angle operator/(double a) const { return _a / a; }
122  double operator/(Angle const & a) const { return _a / a; }
123 
125  double asDegrees() const { return _a.asDegrees(); }
126 
128  double asRadians() const { return _a.asRadians(); }
129 
131  bool isNan() const { return _a.isNan(); }
132 
141  double d = a.asRadians() - asRadians();
142  x._a = Angle((d < 0.0) ? 2.0 * PI + d : d);
143  return x;
144  }
145 
146 private:
147  Angle _a;
148 };
149 
150 inline NormalizedAngle const & abs(NormalizedAngle const & a) { return a; }
151 
152 }} // namespace lsst::sphgeom
153 
154 #endif // LSST_SPHGEOM_NORMALIZEDANGLE_H_
double x
table::Key< int > b
table::Key< int > a
Angle represents an angle in radians.
Definition: Angle.h:43
bool isNan() const
isNan returns true if the angle value is NaN.
Definition: Angle.h:91
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
Definition: Angle.h:82
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition: LonLat.h:48
NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle ca...
bool operator!=(Angle const &a) const
bool operator>=(Angle const &a) const
bool operator<=(Angle const &a) const
bool operator==(Angle const &a) const
bool isNan() const
isNan returns true if the angle value is NaN.
NormalizedAngle(double a)
This constructor creates a NormalizedAngle with the given value in radians, normalized to be in the r...
NormalizedAngle(NormalizedAngle const &a)
This constructor creates a copy of a.
double asRadians() const
asRadians returns the value of this angle in units of radians.
NormalizedAngle getAngleTo(NormalizedAngle const &a) const
getAngleTo computes the angle α ∈ [0, 2π) such that adding α to this angle and then normalizing the r...
static NormalizedAngle fromRadians(double a)
bool operator>(Angle const &a) const
NormalizedAngle(Angle const &a)
This constructor creates a normalized copy of a.
static NormalizedAngle nan()
Angle operator/(double a) const
Angle operator-(Angle const &a) const
Angle operator+(Angle const &a) const
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
static NormalizedAngle fromDegrees(double a)
double operator/(Angle const &a) const
bool operator<(Angle const &a) const
NormalizedAngle()
This constructor creates a NormalizedAngle with a value of zero.
static NormalizedAngle between(NormalizedAngle const &a, NormalizedAngle const &b)
For two angles a and b, between(a, b) returns the smaller of a.getAngleTo(b) and b....
Angle operator*(double a) const
static NormalizedAngle center(NormalizedAngle const &a, NormalizedAngle const &b)
For two normalized angles a and b, center(a, b) returns the angle m such that a.getAngleTo(m) is equa...
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition: Vector3d.h:44
T fmod(T... args)
lsst::geom::Angle Angle
Definition: misc.h:33
Angle abs(Angle const &a)
Definition: Angle.h:106
constexpr double RAD_PER_DEG
Definition: constants.h:38
constexpr double PI
Definition: constants.h:36
A base class for image defects.
This file declares a class for representing angles.