LSST Applications 24.1.6,g063fba187b+e7121a6b04,g0f08755f38+4e0faf0f7f,g12f32b3c4e+7915c4de30,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+94d9f37a33,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+9e154f3e8d,g6b1c1869cb+adc49b6f1a,g781aacb6e4+a8ce1bb630,g7af13505b9+3363a39af3,g7f202ee025+406ba613a5,g80478fca09+8fbba356e2,g82479be7b0+0d223595df,g858d7b2824+4e0faf0f7f,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+32d6120315,gacef1a1666+7f85da65db,gb58c049af0+d64f4d3760,gbcfae0f0a0+a8c62e8bb6,gc28159a63d+ae03bbfc84,gcf0d15dbbd+412a8a6f35,gda6a2b7d83+412a8a6f35,gdaeeff99f8+1711a396fd,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+4e0faf0f7f,gfa999e8aa5+17cd334064,gfb92a5be7c+4e0faf0f7f
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#include <cstdint>
39
40#include "Region.h"
41#include "UnitVector3d.h"
42
43
44namespace lsst {
45namespace sphgeom {
46
54class Circle : public Region {
55public:
56 static constexpr std::uint8_t TYPE_CODE = 'c';
57
58 static Circle empty() { return Circle(); }
59
60 static Circle full() { return Circle(UnitVector3d::Z(), 4.0); }
61
65 static double squaredChordLengthFor(Angle openingAngle);
66
70 static Angle openingAngleFor(double squaredChordLength);
71
74 _center(UnitVector3d::Z()),
75 _squaredChordLength(-1.0),
76 _openingAngle(-1.0)
77 {}
78
84 explicit Circle(UnitVector3d const & c) :
85 _center(c),
86 _squaredChordLength(0.0),
87 _openingAngle(0.0)
88 {}
89
93 Circle(UnitVector3d const & c, Angle a) :
94 _center(c),
95 _squaredChordLength(squaredChordLengthFor(a)),
96 _openingAngle(a)
97 {}
98
102 Circle(UnitVector3d const & c, double cl2) :
103 _center(c),
104 _squaredChordLength(cl2),
105 _openingAngle(openingAngleFor(cl2))
106 {}
107
108 bool operator==(Circle const & c) const {
109 return (isEmpty() && c.isEmpty()) ||
110 (isFull() && c.isFull()) ||
111 (_center == c._center &&
112 _squaredChordLength == c._squaredChordLength &&
113 _openingAngle == c._openingAngle);
114 }
115 bool operator!=(Circle const & c) const { return !(*this == c); }
116
117 bool isEmpty() const {
118 // Return true when _squaredChordLength is negative or NaN.
119 return !(_squaredChordLength >= 0.0);
120 }
121
122 bool isFull() const { return _squaredChordLength >= 4.0; }
123
126 UnitVector3d const & getCenter() const { return _center; }
127
131 double getSquaredChordLength() const { return _squaredChordLength; }
132
136 Angle getOpeningAngle() const { return _openingAngle; }
137
140 bool contains(Circle const & x) const;
141
145 bool isDisjointFrom(UnitVector3d const & x) const { return !contains(x); }
146 bool isDisjointFrom(Circle const & x) const;
148
152 bool intersects(UnitVector3d const & x) const { return contains(x); }
153 bool intersects(Circle const & x) const { return !isDisjointFrom(x); }
155
159 bool isWithin(UnitVector3d const &) const { return isEmpty(); }
160 bool isWithin(Circle const & x) const { return x.contains(*this); }
162
166 Circle & clipTo(UnitVector3d const & x);
167 Circle & clipTo(Circle const & x);
169
174 return Circle(*this).clipTo(x);
175 }
176
177 Circle clippedTo(Circle const & x) const {
178 return Circle(*this).clipTo(x);
179 }
181
184 Circle & expandTo(UnitVector3d const & x);
185 Circle & expandTo(Circle const & x);
187
192 return Circle(*this).expandTo(x);
193 }
194
195 Circle expandedTo(Circle const & x) const {
196 return Circle(*this).expandTo(x);
197 }
199
207 Circle & dilateBy(Angle r);
208 Circle dilatedBy(Angle r) const { return Circle(*this).dilateBy(r); }
209 Circle & erodeBy(Angle r) { return dilateBy(-r); }
210 Circle erodedBy(Angle r) const { return dilatedBy(-r); }
211
213 double getArea() const {
214 return PI * std::max(0.0, std::min(_squaredChordLength, 4.0));
215 }
216
222 Circle & complement();
223
225 Circle complemented() const { return Circle(*this).complement(); }
226
227 Relationship relate(UnitVector3d const & v) const;
228
229 // Region interface
231 return std::unique_ptr<Circle>(new Circle(*this));
232 }
233
234 Box getBoundingBox() const override;
235 Box3d getBoundingBox3d() const override;
236 Circle getBoundingCircle() const override { return *this; }
237
238 bool contains(UnitVector3d const & v) const override {
239 return isFull() ||
240 (v - _center).getSquaredNorm() <= _squaredChordLength;
241 }
242
243 using Region::contains;
244
245 Relationship relate(Region const & r) const override {
246 // Dispatch on the type of r.
247 return invert(r.relate(*this));
248 }
249
250 Relationship relate(Box const &) const override;
251 Relationship relate(Circle const &) const override;
252 Relationship relate(ConvexPolygon const &) const override;
253 Relationship relate(Ellipse const &) const override;
254
255 std::vector<std::uint8_t> encode() const override;
256
260 return decode(s.data(), s.size());
261 }
262 static std::unique_ptr<Circle> decode(std::uint8_t const * buffer, size_t n);
264
265private:
266 static constexpr size_t ENCODED_SIZE = 41;
267
268 UnitVector3d _center;
269 double _squaredChordLength;
270 Angle _openingAngle;
271};
272
273std::ostream & operator<<(std::ostream &, Circle const &);
274
275}} // namespace lsst::sphgeom
276
277#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:62
Circle is a circular region on the unit sphere that contains its boundary.
Definition Circle.h:54
static constexpr std::uint8_t TYPE_CODE
Definition Circle.h:56
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:117
bool isWithin(Circle const &x) const
Definition Circle.h:160
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition Circle.cc:221
static Circle empty()
Definition Circle.h:58
Circle clippedTo(UnitVector3d const &x) const
Definition Circle.h:173
Circle & clipTo(UnitVector3d const &x)
Definition Circle.cc:98
bool operator==(Circle const &c) const
Definition Circle.h:108
bool operator!=(Circle const &c) const
Definition Circle.h:115
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition Circle.h:230
double getArea() const
getArea returns the area of this circle in steradians.
Definition Circle.h:213
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:60
bool isWithin(UnitVector3d const &) const
Definition Circle.h:159
Circle expandedTo(UnitVector3d const &x) const
Definition Circle.h:191
Circle(UnitVector3d const &c, Angle a)
This constructor creates a circle with center c and opening angle a.
Definition Circle.h:93
bool intersects(Circle const &x) const
Definition Circle.h:153
bool isFull() const
Definition Circle.h:122
Circle dilatedBy(Angle r) const
Definition Circle.h:208
bool isDisjointFrom(UnitVector3d const &x) const
Definition Circle.h:145
std::vector< std::uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition Circle.cc:339
Circle(UnitVector3d const &c, double cl2)
This constructor creates a circle with center c and squared chord length cl2.
Definition Circle.h:102
Circle(UnitVector3d const &c)
This constructor creates the circle with center c and squared chord length / opening angle of zero.
Definition Circle.h:84
static std::unique_ptr< Circle > decode(std::vector< std::uint8_t > const &s)
Definition Circle.h:259
Relationship relate(UnitVector3d const &v) const
Definition Circle.cc:278
Circle & erodeBy(Angle r)
Definition Circle.h:209
double getSquaredChordLength() const
getSquaredChordLength returns the squared length of chords between the circle center and points on th...
Definition Circle.h:131
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition Circle.h:238
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition Circle.h:136
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition Circle.h:126
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:177
bool intersects(UnitVector3d const &x) const
Definition Circle.h:152
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:73
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition Circle.h:236
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:195
Circle complemented() const
complemented returns the closure of the complement of this circle.
Definition Circle.h:225
Relationship relate(Region const &r) const override
Definition Circle.h:245
Circle erodedBy(Angle r) const
Definition Circle.h:210
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:87
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.