lsst.sphgeom gbd998247f1+585e252eca
Loading...
Searching...
No Matches
NormalizedAngleInterval.h
Go to the documentation of this file.
1/*
2 * This file is part of sphgeom.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (http://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This software is dual licensed under the GNU General Public License and also
11 * under a 3-clause BSD license. Recipients may choose which of these licenses
12 * to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
13 * respectively. If you choose the GPL option then the following text applies
14 * (but note that there is still no warranty even if you opt for BSD instead):
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30#ifndef LSST_SPHGEOM_NORMALIZEDANGLEINTERVAL_H_
31#define LSST_SPHGEOM_NORMALIZEDANGLEINTERVAL_H_
32
36
37#include <iosfwd>
38
39#include "NormalizedAngle.h"
40#include "Relationship.h"
41
42
43namespace lsst {
44namespace sphgeom {
45
65public:
66 // Factory functions
67 static NormalizedAngleInterval fromDegrees(double a, double b) {
68 return NormalizedAngleInterval(Angle::fromDegrees(a),
69 Angle::fromDegrees(b));
70 }
71
72 static NormalizedAngleInterval fromRadians(double a, double b) {
73 return NormalizedAngleInterval(Angle(a), Angle(b));
74 }
75
76 static NormalizedAngleInterval empty() {
78 }
79
80 static NormalizedAngleInterval full() {
82 NormalizedAngle(2.0 * PI));
83 }
84
88
91 explicit NormalizedAngleInterval(Angle const & x) : _a(x), _b(_a) {}
92
95 _a(x), _b(x) {}
96
104
108
110 bool operator==(NormalizedAngleInterval const & i) const {
111 return (_a == i._a && _b == i._b) || (isEmpty() && i.isEmpty());
112 }
113
114 bool operator!=(NormalizedAngleInterval const & i) const {
115 return !(*this == i);
116 }
117
120 return (_a == x && _b == x) || (x.isNan() && isEmpty());
121 }
122
123 bool operator!=(NormalizedAngle x) const { return !(*this == x); }
124
126 NormalizedAngle getA() const { return _a; }
127
129 NormalizedAngle getB() const { return _b; }
130
133 bool isEmpty() const { return _a.isNan() || _b.isNan(); }
134
136 bool isFull() const {
137 return _a.asRadians() == 0.0 && _b.asRadians() == 2.0 * PI;
138 }
139
142 bool wraps() const { return _a > _b; }
143
147
152 NormalizedAngle getSize() const { return _a.getAngleTo(_b); }
153
157 bool contains(NormalizedAngle x) const {
158 if (x.isNan()) {
159 return true;
160 }
161 return wraps() ? (x <= _b || _a <= x) : (_a <= x && x <= _b);
162 }
163
164 bool contains(NormalizedAngleInterval const & x) const;
166
171 return !intersects(x);
172 }
173
174 bool isDisjointFrom(NormalizedAngleInterval const & x) const;
176
181 return wraps() ? (x <= _b || _a <= x) : (_a <= x && x <= _b);
182 }
183
184 bool intersects(NormalizedAngleInterval const & x) const {
185 return !isDisjointFrom(x);
186 }
188
192 bool isWithin(NormalizedAngle x) const {
193 return (_a == x && _b == x) || isEmpty();
194 }
195
196 bool isWithin(NormalizedAngleInterval const & x) const {
197 return x.contains(*this);
198 }
200
205 Relationship relate(NormalizedAngle x) const;
208
211 *this = clippedTo(x);
212 return *this;
213 }
214
219
224
231
239
247
249 return NormalizedAngleInterval(*this).expandTo(x);
250 }
252
257 NormalizedAngleInterval dilatedBy(Angle x) const;
258 NormalizedAngleInterval erodedBy(Angle x) const { return dilatedBy(-x); }
259
260 NormalizedAngleInterval & dilateBy(Angle x) {
261 *this = dilatedBy(x);
262 return *this;
263 }
264
265 NormalizedAngleInterval & erodeBy(Angle x) { return dilateBy(-x); }
266
267private:
268 NormalizedAngle _a;
269 NormalizedAngle _b;
270};
271
272std::ostream & operator<<(std::ostream &, NormalizedAngleInterval const &);
273
274}} // namespace lsst::sphgeom
275
276#endif // LSST_SPHGEOM_NORMALIZEDANGLEINTERVAL_H_
This file declares a class for representing normalized angles.
Definition Angle.h:50
Definition NormalizedAngle.h:50
bool isNan() const
isNan returns true if the angle value is NaN.
Definition NormalizedAngle.h:140
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition NormalizedAngle.h:137
NormalizedAngle getAngleTo(NormalizedAngle const &a) const
Definition NormalizedAngle.h:148
static NormalizedAngle center(NormalizedAngle const &a, NormalizedAngle const &b)
Definition NormalizedAngle.cc:52
Definition NormalizedAngleInterval.h:64
bool isFull() const
isFull returns true if this interval contains all normalized angles.
Definition NormalizedAngleInterval.h:136
bool isDisjointFrom(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:170
NormalizedAngleInterval()
This constructor creates an empty interval.
Definition NormalizedAngleInterval.h:86
bool wraps() const
Definition NormalizedAngleInterval.h:142
NormalizedAngleInterval clippedTo(NormalizedAngleInterval const &x) const
Definition NormalizedAngleInterval.h:228
NormalizedAngleInterval & clipTo(NormalizedAngle x)
clipTo shrinks this interval until all its points are in x.
Definition NormalizedAngleInterval.h:210
NormalizedAngleInterval(NormalizedAngle x, NormalizedAngle y)
This constructor creates an interval with the given endpoints.
Definition NormalizedAngleInterval.h:106
NormalizedAngle getA() const
getA returns the first endpoint of this interval.
Definition NormalizedAngleInterval.h:126
NormalizedAngle getCenter() const
Definition NormalizedAngleInterval.h:146
bool operator==(NormalizedAngle x) const
A closed interval is equal to a point x if both endpoints equal x.
Definition NormalizedAngleInterval.h:119
NormalizedAngleInterval(Angle const &x)
Definition NormalizedAngleInterval.h:91
NormalizedAngleInterval dilatedBy(Angle x) const
Definition NormalizedAngleInterval.cc:239
Relationship relate(NormalizedAngle x) const
Definition NormalizedAngleInterval.cc:95
NormalizedAngleInterval expandedTo(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:244
NormalizedAngle getSize() const
Definition NormalizedAngleInterval.h:152
NormalizedAngleInterval & expandTo(NormalizedAngle x)
Definition NormalizedAngleInterval.cc:196
NormalizedAngle getB() const
getB returns the second endpoint of this interval.
Definition NormalizedAngleInterval.h:129
bool intersects(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:180
bool operator==(NormalizedAngleInterval const &i) const
Two intervals are equal if they contain the same points.
Definition NormalizedAngleInterval.h:110
NormalizedAngleInterval(NormalizedAngle const &x)
This constructor creates a closed interval containing only x.
Definition NormalizedAngleInterval.h:94
bool isWithin(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:192
NormalizedAngleInterval clippedTo(NormalizedAngle x) const
clippedTo returns the intersection of this interval and x.
Definition NormalizedAngleInterval.h:221
bool contains(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:157
bool isEmpty() const
Definition NormalizedAngleInterval.h:133
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition Relationship.h:42
This file provides a type alias for describing set relationships.