LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
Circle.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_CIRCLE_H_
31#define LSST_SPHGEOM_CIRCLE_H_
32
36
37#include <iosfwd>
38
39#include "Region.h"
40#include "UnitVector3d.h"
41
42
43namespace lsst {
44namespace sphgeom {
45
53class Circle : public Region {
54public:
55 static constexpr uint8_t TYPE_CODE = 'c';
56
57 static Circle empty() { return Circle(); }
58
59 static Circle full() { return Circle(UnitVector3d::Z(), 4.0); }
60
64 static double squaredChordLengthFor(Angle openingAngle);
65
69 static Angle openingAngleFor(double squaredChordLength);
70
73 _center(UnitVector3d::Z()),
74 _squaredChordLength(-1.0),
75 _openingAngle(-1.0)
76 {}
77
83 explicit Circle(UnitVector3d const & c) :
84 _center(c),
85 _squaredChordLength(0.0),
86 _openingAngle(0.0)
87 {}
88
92 Circle(UnitVector3d const & c, Angle a) :
93 _center(c),
94 _squaredChordLength(squaredChordLengthFor(a)),
95 _openingAngle(a)
96 {}
97
101 Circle(UnitVector3d const & c, double cl2) :
102 _center(c),
103 _squaredChordLength(cl2),
104 _openingAngle(openingAngleFor(cl2))
105 {}
106
107 bool operator==(Circle const & c) const {
108 return (isEmpty() && c.isEmpty()) ||
109 (isFull() && c.isFull()) ||
110 (_center == c._center &&
111 _squaredChordLength == c._squaredChordLength &&
112 _openingAngle == c._openingAngle);
113 }
114 bool operator!=(Circle const & c) const { return !(*this == c); }
115
116 bool isEmpty() const {
117 // Return true when _squaredChordLength is negative or NaN.
118 return !(_squaredChordLength >= 0.0);
119 }
120
121 bool isFull() const { return _squaredChordLength >= 4.0; }
122
125 UnitVector3d const & getCenter() const { return _center; }
126
130 double getSquaredChordLength() const { return _squaredChordLength; }
131
135 Angle getOpeningAngle() const { return _openingAngle; }
136
139 bool contains(Circle const & x) const;
140
144 bool isDisjointFrom(UnitVector3d const & x) const { return !contains(x); }
145 bool isDisjointFrom(Circle const & x) const;
147
151 bool intersects(UnitVector3d const & x) const { return contains(x); }
152 bool intersects(Circle const & x) const { return !isDisjointFrom(x); }
154
158 bool isWithin(UnitVector3d const &) const { return isEmpty(); }
159 bool isWithin(Circle const & x) const { return x.contains(*this); }
161
165 Circle & clipTo(UnitVector3d const & x);
166 Circle & clipTo(Circle const & x);
168
173 return Circle(*this).clipTo(x);
174 }
175
176 Circle clippedTo(Circle const & x) const {
177 return Circle(*this).clipTo(x);
178 }
180
183 Circle & expandTo(UnitVector3d const & x);
184 Circle & expandTo(Circle const & x);
186
191 return Circle(*this).expandTo(x);
192 }
193
194 Circle expandedTo(Circle const & x) const {
195 return Circle(*this).expandTo(x);
196 }
198
206 Circle & dilateBy(Angle r);
207 Circle dilatedBy(Angle r) const { return Circle(*this).dilateBy(r); }
208 Circle & erodeBy(Angle r) { return dilateBy(-r); }
209 Circle erodedBy(Angle r) const { return dilatedBy(-r); }
210
212 double getArea() const {
213 return PI * std::max(0.0, std::min(_squaredChordLength, 4.0));
214 }
215
221 Circle & complement();
222
224 Circle complemented() const { return Circle(*this).complement(); }
225
226 Relationship relate(UnitVector3d const & v) const;
227
228 // Region interface
230 return std::unique_ptr<Circle>(new Circle(*this));
231 }
232
233 Box getBoundingBox() const override;
234 Box3d getBoundingBox3d() const override;
235 Circle getBoundingCircle() const override { return *this; }
236
237 bool contains(UnitVector3d const & v) const override {
238 return isFull() ||
239 (v - _center).getSquaredNorm() <= _squaredChordLength;
240 }
241
242 using Region::contains;
243
244 Relationship relate(Region const & r) const override {
245 // Dispatch on the type of r.
246 return invert(r.relate(*this));
247 }
248
249 Relationship relate(Box const &) const override;
250 Relationship relate(Circle const &) const override;
251 Relationship relate(ConvexPolygon const &) const override;
252 Relationship relate(Ellipse const &) const override;
253
254 std::vector<uint8_t> encode() const override;
255
259 return decode(s.data(), s.size());
260 }
261 static std::unique_ptr<Circle> decode(uint8_t const * buffer, size_t n);
263
264private:
265 static constexpr size_t ENCODED_SIZE = 41;
266
267 UnitVector3d _center;
268 double _squaredChordLength;
269 Angle _openingAngle;
270};
271
272std::ostream & operator<<(std::ostream &, Circle const &);
273
274}} // namespace lsst::sphgeom
275
276#endif // LSST_SPHGEOM_CIRCLE_H_
This file defines an interface for spherical regions.
This file declares a class for representing unit vectors in ℝ³.
Angle represents an angle in radians.
Definition Angle.h:50
Box3d represents a box in ℝ³.
Definition Box3d.h:49
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition Box.h:61
Circle is a circular region on the unit sphere that contains its boundary.
Definition Circle.h:53
bool contains(Circle const &x) const
contains returns true if the intersection of this circle and x is equal to x.
Definition Circle.cc:71
static Angle openingAngleFor(double squaredChordLength)
openingAngleFor computes and returns the angular separation between points in S² that are separated b...
Definition Circle.cc:59
bool isEmpty() const
Definition Circle.h:116
bool isWithin(Circle const &x) const
Definition Circle.h:159
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition Circle.cc:221
static Circle empty()
Definition Circle.h:57
Circle clippedTo(UnitVector3d const &x) const
Definition Circle.h:172
Circle & clipTo(UnitVector3d const &x)
Definition Circle.cc:98
bool operator==(Circle const &c) const
Definition Circle.h:107
bool operator!=(Circle const &c) const
Definition Circle.h:114
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition Circle.h:229
double getArea() const
getArea returns the area of this circle in steradians.
Definition Circle.h:212
Circle & dilateBy(Angle r)
If r is positive, dilateBy increases the opening angle of this circle to include all points within an...
Definition Circle.cc:194
static Circle full()
Definition Circle.h:59
bool isWithin(UnitVector3d const &) const
Definition Circle.h:158
static std::unique_ptr< Circle > decode(std::vector< uint8_t > const &s)
Definition Circle.h:258
Circle expandedTo(UnitVector3d const &x) const
Definition Circle.h:190
Circle(UnitVector3d const &c, Angle a)
This constructor creates a circle with center c and opening angle a.
Definition Circle.h:92
bool intersects(Circle const &x) const
Definition Circle.h:152
bool isFull() const
Definition Circle.h:121
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition Circle.cc:339
Circle dilatedBy(Angle r) const
Definition Circle.h:207
bool isDisjointFrom(UnitVector3d const &x) const
Definition Circle.h:144
Circle(UnitVector3d const &c, double cl2)
This constructor creates a circle with center c and squared chord length cl2.
Definition Circle.h:101
Circle(UnitVector3d const &c)
This constructor creates the circle with center c and squared chord length / opening angle of zero.
Definition Circle.h:83
Relationship relate(UnitVector3d const &v) const
Definition Circle.cc:278
Circle & erodeBy(Angle r)
Definition Circle.h:208
double getSquaredChordLength() const
getSquaredChordLength returns the squared length of chords between the circle center and points on th...
Definition Circle.h:130
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition Circle.h:237
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition Circle.h:135
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition Circle.h:125
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition Circle.cc:229
Circle clippedTo(Circle const &x) const
Definition Circle.h:176
bool intersects(UnitVector3d const &x) const
Definition Circle.h:151
Circle & complement()
complement sets this circle to the closure of its complement.
Definition Circle.cc:204
Circle & expandTo(UnitVector3d const &x)
Definition Circle.cc:130
Circle()
This constructor creates an empty circle.
Definition Circle.h:72
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition Circle.h:235
static double squaredChordLengthFor(Angle openingAngle)
squaredChordLengthFor computes and returns the squared chord length between points in S² that are sep...
Definition Circle.cc:48
Circle expandedTo(Circle const &x) const
Definition Circle.h:194
Circle complemented() const
complemented returns the closure of the complement of this circle.
Definition Circle.h:224
static constexpr uint8_t TYPE_CODE
Definition Circle.h:55
Relationship relate(Region const &r) const override
Definition Circle.h:244
Circle erodedBy(Angle r) const
Definition Circle.h:209
ConvexPolygon is a closed convex polygon on the unit sphere.
Ellipse is an elliptical region on the sphere.
Definition Ellipse.h:177
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:86
virtual Relationship relate(Region const &) const =0
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
static UnitVector3d Z()
T max(T... args)
T min(T... args)
std::ostream & operator<<(std::ostream &, Angle const &)
Definition Angle.cc:41
constexpr double PI
Definition constants.h:43
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.