lsst.sphgeom g161b0bc589+ac198e9f13
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
36namespace lsst {
37namespace sphgeom {
38
58public:
59 // Factory functions
60 static NormalizedAngleInterval fromDegrees(double a, double b) {
61 return NormalizedAngleInterval(Angle::fromDegrees(a),
62 Angle::fromDegrees(b));
63 }
64
65 static NormalizedAngleInterval fromRadians(double a, double b) {
66 return NormalizedAngleInterval(Angle(a), Angle(b));
67 }
68
69 static NormalizedAngleInterval empty() {
71 }
72
73 static NormalizedAngleInterval full() {
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
198 Relationship relate(NormalizedAngle x) const;
199 Relationship relate(NormalizedAngleInterval const & x) const;
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
250 NormalizedAngleInterval dilatedBy(Angle x) const;
251 NormalizedAngleInterval erodedBy(Angle x) const { return dilatedBy(-x); }
252
253 NormalizedAngleInterval & dilateBy(Angle x) {
254 *this = dilatedBy(x);
255 return *this;
256 }
257
258 NormalizedAngleInterval & erodeBy(Angle x) { return dilateBy(-x); }
259
260private:
261 NormalizedAngle _a;
262 NormalizedAngle _b;
263};
264
265std::ostream & operator<<(std::ostream &, NormalizedAngleInterval const &);
266
267}} // namespace lsst::sphgeom
268
269#endif // LSST_SPHGEOM_NORMALIZEDANGLEINTERVAL_H_
This file declares a class for representing normalized angles.
Definition: Angle.h:43
Definition: NormalizedAngle.h:43
bool isNan() const
isNan returns true if the angle value is NaN.
Definition: NormalizedAngle.h:133
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: NormalizedAngle.h:130
NormalizedAngle getAngleTo(NormalizedAngle const &a) const
Definition: NormalizedAngle.h:141
static NormalizedAngle center(NormalizedAngle const &a, NormalizedAngle const &b)
Definition: NormalizedAngle.cc:45
Definition: NormalizedAngleInterval.h:57
bool isFull() const
isFull returns true if this interval contains all normalized angles.
Definition: NormalizedAngleInterval.h:129
bool isDisjointFrom(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:163
NormalizedAngleInterval()
This constructor creates an empty interval.
Definition: NormalizedAngleInterval.h:79
bool wraps() const
Definition: NormalizedAngleInterval.h:135
NormalizedAngleInterval clippedTo(NormalizedAngleInterval const &x) const
Definition: NormalizedAngleInterval.h:221
NormalizedAngleInterval & clipTo(NormalizedAngle x)
clipTo shrinks this interval until all its points are in x.
Definition: NormalizedAngleInterval.h:203
NormalizedAngleInterval(NormalizedAngle x, NormalizedAngle y)
This constructor creates an interval with the given endpoints.
Definition: NormalizedAngleInterval.h:99
NormalizedAngle getA() const
getA returns the first endpoint of this interval.
Definition: NormalizedAngleInterval.h:119
NormalizedAngle getCenter() const
Definition: NormalizedAngleInterval.h:139
bool operator==(NormalizedAngle x) const
A closed interval is equal to a point x if both endpoints equal x.
Definition: NormalizedAngleInterval.h:112
NormalizedAngleInterval(Angle const &x)
Definition: NormalizedAngleInterval.h:84
NormalizedAngleInterval dilatedBy(Angle x) const
Definition: NormalizedAngleInterval.cc:232
Relationship relate(NormalizedAngle x) const
Definition: NormalizedAngleInterval.cc:88
NormalizedAngleInterval expandedTo(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:237
NormalizedAngle getSize() const
Definition: NormalizedAngleInterval.h:145
NormalizedAngleInterval & expandTo(NormalizedAngle x)
Definition: NormalizedAngleInterval.cc:189
NormalizedAngle getB() const
getB returns the second endpoint of this interval.
Definition: NormalizedAngleInterval.h:122
bool intersects(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:173
bool operator==(NormalizedAngleInterval const &i) const
Two intervals are equal if they contain the same points.
Definition: NormalizedAngleInterval.h:103
NormalizedAngleInterval(NormalizedAngle const &x)
This constructor creates a closed interval containing only x.
Definition: NormalizedAngleInterval.h:87
bool isWithin(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:185
NormalizedAngleInterval clippedTo(NormalizedAngle x) const
clippedTo returns the intersection of this interval and x.
Definition: NormalizedAngleInterval.h:214
bool contains(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:150
bool isEmpty() const
Definition: NormalizedAngleInterval.h:126
This file provides a type alias for describing set relationships.