NumCpp  2.8.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 
30 #include <cmath>
31 #include <iostream>
32 #include <string>
33 
35 #include "NumCpp/Core/Types.hpp"
38 #include "NumCpp/Utils/num2str.hpp"
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)
82  noexcept :
83  hours_(inHours),
84  minutes_(inMinutes),
85  seconds_(inSeconds)
86  {
87  degrees_ = static_cast<double>(hours_) * 15.0 + static_cast<double>(minutes_) / 4.0 + seconds_ / 240.0;
88  radians_ = deg2rad(degrees_);
89  }
90 
91  //============================================================================
96  double radians() const noexcept
97  {
98  return radians_;
99  }
100 
101  //============================================================================
106  double degrees() const noexcept
107  {
108  return degrees_;
109  }
110 
111  //============================================================================
116  uint8 hours() const noexcept
117  {
118  return hours_;
119  }
120 
121  //============================================================================
126  uint8 minutes() const noexcept
127  {
128  return minutes_;
129  }
130 
131  //============================================================================
136  double seconds() const noexcept
137  {
138  return seconds_;
139  }
140 
141  //============================================================================
146  std::string str() const
147  {
148  std::string out =
149  "RA hms: " + utils::num2str(hours_) + " hours, " + utils::num2str(minutes_) + " minutes, ";
150  out += utils::num2str(seconds_) + " seconds\nRA degrees: " + utils::num2str(degrees_) + '\n';
151  return out;
152  }
153 
154  //============================================================================
157  void print() const
158  {
159  std::cout << *this;
160  }
161 
162  //============================================================================
169  bool operator==(const RA& inRhs) const noexcept
170  {
171  return utils::essentiallyEqual(degrees_, inRhs.degrees_);
172  }
173 
174  //============================================================================
181  bool operator!=(const RA& inRhs) const noexcept
182  {
183  return !(*this == inRhs);
184  }
185 
186  //============================================================================
192  friend std::ostream& operator<<(std::ostream& inStream, const RA& inRa)
193  {
194  inStream << inRa.str();
195  return inStream;
196  }
197 
198  private:
199  //====================================Attributes==============================
200  uint8 hours_{ 0 };
201  uint8 minutes_{ 0 };
202  double seconds_{ 0.0 };
203  double degrees_{ 0.0 };
204  double radians_{ 0.0 };
205  };
206  } // namespace coordinates
207 } // 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:157
std::string str() const
Definition: RA.hpp:146
uint8 hours() const noexcept
Definition: RA.hpp:116
uint8 minutes() const noexcept
Definition: RA.hpp:126
double radians() const noexcept
Definition: RA.hpp:96
friend std::ostream & operator<<(std::ostream &inStream, const RA &inRa)
Definition: RA.hpp:192
double degrees() const noexcept
Definition: RA.hpp:106
RA(double inDegrees)
Definition: RA.hpp:59
bool operator!=(const RA &inRhs) const noexcept
Definition: RA.hpp:181
bool operator==(const RA &inRhs) const noexcept
Definition: RA.hpp:169
double seconds() const noexcept
Definition: RA.hpp:136
std::string num2str(dtype inNumber)
Definition: num2str.hpp:46
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:51
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