LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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_
Angle abs(Angle const &a)
Definition: Angle.h:106
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...
bool operator!=(Angle const &a) const
NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle ca...
bool isNan() const
isNan returns true if the angle value is NaN.
Definition: Angle.h:91
double asRadians() const
asRadians returns the value of this angle in units of radians.
NormalizedAngle()
This constructor creates a NormalizedAngle with a value of zero.
table::Key< int > b
T fmod(T... args)
table::Key< int > a
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition: Vector3d.h:44
NormalizedAngle getAngleTo(NormalizedAngle const &a) const
getAngleTo computes the angle α ∈ [0, 2π) such that adding α to this angle and then normalizing the ...
static NormalizedAngle fromDegrees(double a)
This file declares a class for representing angles.
NormalizedAngle(Angle const &a)
This constructor creates a normalized copy of a.
bool operator<=(Angle const &a) const
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
bool isNan() const
isNan returns true if the angle value is NaN.
A base class for image defects.
bool operator==(Angle const &a) const
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85
double asDegrees() const
asDegrees returns the value of this angle in units of degrees.
Definition: Angle.h:82
constexpr double PI
Definition: constants.h:36
static NormalizedAngle nan()
static NormalizedAngle fromRadians(double a)
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.getAngleTo(a).
double x
double operator/(Angle const &a) const
NormalizedAngle(double a)
This constructor creates a NormalizedAngle with the given value in radians, normalized to be in the r...
bool operator>=(Angle const &a) const
Angle represents an angle in radians.
Definition: Angle.h:43
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition: LonLat.h:48
Angle operator+(Angle const &a) const
bool operator<(Angle const &a) const
lsst::geom::Angle Angle
Definition: misc.h:33
Angle operator*(double a) const
NormalizedAngle(NormalizedAngle const &a)
This constructor creates a copy of a.
Angle operator-(Angle const &a) const
bool operator>(Angle const &a) const
constexpr double RAD_PER_DEG
Definition: constants.h:38