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
Public Types | Public Member Functions | Private Member Functions | List of all members
scifir::latitude Class Reference

#include <latitude.hpp>

Inheritance diagram for scifir::latitude:
Inheritance graph
[legend]
Collaboration diagram for scifir::latitude:
Collaboration graph
[legend]

Public Types

enum  position : int8_t { NORTH , SOUTH , CENTER }
 
- Public Types inherited from scifir::angle
enum  type : int8_t { DEGREE , RADIAN , GRADIAN , TURN }
 Represents an type of angle, which can be a degree or a radian. The value of the angle inside the angle class is always stored in degrees, but can be get in radian if it's needed. More...
 

Public Member Functions

 latitude ()
 
 latitude (const latitude &x)
 
 latitude (latitude &&x)
 
 latitude (float new_value)
 
 latitude (double new_value)
 
 latitude (long double new_value)
 
 latitude (int new_value)
 
 latitude (const string &init_latitude)
 
 latitude (const scalar_unit &x)
 
 latitude (const angle &x)
 
latitudeoperator= (const latitude &x)
 
latitudeoperator= (latitude &&x)
 
latitudeoperator= (float new_value)
 
latitudeoperator= (const string &init_latitude)
 
latitudeoperator= (const scalar_unit &x)
 
latitude::position get_position () const
 
void invert ()
 
- Public Member Functions inherited from scifir::angle
 angle ()
 Default constructor of angle. The value is set to 0.
 
 angle (const angle &x)
 Copy constructor of angle. The value is copied from the angle x.
 
 angle (angle &&x)
 Move constructor of angle. The value is moved from the angle x.
 
 angle (float new_value, angle::type init_type=angle::DEGREE)
 Constructor of angle. The value is initialized to the float new_value. init_type is not stored as a member-variable, but instead allows to select if the value is given in DEGREE or in RADIAN. By default it's in DEGREE.
 
 angle (double new_value, angle::type init_type=angle::DEGREE)
 Constructor of angle. The value is initialized from the double new_value casted to a float. init_type is not stored as a member-variable, but instead allows to select if the value is given in DEGREE or in RADIAN. By default it's in DEGREE.
 
 angle (long double new_value, angle::type init_type=angle::DEGREE)
 Constructor of angle. The value is initialized from the long double new_value casted to a float. init_type is not stored as a member-variable, but instead allows to select if the value is given in DEGREE or in RADIAN. By default it's in DEGREE.
 
 angle (int new_value, angle::type init_type=angle::DEGREE)
 Constructor of angle. The value is initialized from the int new_value casted to a float. init_type is not stored as a member-variable, but instead allows to select if the value is given in DEGREE or in RADIAN. By default it's in DEGREE.
 
 angle (const string &init_angle)
 Constructor of angle. The value is initialized from the initialization string of angle, which uses the character 00B0 or the character 00BA to represent degrees.
 
 angle (const scalar_unit &x)
 Constructor of angle. The value is initialized from the scalar_unit x, if the scalar_unit has empty dimensions.
 
angleoperator= (const angle &x)
 Copy assignment of angle. The value is copied to the value of angle x.
 
angleoperator= (angle &&x)
 Move assignment of angle. The value is moved from the value of angle x.
 
angleoperator= (float new_value)
 Assignment operator. The value is copied from the float.
 
angleoperator= (const string &init_angle)
 Assignment operator. An initialization string is used to set the value, which contains the character 00B0 or the character 00BA to represent degrees.
 
angleoperator= (const scalar_unit &x)
 Assignment operator. The value of the angle is set to the value of the scalar_unit x, only if the scalar_unit has empty dimensions.
 
 operator float () const
 Cast angle to a float.
 
const floatget_value () const
 Gets the value of the angle, in degrees.
 
angle operator+ (const angle &x) const
 Creates a new angle as the sum of other two.
 
angle operator- (const angle &x) const
 Creates a new angle as the substraction of this angle and another angle x.
 
angle operator* (const angle &x) const
 Creates a new angle as the multiplication of other two.
 
angle operator/ (const angle &x) const
 Creates a new angle as the division of this angle and another angle x.
 
angle operator^ (const angle &x) const
 Creates a new angle by powering the angle class with the value of another angle x.
 
void operator+= (const angle &x)
 Sums the value of the angle x to the value of this angle. The value is normalized after.
 
void operator-= (const angle &x)
 Substract the value of the angle x to the value of this angle. The value is normalized after.
 
void operator*= (const angle &x)
 Multiplies the value of this angle with the value of angle x. The value is normalized after.
 
void operator/= (const angle &x)
 Divides the value of this angle with the value of angle x. The value is normalized after.
 
void operator^= (const angle &x)
 Powers the value of this angle with the value of angle x. The value is normalized after.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator= (T new_value)
 Sets the value to the value of some numeric type, casting it to a float first, and normalizing the value after that.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
angle operator+ (T x) const
 Creates a new angle as the sum of a numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
angle operator- (T x) const
 Creates a new angle as the substraction of the value of this angle with a numeric type.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
angle operator* (T x) const
 Creates a new angle as the multiplication of a numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
angle operator/ (T x) const
 Creates a new angle as the division of a numeric type with the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
angle operator^ (T x) const
 Creates a new angle as the power of the value of this angle with a numeric type.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator+= (T x)
 Sums a numeric type to the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator-= (T x)
 Substracts a numeric type to the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator*= (T x)
 Multiplies a numeric type to the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator/= (T x)
 Divides a numeric type to the value of this angle.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator^= (T x)
 Powers a numeric type to the value of this angle.
 
