lsst.afw  14.0-22-gc76603d1b
SpherePoint.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * See COPYRIGHT file at the top of the source tree.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_GEOM_SPHEREPOINT_H_
26 #define LSST_AFW_GEOM_SPHEREPOINT_H_
27 
28 #include <ostream>
29 #include <utility>
30 
31 #include "lsst/afw/geom/Angle.h"
32 #include "lsst/afw/geom/Point.h"
33 
34 namespace lsst {
35 namespace afw {
36 namespace geom {
37 
60 class SpherePoint final {
61 public:
74  SpherePoint(Angle const& longitude, Angle const& latitude);
75 
89  SpherePoint(double longitude, double latitude, AngleUnit units);
90 
103  explicit SpherePoint(Point3D const& vector);
104 
112  SpherePoint(SpherePoint const& other) noexcept;
113 
120  SpherePoint(SpherePoint&& other) noexcept;
121 
134  SpherePoint& operator=(SpherePoint const& other) noexcept;
135 
142  SpherePoint& operator=(SpherePoint&& other) noexcept;
143 
144  /*
145  * Accessors
146  */
147 
160  Angle getLongitude() const noexcept { return _longitude * radians; };
161 
169  Angle getLatitude() const noexcept { return _latitude * radians; };
170 
178  Point3D getVector() const noexcept;
179 
194  Angle operator[](size_t index) const;
195 
204  bool atPole() const noexcept {
205  // Unit tests indicate we don't need to worry about epsilon-errors
206  // Objects constructed from lat=90*degrees, <0,0,1>, etc. all have
207  // atPole() = true. More complex operations like bearingTo have also
208  // been tested near the poles with no ill effects
209  return fabs(_latitude) >= HALFPI;
210  }
211 
221  bool isFinite() const noexcept;
222 
223  /*
224  * Comparisons between points
225  */
226 
246  bool operator==(SpherePoint const& other) const noexcept;
247 
254  bool operator!=(SpherePoint const& other) const noexcept;
255 
276  Angle bearingTo(SpherePoint const& other) const;
277 
287  Angle separation(SpherePoint const& other) const noexcept;
288 
289  /*
290  * Transformations of points
291  */
292 
303  SpherePoint rotated(SpherePoint const& axis, Angle const& amount) const noexcept;
304 
325  SpherePoint offset(Angle const& bearing, Angle const& amount) const;
326 
327 private:
328  // For compatibility with Starlink AST, the implementation must be a
329  // pair of floating-point numbers, with no other data. Do not change
330  // the implementation without an RFC.
331  double _longitude; // radians
332  double _latitude; // radians
333 };
334 
335 /*
336  * Object-level display
337  */
338 
359 std::ostream& operator<<(std::ostream& os, SpherePoint const& point);
360 }
361 }
362 } /* namespace lsst::afw::geom */
363 
364 #endif /* LSST_AFW_GEOM_SPHEREPOINT_H_ */
SpherePoint offset(Angle const &bearing, Angle const &amount) const
Return a point offset from this one along a great circle.
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:60
bool operator!=(SpherePoint const &other) const noexcept
false if two points represent the same position.
Angle separation(SpherePoint const &other) const noexcept
Angular distance between two points.
std::ostream & operator<<(std::ostream &os, SpherePoint const &point)
Print the value of a point to a stream.
double constexpr HALFPI
Definition: Angle.h:23
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
Angle getLongitude() const noexcept
The longitude of this point.
Definition: SpherePoint.h:160
SpherePoint(Angle const &longitude, Angle const &latitude)
Construct a SpherePoint from a longitude and latitude.
Angle operator[](size_t index) const
Longitude and latitude by index.
table::Key< geom::Angle > latitude
Definition: VisitInfo.cc:165
bool isFinite() const noexcept
true if this point is a well-defined position.
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
A coordinate class intended to represent absolute positions.
A class representing an angle.
Definition: Angle.h:102
A base class for image defects.
table::Key< geom::Angle > longitude
Definition: VisitInfo.cc:166
SpherePoint & operator=(SpherePoint const &other) noexcept
Overwrite this object with the value of another SpherePoint.
SpherePoint rotated(SpherePoint const &axis, Angle const &amount) const noexcept
Return a point rotated from this one around an axis.
Angle bearingTo(SpherePoint const &other) const
Direction from one point to another.
Angle getLatitude() const noexcept
The latitude of this point.
Definition: SpherePoint.h:169
bool operator==(SpherePoint const &other) const noexcept
true if two points represent the same position.
bool atPole() const noexcept
true if this point is either coordinate pole.
Definition: SpherePoint.h:204
Point3D getVector() const noexcept
A unit vector representation of this point.
STL class.