LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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 <limits>
30 
31 #include "Angle.h"
32 
33 
34 namespace lsst {
35 namespace sphgeom {
36 
37 // Forward declarations
38 class LonLat;
39 class Vector3d;
40 
44 public:
45  static NormalizedAngle nan() {
47  }
48 
49  static NormalizedAngle fromDegrees(double a) {
50  return NormalizedAngle(a * RAD_PER_DEG);
51  }
52 
53  static NormalizedAngle fromRadians(double a) {
54  return NormalizedAngle(a);
55  }
56 
65  NormalizedAngle const & b);
66 
69  static NormalizedAngle center(NormalizedAngle const & a,
70  NormalizedAngle const & b);
71 
73  NormalizedAngle() = default;
74 
76  NormalizedAngle(NormalizedAngle const & a) = default;
77 
79  explicit NormalizedAngle(Angle const & a) {
80  *this = NormalizedAngle(a.asRadians());
81  }
82 
85  explicit NormalizedAngle(double a) {
86  // For really large |a|, the error in this reduction can exceed 2*PI
87  // (because PI is only an approximation to π).
88  if (a < 0.0) {
89  _a = Angle(std::fmod(a, 2.0 * PI) + 2.0 * PI);
90  } else if (a > 2 * PI) {
91  _a = Angle(std::fmod(a, 2.0 * PI));
92  } else {
93  _a = Angle(a);
94  }
95  }
96 
99  NormalizedAngle(LonLat const &, LonLat const &);
100 
103  NormalizedAngle(Vector3d const &, Vector3d const &);
104 
108  operator Angle const & () const { return _a; }
109 
110  // Comparison operators
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  bool operator<=(Angle const & a) const { return _a <= a; }
116  bool operator>=(Angle const & a) const { return _a >= a; }
117 
118  // Arithmetic operators
119  Angle operator-() const { return Angle(-_a); }
120  Angle operator+(Angle const & a) const { return _a + a; }
121  Angle operator-(Angle const & a) const { return _a - a; }
122  Angle operator*(double a) const { return _a * a; }
123  Angle operator/(double a) const { return _a / a; }
124  double operator/(Angle const & a) const { return _a / a; }
125 
127  double asDegrees() const { return _a.asDegrees(); }
128 
130  double asRadians() const { return _a.asRadians(); }
131 
133  bool isNan() const { return _a.isNan(); }
134 
143  double d = a.asRadians() - asRadians();
144  x._a = Angle((d < 0.0) ? 2.0 * PI + d : d);
145  return x;
146  }
147 
148 private:
149  Angle _a;
150 };
151 
152 inline NormalizedAngle const & abs(NormalizedAngle const & a) { return a; }
153 
154 }} // namespace lsst::sphgeom
155 
156 #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...
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
NormalizedAngle()=default
This constructor creates a NormalizedAngle with a value of zero.
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
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...
NormalizedAngle(NormalizedAngle const &a)=default
This constructor creates a copy of a.
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.