scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
latitude.cpp
Go to the documentation of this file.
1#include "./latitude.hpp"
2
3#include "../util/types.hpp"
4
5#include "boost/algorithm/string.hpp"
6#include "unicode/unistr.h"
7#include "unicode/uchar.h"
8
9#include <cmath>
10#include <iostream>
11#include <sstream>
12#include <string>
13
14using namespace std;
15
16namespace scifir
17{
20
22 {}
23
24 latitude::latitude(latitude&& x) : angle(std::move(x))
25 {}
26
32
38
40 {
43 }
44
50
55
57 {
59 {
60 value = float(x);
62 }
63 else
64 {
65 cerr << "A latitude cannot be initialized with dimensions" << endl;
66 value = 0.0f;
67 }
68 }
69
71 {
73 }
74
76 {
77 value = x.get_value();
78 return *this;
79 }
80
82 {
83 value = std::move(x.get_value());
84 return *this;
85 }
86
88 {
91 return *this;
92 }
93
95 {
97 return *this;
98 }
99
101 {
102 if (x.has_empty_dimensions())
103 {
104 value = x.get_value();
106 }
107 else
108 {
109 cerr << "A latitude cannot be initialized with dimensions" << endl;
110 }
111 return *this;
112 }
113
115 {
116 if (value > 0.0f)
117 {
118 return latitude::NORTH;
119 }
120 else if (value < 0.0f)
121 {
122 return latitude::SOUTH;
123 }
124 else if (value == 0.0f)
125 {
126 return latitude::CENTER;
127 }
128 return latitude::CENTER;
129 }
130
132 {
133 if (value > 0.0f)
134 {
135 value = -90.0f + std::abs(value);
136 }
137 else if (value < 0.0f)
138 {
139 value = 90.0f - std::abs(value);
140 }
141 }
142
144 {
145 if(isfinite(value))
146 {
147 if (value > 90.0f)
148 {
149 value = 0.0f;
150 }
151 else if (value < -90.0f)
152 {
153 value = 0.0f;
154 }
155 }
156 }
157
159 {
160 if (x >= 270.0f)
161 {
162 value = -90.0f + std::abs(x.get_value() - 270.0f);
163 }
164 else if (x <= 90.0f)
165 {
166 value = x.get_value();
167 }
168 else
169 {
170 value = 0.0f;
171 }
172 }
173
175 {
176 if (init_latitude.length() >= 3)
177 {
178 if (init_latitude.substr(init_latitude.length() - 1) == "N")
179 {
180 value = stof(init_latitude.substr(0,init_latitude.length() - 2));
182 return;
183 }
184 else if (init_latitude.substr(init_latitude.length() - 1) == "S")
185 {
186 value = -1.0f * stof(init_latitude.substr(0,init_latitude.length() - 2));
188 return;
189 }
190 }
191 icu::UnicodeString init_latitude_unicode = icu::UnicodeString(init_latitude.c_str());
192 if (init_latitude_unicode.endsWith(0x00B0) or init_latitude_unicode.endsWith(0x00BA))
193 {
196 }
197 }
198
199 bool is_latitude(const string& init_latitude)
200 {
201 if (init_latitude.length() == 0)
202 {
203 return false;
204 }
205 bool cardinale_point_present = false;
206 if (init_latitude.substr(init_latitude.length() - 1) == "N")
207 {
209 }
210 else if (init_latitude.substr(init_latitude.length() - 1) == "S")
211 {
213 }
214 int start_point = 0;
215 if (cardinale_point_present == false && init_latitude[0] == '-')
216 {
217 start_point++;
218 }
219 icu::UnicodeString x_unicode = icu::UnicodeString(init_latitude.c_str());
220 int total_chars = x_unicode.countChar32();
222 {
223 total_chars--;
224 }
225 bool loop = false;
226 if (x_unicode[total_chars - 1] == 0x00B0 || x_unicode[total_chars - 1] == 0x00BA)
227 {
228 loop = true;
229 }
230 if (loop == false)
231 {
232 return false;
233 }
234 bool dot_present = false;
235 for (int i = start_point; i < (total_chars - 1); i++)
236 {
237 if (x_unicode[i] == '.')
238 {
239 if (dot_present)
240 {
241 return false;
242 }
243 else
244 {
245 dot_present = true;
246 }
247 }
248 else if (!u_isdigit(x_unicode[i]))
249 {
250 return false;
251 }
252 }
253 return true;
254 }
255}
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition angle.hpp:77
const float & get_value() const
Gets the value of the angle, in degrees.
Definition angle.hpp:102
float value
Value of the angle. It is stored in degrees.
Definition angle.hpp:212
void initialize_from_angle(const angle &x)
Definition latitude.cpp:158
void normalize_value()
Definition latitude.cpp:143
void initialize_from_string(string init_latitude)
Definition latitude.cpp:174
latitude::position get_position() const
Definition latitude.cpp:114
latitude & operator=(const latitude &x)
Definition latitude.cpp:75
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
bool has_empty_dimensions() const
Checks if there aren't base dimensions.
const float & get_value() const
Read-only getter of the value.
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
bool is_latitude(const string &init_latitude)
Definition latitude.cpp:199