LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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
34namespace lsst {
35namespace sphgeom {
36
37// Forward declarations
38class LonLat;
39class Vector3d;
40
44public:
47 }
48
49 static NormalizedAngle fromDegrees(double a) {
51 }
52
53 static NormalizedAngle fromRadians(double a) {
54 return NormalizedAngle(a);
55 }
56
65 NormalizedAngle const & b);
66
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
148private:
149 Angle _a;
150};
151
152inline 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.