angleoperator++ ()
 Increments the value by one.
 
angle operator++ (int)
 Increments the value by one.
 
angleoperator-- ()
 Decrements the value by one.
 
angle operator-- (int)
 Decrements the value by one.
 
void invert ()
 Inverts the angle to the opposite direction in a 2D plane, which is to add 180 degrees. The value is normalized after.
 
scalar_unit to_scalar_unit () const
 Creates a scalar_unit with the same value and degree dimensions.
 
string display (int number_of_decimals=2) const
 Creates an string from the angle, with the value and the degrees symbol.
 
float get_degree () const
 Gets the value of the angle in degrees.
 
float get_radian () const
 Gets the value of the angle in radians.
 

Private Member Functions

void normalize_value ()
 
void initialize_from_angle (const angle &x)
 
void initialize_from_string (string init_latitude)
 

Additional Inherited Members

- Protected Member Functions inherited from scifir::angle
void initialize_from_string (string init_angle)
 Internal function. Sets the value of the angle to a new value using the initialization string of angles.
 
- Protected Attributes inherited from scifir::angle
float value
 Value of the angle. It is stored in degrees.
 

Detailed Description

Definition at line 16 of file latitude.hpp.

Member Enumeration Documentation

◆ position

Enumerator
NORTH 
SOUTH 
CENTER 

Definition at line 19 of file latitude.hpp.

Constructor & Destructor Documentation

◆ latitude() [1/10]

scifir::latitude::latitude ( )

Definition at line 18 of file latitude.cpp.

18 : angle()
19 {}
angle()
Default constructor of angle. The value is set to 0.
Definition angle.cpp:18

◆ latitude() [2/10]

scifir::latitude::latitude ( const latitude x)

Definition at line 21 of file latitude.cpp.

21 : angle(x)
22 {}

◆ latitude() [3/10]

scifir::latitude::latitude ( latitude &&  x)

Definition at line 24 of file latitude.cpp.

24 : angle(std::move(x))
25 {}

◆ latitude() [4/10]

scifir::latitude::latitude ( float  new_value)
explicit

Definition at line 27 of file latitude.cpp.

27 : angle()
28 {
29 value = new_value;
31 }
float value
Value of the angle. It is stored in degrees.
Definition angle.hpp:212
void normalize_value()
Definition latitude.cpp:143

◆ latitude() [5/10]

scifir::latitude::latitude ( double  new_value)
explicit

Definition at line 33 of file latitude.cpp.

33 : angle()
34 {
35 value = float(new_value);
37 }

◆ latitude() [6/10]

scifir::latitude::latitude ( long double  new_value)
explicit

Definition at line 39 of file latitude.cpp.

39 : angle()
40 {
41 value = float(new_value);
43 }

◆ latitude() [7/10]

scifir::latitude::latitude ( int  new_value)
explicit

Definition at line 45 of file latitude.cpp.

45 : angle()
46 {
47 value = float(new_value);
49 }

◆ latitude() [8/10]

scifir::latitude::latitude ( const string init_latitude)
explicit

Definition at line 51 of file latitude.cpp.

51 : angle()
52 {
53 initialize_from_string(init_latitude);
54 }
void initialize_from_string(string init_latitude)
Definition latitude.cpp:174

◆ latitude() [9/10]

scifir::latitude::latitude ( const scalar_unit x)
explicit

Definition at line 56 of file latitude.cpp.

56 : angle()
57 {
58 if (x.has_empty_dimensions())
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 }

◆ latitude() [10/10]

scifir::latitude::latitude ( const angle x)
explicit

Definition at line 70 of file latitude.cpp.

70 : angle()
71 {
73 }
void initialize_from_angle(const angle &x)
Definition latitude.cpp:158

Member Function Documentation

◆ get_position()

latitude::position scifir::latitude::get_position ( ) const

Definition at line 114 of file latitude.cpp.

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 }

◆ initialize_from_angle()

void scifir::latitude::initialize_from_angle ( const angle x)
private

Definition at line 158 of file latitude.cpp.

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 }

◆ initialize_from_string()

void scifir::latitude::initialize_from_string ( string  init_latitude)
private

Definition at line 174 of file latitude.cpp.

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 {
194 value = stof(init_latitude);
196 }
197 }

◆ invert()

void scifir::latitude::invert ( )

Definition at line 131 of file latitude.cpp.

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 }

◆ normalize_value()

void scifir::latitude::normalize_value ( )
private

Definition at line 143 of file latitude.cpp.

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 }

◆ operator=() [1/5]

latitude & scifir::latitude::operator= ( const latitude x)

Definition at line 75 of file latitude.cpp.

76 {
77 value = x.get_value();
78 return *this;
79 }

◆ operator=() [2/5]

latitude & scifir::latitude::operator= ( const scalar_unit x)

Definition at line 100 of file latitude.cpp.

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 }

◆ operator=() [3/5]

latitude & scifir::latitude::operator= ( const string init_latitude)

Definition at line 94 of file latitude.cpp.

95 {
96 initialize_from_string(init_latitude);
97 return *this;
98 }

◆ operator=() [4/5]

latitude & scifir::latitude::operator= ( float  new_value)

Definition at line 87 of file latitude.cpp.

88 {
89 value = new_value;
91 return *this;
92 }

◆ operator=() [5/5]

latitude & scifir::latitude::operator= ( latitude &&  x)

Definition at line 81 of file latitude.cpp.

82 {
83 value = std::move(x.get_value());
84 return *this;
85 }

The documentation for this class was generated from the following files: