LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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
This file declares a class for representing angles.
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)
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