LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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)
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
This file declares a class for representing angles.
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