CppEphem
CEAngle.h
Go to the documentation of this file.
1 /***************************************************************************
2  * CEAngle.h: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2019 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef CEAngle_h
23 #define CEAngle_h
24 
25 #include <string>
26 #include <vector>
27 
28 #include "CENamespace.h"
29 
30 enum class CEAngleType
31 {
32  DEGREES=0,
33  RADIANS=1,
34  HMS=2,
35  DMS=3
36 };
37 
38 class CEAngle {
39 public:
40  // Constructors
41  CEAngle();
42  CEAngle(const double& angle);
43  explicit CEAngle(const CEAngle& other);
44  virtual ~CEAngle();
45 
46  // Copy-assignment operators
47  CEAngle& operator=(const CEAngle& other);
48  CEAngle& operator=(const double& other);
49 
50  // Make sure the angle object can be interpreted as a double
51  operator double();
52  operator double() const;
53 
54  static CEAngle Hms(const char* angle_str,
55  const char& delim=0);
56  static CEAngle Hms(const std::vector<double>& angle_vec);
57  static CEAngle Dms(const char* angle_str,
58  const char& delim=0);
59  static CEAngle Dms(const std::vector<double>& angle_vec);
60 
61  // Create from an angle value
62  static CEAngle Deg(const double& angle);
63  static CEAngle Rad(const double& angle);
64 
65  // Methods to return a formatted value for the angle
66  std::string HmsStr(const char& delim=':') const;
67  std::vector<double> HmsVect(void) const;
68  std::string DmsStr(const char& delim=':') const;
69  std::vector<double> DmsVect(void) const;
70  double Deg(void) const;
71  double Rad(void) const;
72 
73  // Generic methods for setting the angle
74  void SetAngle(const double& angle,
75  const CEAngleType& angle_type=CEAngleType::RADIANS);
76  void SetAngle(const char* angle_str,
77  const CEAngleType& angle_type,
78  const char& delim=0);
79  void SetAngle(const std::vector<double>& angle_vec,
80  const CEAngleType& angle_type);
81 
82 private:
83 
84  // Methods
85  void copy_members(const CEAngle& other);
86  void init_members(void);
87  void free_members(void);
88 
89  void SetAngle_HmsVect(const std::vector<double>& angle);
90  void SetAngle_DmsVect(const std::vector<double>& angle);
91 
92  // Variables
93  mutable double angle_;
94 
95 };
96 
97 #endif /* CEAngle_h */
CEAngle::Dms
static CEAngle Dms(const char *angle_str, const char &delim=0)
Return double constructed from a string representing degrees, minutes, seconds.
Definition: CEAngle.cpp:234
CEAngle::~CEAngle
virtual ~CEAngle()
Destructor.
Definition: CEAngle.cpp:73
CENamespace.h
CEAngle::DmsStr
std::string DmsStr(const char &delim=':') const
Return string representing the angle in DD:MM:SS.
Definition: CEAngle.cpp:270
CEAngle::DmsVect
std::vector< double > DmsVect(void) const
Return vector of doubles representing the {degrees, arcmin, arcsec, arcsec-fraction}.
Definition: CEAngle.cpp:291
CEAngleType
CEAngleType
Definition: CEAngle.h:30
CEAngle::free_members
void free_members(void)
Free allocated data members.
Definition: CEAngle.cpp:581
CEAngle::HmsVect
std::vector< double > HmsVect(void) const
Return vector of doubles representing the {hours, min, sec, sec-fraction}.
Definition: CEAngle.cpp:199
CEAngle
Definition: CEAngle.h:38
CEAngle::Rad
double Rad(void) const
Return angle in radians as a double.
Definition: CEAngle.cpp:351
CEAngle::SetAngle
void SetAngle(const double &angle, const CEAngleType &angle_type=CEAngleType::RADIANS)
Set the angle from a double.
Definition: CEAngle.cpp:369
CEAngle::SetAngle_DmsVect
void SetAngle_DmsVect(const std::vector< double > &angle)
Set the angle from a vector of doubles of the form {degrees, arcmin, arcsec}.
Definition: CEAngle.cpp:541
CEAngleType::DEGREES
CEAngle::copy_members
void copy_members(const CEAngle &other)
Copy data members from another CEAngle object.
Definition: CEAngle.cpp:593
CEAngle::angle_
double angle_
Angle stored in radians.
Definition: CEAngle.h:93
CEAngle::operator=
CEAngle & operator=(const CEAngle &other)
Copy assignment operator.
Definition: CEAngle.cpp:85
CEAngle::init_members
void init_members(void)
Initialize data members.
Definition: CEAngle.cpp:602
CEAngleType::RADIANS
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
CEAngle::Hms
static CEAngle Hms(const char *angle_str, const char &delim=0)
Return angle constructed from a string representing hours, minutes, seconds.
Definition: CEAngle.cpp:142
CEAngle::CEAngle
CEAngle()
Default constructor.
Definition: CEAngle.cpp:38
CEAngleType::DMS
CEAngleType::HMS
CEAngle::HmsStr
std::string HmsStr(const char &delim=':') const
Return string representing the angle in HH:MM:SS.
Definition: CEAngle.cpp:178
CEAngle::SetAngle_HmsVect
void SetAngle_HmsVect(const std::vector< double > &angle)
Set the angle from a vector of doubles representing {hours, minutes, seconds}.
Definition: CEAngle.cpp:496