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
NormalizedAngleInterval.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_NORMALIZEDANGLEINTERVAL_H_
24 #define LSST_SPHGEOM_NORMALIZEDANGLEINTERVAL_H_
25 
29 
30 #include <iosfwd>
31 
32 #include "NormalizedAngle.h"
33 #include "Relationship.h"
34 
35 
36 namespace lsst {
37 namespace sphgeom {
38 
58 public:
59  // Factory functions
60  static NormalizedAngleInterval fromDegrees(double a, double b) {
63  }
64 
65  static NormalizedAngleInterval fromRadians(double a, double b) {
67  }
68 
70  return NormalizedAngleInterval();
71  }
72 
75  NormalizedAngle(2.0 * PI));
76  }
77 
80  _a(NormalizedAngle::nan()), _b(NormalizedAngle::nan()) {}
81 
84  explicit NormalizedAngleInterval(Angle const & x) : _a(x), _b(_a) {}
85 
88  _a(x), _b(x) {}
89 
97 
100  _a(x), _b(y) {}
101 
103  bool operator==(NormalizedAngleInterval const & i) const {
104  return (_a == i._a && _b == i._b) || (isEmpty() && i.isEmpty());
105  }
106 
107  bool operator!=(NormalizedAngleInterval const & i) const {
108  return !(*this == i);
109  }
110 
113  return (_a == x && _b == x) || (x.isNan() && isEmpty());
114  }
115 
116  bool operator!=(NormalizedAngle x) const { return !(*this == x); }
117 
119  NormalizedAngle getA() const { return _a; }
120 
122  NormalizedAngle getB() const { return _b; }
123 
126  bool isEmpty() const { return _a.isNan() || _b.isNan(); }
127 
129  bool isFull() const {
130  return _a.asRadians() == 0.0 && _b.asRadians() == 2.0 * PI;
131  }
132 
135  bool wraps() const { return _a > _b; }
136 
140 
145  NormalizedAngle getSize() const { return _a.getAngleTo(_b); }
146 
150  bool contains(NormalizedAngle x) const {
151  if (x.isNan()) {
152  return true;
153  }
154  return wraps() ? (x <= _b || _a <= x) : (_a <= x && x <= _b);
155  }
156 
157  bool contains(NormalizedAngleInterval const & x) const;
159 
164  return !intersects(x);
165  }
166 
167  bool isDisjointFrom(NormalizedAngleInterval const & x) const;
169 
174  return wraps() ? (x <= _b || _a <= x) : (_a <= x && x <= _b);
175  }
176 
177  bool intersects(NormalizedAngleInterval const & x) const {
178  return !isDisjointFrom(x);
179  }
181 
185  bool isWithin(NormalizedAngle x) const {
186  return (_a == x && _b == x) || isEmpty();
187  }
188 
189  bool isWithin(NormalizedAngleInterval const & x) const {
190  return x.contains(*this);
191  }
193 
201 
204  *this = clippedTo(x);
205  return *this;
206  }
207 
212 
215  return contains(x) ? NormalizedAngleInterval(x) : empty();
216  }
217 
222  return NormalizedAngleInterval(*this).clipTo(x);
223  }
224 
232 
238  return NormalizedAngleInterval(*this).expandTo(x);
239  }
240 
242  return NormalizedAngleInterval(*this).expandTo(x);
243  }
245 
252 
254  *this = dilatedBy(x);
255  return *this;
256  }
257 
259 
260 private:
261  NormalizedAngle _a;
262  NormalizedAngle _b;
263 };
264 
265 std::ostream & operator<<(std::ostream &, NormalizedAngleInterval const &);
266 
267 }} // namespace lsst::sphgeom
268 
269 #endif // LSST_SPHGEOM_NORMALIZEDANGLEINTERVAL_H_
double x
This file declares a class for representing normalized angles.
int y
Definition: SpanSet.cc:48
table::Key< int > b
table::Key< int > a
Angle represents an angle in radians.
Definition: Angle.h:43
static Angle fromDegrees(double a)
Definition: Angle.h:49
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.
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 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...
NormalizedAngleInterval represents closed intervals of normalized angles, i.e.
static NormalizedAngleInterval empty()
NormalizedAngleInterval & clipTo(NormalizedAngle x)
clipTo shrinks this interval until all its points are in x.
bool isFull() const
isFull returns true if this interval contains all normalized angles.
bool isDisjointFrom(NormalizedAngle x) const
NormalizedAngleInterval()
This constructor creates an empty interval.
bool wraps() const
wraps returns true if the interval "wraps" around the 0/2π angle discontinuity, i....
NormalizedAngleInterval clippedTo(NormalizedAngleInterval const &x) const
clippedTo returns the smallest interval containing the intersection of this interval and x.
NormalizedAngleInterval(NormalizedAngle x, NormalizedAngle y)
This constructor creates an interval with the given endpoints.
NormalizedAngle getA() const
getA returns the first endpoint of this interval.
NormalizedAngle getCenter() const
getCenter returns the center of this interval.
bool intersects(NormalizedAngleInterval const &x) const
bool operator==(NormalizedAngle x) const
A closed interval is equal to a point x if both endpoints equal x.
NormalizedAngleInterval(Angle const &x)
This constructor creates a closed interval containing only the normalization of x.
bool isWithin(NormalizedAngleInterval const &x) const
NormalizedAngleInterval expandedTo(NormalizedAngleInterval const &x) const
NormalizedAngleInterval dilatedBy(Angle x) const
For positive x, dilatedBy returns the morphological dilation of this interval by [-x,...
NormalizedAngleInterval & erodeBy(Angle x)
Relationship relate(NormalizedAngle x) const
NormalizedAngleInterval erodedBy(Angle x) const
NormalizedAngleInterval expandedTo(NormalizedAngle x) const
NormalizedAngle getSize() const
getSize returns the size (length, width) of this interval.
NormalizedAngleInterval & expandTo(NormalizedAngle x)
NormalizedAngle getB() const
getB returns the second endpoint of this interval.
bool operator==(NormalizedAngleInterval const &i) const
Two intervals are equal if they contain the same points.
NormalizedAngleInterval & dilateBy(Angle x)
NormalizedAngleInterval(NormalizedAngle const &x)
This constructor creates a closed interval containing only x.
bool operator!=(NormalizedAngleInterval const &i) const
static NormalizedAngleInterval fromDegrees(double a, double b)
static NormalizedAngleInterval fromRadians(double a, double b)
NormalizedAngleInterval clippedTo(NormalizedAngle x) const
clippedTo returns the intersection of this interval and x.
static NormalizedAngleInterval full()
bool isEmpty() const
isEmpty returns true if this interval does not contain any normalized angles.
lsst::geom::Angle Angle
Definition: misc.h:33
std::ostream & operator<<(std::ostream &, Angle const &)
Definition: Angle.cc:34
constexpr double PI
Definition: constants.h:36
A base class for image defects.
This file provides a type alias for describing set relationships.