LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
Circle.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_CIRCLE_H_
24 #define LSST_SPHGEOM_CIRCLE_H_
25 
29 
30 #include <iosfwd>
31 
32 #include "Region.h"
33 #include "UnitVector3d.h"
34 
35 
36 namespace lsst {
37 namespace sphgeom {
38 
46 class Circle : public Region {
47 public:
48  static constexpr uint8_t TYPE_CODE = 'c';
49 
50  static Circle empty() { return Circle(); }
51 
52  static Circle full() { return Circle(UnitVector3d::Z(), 4.0); }
53 
57  static double squaredChordLengthFor(Angle openingAngle);
58 
62  static Angle openingAngleFor(double squaredChordLength);
63 
65  Circle() :
66  _center(UnitVector3d::Z()),
67  _squaredChordLength(-1.0),
68  _openingAngle(-1.0)
69  {}
70 
76  explicit Circle(UnitVector3d const & c) :
77  _center(c),
78  _squaredChordLength(0.0),
79  _openingAngle(0.0)
80  {}
81 
85  Circle(UnitVector3d const & c, Angle a) :
86  _center(c),
87  _squaredChordLength(squaredChordLengthFor(a)),
88  _openingAngle(a)
89  {}
90 
94  Circle(UnitVector3d const & c, double cl2) :
95  _center(c),
96  _squaredChordLength(cl2),
97  _openingAngle(openingAngleFor(cl2))
98  {}
99 
100  bool operator==(Circle const & c) const {
101  return (isEmpty() && c.isEmpty()) ||
102  (isFull() && c.isFull()) ||
103  (_center == c._center &&
104  _squaredChordLength == c._squaredChordLength &&
105  _openingAngle == c._openingAngle);
106  }
107  bool operator!=(Circle const & c) const { return !(*this == c); }
108 
109  bool isEmpty() const {
110  // Return true when _squaredChordLength is negative or NaN.
111  return !(_squaredChordLength >= 0.0);
112  }
113 
114  bool isFull() const { return _squaredChordLength >= 4.0; }
115 
118  UnitVector3d const & getCenter() const { return _center; }
119 
123  double getSquaredChordLength() const { return _squaredChordLength; }
124 
128  Angle getOpeningAngle() const { return _openingAngle; }
129 
132  bool contains(Circle const & x) const;
133 
137  bool isDisjointFrom(UnitVector3d const & x) const { return !contains(x); }
138  bool isDisjointFrom(Circle const & x) const;
140 
144  bool intersects(UnitVector3d const & x) const { return contains(x); }
145  bool intersects(Circle const & x) const { return !isDisjointFrom(x); }
147 
151  bool isWithin(UnitVector3d const &) const { return isEmpty(); }
152  bool isWithin(Circle const & x) const { return x.contains(*this); }
154 
158  Circle & clipTo(UnitVector3d const & x);
159  Circle & clipTo(Circle const & x);
161 
165  Circle clippedTo(UnitVector3d const & x) const {
166  return Circle(*this).clipTo(x);
167  }
168 
169  Circle clippedTo(Circle const & x) const {
170  return Circle(*this).clipTo(x);
171  }
173 
176  Circle & expandTo(UnitVector3d const & x);
177  Circle & expandTo(Circle const & x);
179 
183  Circle expandedTo(UnitVector3d const & x) const {
184  return Circle(*this).expandTo(x);
185  }
186 
187  Circle expandedTo(Circle const & x) const {
188  return Circle(*this).expandTo(x);
189  }
191 
199  Circle & dilateBy(Angle r);
200  Circle dilatedBy(Angle r) const { return Circle(*this).dilateBy(r); }
201  Circle & erodeBy(Angle r) { return dilateBy(-r); }
202  Circle erodedBy(Angle r) const { return dilatedBy(-r); }
203 
205  double getArea() const {
206  return PI * std::max(0.0, std::min(_squaredChordLength, 4.0));
207  }
208 
214  Circle & complement();
215 
217  Circle complemented() const { return Circle(*this).complement(); }
218 
219  Relationship relate(UnitVector3d const & v) const;
220 
221  // Region interface
222  std::unique_ptr<Region> clone() const override {
223  return std::unique_ptr<Circle>(new Circle(*this));
224  }
225 
226  Box getBoundingBox() const override;
227  Box3d getBoundingBox3d() const override;
228  Circle getBoundingCircle() const override { return *this; }
229 
230  bool contains(UnitVector3d const & v) const override {
231  return isFull() ||
232  (v - _center).getSquaredNorm() <= _squaredChordLength;
233  }
234 
235  Relationship relate(Region const & r) const override {
236  // Dispatch on the type of r.
237  return invert(r.relate(*this));
238  }
239 
240  Relationship relate(Box const &) const override;
241  Relationship relate(Circle const &) const override;
242  Relationship relate(ConvexPolygon const &) const override;
243  Relationship relate(Ellipse const &) const override;
244 
245  std::vector<uint8_t> encode() const override;
246 
250  return decode(s.data(), s.size());
251  }
252  static std::unique_ptr<Circle> decode(uint8_t const * buffer, size_t n);
254 
255 private:
256  static constexpr size_t ENCODED_SIZE = 41;
257 
258  UnitVector3d _center;
259  double _squaredChordLength;
260  Angle _openingAngle;
261 };
262 
263 std::ostream & operator<<(std::ostream &, Circle const &);
264 
265 }} // namespace lsst::sphgeom
266 
267 #endif // LSST_SPHGEOM_CIRCLE_H_
double x
This file defines an interface for spherical regions.
table::Key< int > a
This file declares a class for representing unit vectors in ℝ³.
Angle represents an angle in radians.
Definition: Angle.h:43
Box3d represents a box in ℝ³.
Definition: Box3d.h:42
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition: Box.h:54
Circle is a circular region on the unit sphere that contains its boundary.
Definition: Circle.h:46
bool contains(Circle const &x) const
contains returns true if the intersection of this circle and x is equal to x.
Definition: Circle.cc:64
static Angle openingAngleFor(double squaredChordLength)
openingAngleFor computes and returns the angular separation between points in S² that are separated b...
Definition: Circle.cc:52
bool isEmpty() const
Definition: Circle.h:109
bool isWithin(Circle const &x) const
Definition: Circle.h:152
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition: Circle.cc:211
static Circle empty()
Definition: Circle.h:50
Circle clippedTo(UnitVector3d const &x) const
Definition: Circle.h:165
Circle & clipTo(UnitVector3d const &x)
Definition: Circle.cc:88
bool operator==(Circle const &c) const
Definition: Circle.h:100
bool operator!=(Circle const &c) const
Definition: Circle.h:107
double getArea() const
getArea returns the area of this circle in steradians.
Definition: Circle.h:205
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:184
static Circle full()
Definition: Circle.h:52
bool isWithin(UnitVector3d const &) const
Definition: Circle.h:151
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Circle.h:222
static std::unique_ptr< Circle > decode(std::vector< uint8_t > const &s)
Definition: Circle.h:249
Circle expandedTo(UnitVector3d const &x) const
Definition: Circle.h:183
Circle(UnitVector3d const &c, Angle a)
This constructor creates a circle with center c and opening angle a.
Definition: Circle.h:85
bool intersects(Circle const &x) const
Definition: Circle.h:145
bool isFull() const
Definition: Circle.h:114
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition: Circle.cc:324
Circle dilatedBy(Angle r) const
Definition: Circle.h:200
bool isDisjointFrom(UnitVector3d const &x) const
Definition: Circle.h:137
Circle(UnitVector3d const &c, double cl2)
This constructor creates a circle with center c and squared chord length cl2.
Definition: Circle.h:94
Circle(UnitVector3d const &c)
This constructor creates the circle with center c and squared chord length / opening angle of zero.
Definition: Circle.h:76
Relationship relate(UnitVector3d const &v) const
Definition: Circle.cc:268
double getSquaredChordLength() const
getSquaredChordLength returns the squared length of chords between the circle center and points on th...
Definition: Circle.h:123
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition: Circle.h:230
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition: Circle.h:118
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition: Circle.h:128
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition: Circle.cc:219
Circle clippedTo(Circle const &x) const
Definition: Circle.h:169
bool intersects(UnitVector3d const &x) const
Definition: Circle.h:144
Circle & erodeBy(Angle r)
Definition: Circle.h:201
Circle & complement()
complement sets this circle to the closure of its complement.
Definition: Circle.cc:194
Circle & expandTo(UnitVector3d const &x)
Definition: Circle.cc:120
Circle()
This constructor creates an empty circle.
Definition: Circle.h:65
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition: Circle.h:228
static double squaredChordLengthFor(Angle openingAngle)
squaredChordLengthFor computes and returns the squared chord length between points in S² that are sep...
Definition: Circle.cc:41
Circle expandedTo(Circle const &x) const
Definition: Circle.h:187
Circle complemented() const
complemented returns the closure of the complement of this circle.
Definition: Circle.h:217
static constexpr uint8_t TYPE_CODE
Definition: Circle.h:48
Relationship relate(Region const &r) const override
Definition: Circle.h:235
Circle erodedBy(Angle r) const
Definition: Circle.h:202
ConvexPolygon is a closed convex polygon on the unit sphere.
Definition: ConvexPolygon.h:57
Ellipse is an elliptical region on the sphere.
Definition: Ellipse.h:169
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition: Region.h:79
virtual Relationship relate(Region const &) const =0
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Definition: UnitVector3d.h:55
static UnitVector3d Z()
Definition: UnitVector3d.h:101
T data(T... args)
T max(T... args)
T min(T... args)
std::ostream & operator<<(std::ostream &, Angle const &)
Definition: Angle.cc:34
constexpr double PI
Definition: constants.h:36
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
A base class for image defects.
T size(T... args)