NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
RA.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/Utils/num2str.hpp"
35 
36 #include <cmath>
37 #include <iostream>
38 #include <string>
39 
40 namespace nc
41 {
42  namespace coordinates
43  {
44  //================================================================================
46  class RA
47  {
48  public:
49  //============================================================================
52  RA() = default;
53 
54  //============================================================================
59  explicit RA(double inDegrees) :
60  degrees_(inDegrees),
61  radians_(deg2rad(inDegrees))
62  {
63  if (inDegrees < 0 || inDegrees >= 360)
64  {
65  THROW_INVALID_ARGUMENT_ERROR("input degrees must be of the range [0, 360)");
66  }
67 
68  hours_ = static_cast<uint8>(std::floor(degrees_ / 15.0));
69  const double decMinutes = (degrees_ - static_cast<double>(hours_) * 15.0) * 4.0;
70  minutes_ = static_cast<uint8>(std::floor(decMinutes));
71  seconds_ = static_cast<double>((decMinutes - static_cast<double>(minutes_)) * 60.0);
72  }
73 
74  //============================================================================
81  RA(uint8 inHours, uint8 inMinutes, double inSeconds) noexcept :
82  hours_(inHours),
83  minutes_(inMinutes),
84  seconds_(inSeconds)
85  {
86  degrees_ = static_cast<double>(hours_) * 15.0 + static_cast<double>(minutes_) / 4.0 + seconds_ / 240.0;
87  radians_ = deg2rad(degrees_);
88  }
89 
90  //============================================================================
95  double radians() const noexcept
96  {
97  return radians_;
98  }
99 
100  //============================================================================
105  double degrees() const noexcept
106  {
107  return degrees_;
108  }
109 
110  //============================================================================
115  uint8 hours() const noexcept
116  {
117  return hours_;
118  }
119 
120  //============================================================================
125  uint8 minutes() const noexcept
126  {
127  return minutes_;
128  }
129 
130  //============================================================================
135  double seconds() const noexcept
136  {
137  return seconds_;
138  }
139 
140  //============================================================================
145  std::string str() const
146  {
147  std::string out = "RA hms: " + utils::num2str(hours_) + " hours, " + utils::num2str(minutes_) + " minutes, ";
148  out += utils::num2str(seconds_) + " seconds\nRA degrees: " + utils::num2str(degrees_) + '\n';
149  return out;
150  }
151 
152  //============================================================================
155  void print() const
156  {
157  std::cout << *this;
158  }
159 
160  //============================================================================
167  bool operator==(const RA& inRhs) const noexcept
168  {
169  return utils::essentiallyEqual(degrees_, inRhs.degrees_);
170  }
171 
172  //============================================================================
179  bool operator!=(const RA& inRhs) const noexcept
180  {
181  return !(*this == inRhs);
182  }
183 
184  //============================================================================
190  friend std::ostream& operator<<(std::ostream& inStream, const RA& inRa)
191  {
192  inStream << inRa.str();
193  return inStream;
194  }
195 
196  private:
197  //====================================Attributes==============================
198  uint8 hours_{ 0 };
199  uint8 minutes_{ 0 };
200  double seconds_{ 0.0 };
201  double degrees_{ 0.0 };
202  double radians_{ 0.0 };
203  };
204  } // namespace coordinates
205 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds a right ascension object.
Definition: RA.hpp:47
void print() const
Definition: RA.hpp:155
std::string str() const
Definition: RA.hpp:145
uint8 hours() const noexcept
Definition: RA.hpp:115
RA(uint8 inHours, uint8 inMinutes, double inSeconds) noexcept
Definition: RA.hpp:81
uint8 minutes() const noexcept
Definition: RA.hpp:125
double radians() const noexcept
Definition: RA.hpp:95
friend std::ostream & operator<<(std::ostream &inStream, const RA &inRa)
Definition: RA.hpp:190
double degrees() const noexcept
Definition: RA.hpp:105
RA(double inDegrees)
Definition: RA.hpp:59
bool operator!=(const RA &inRhs) const noexcept
Definition: RA.hpp:179
bool operator==(const RA &inRhs) const noexcept
Definition: RA.hpp:167
double seconds() const noexcept
Definition: RA.hpp:135
std::string num2str(dtype inNumber)
Definition: num2str.hpp:46
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
Definition: Coordinate.hpp:45
constexpr auto deg2rad(dtype inValue) noexcept
Definition: deg2rad.hpp:47
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:48
std::uint8_t uint8
Definition: Types.hpp:42