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::longitude Class Reference

#include <longitude.hpp>

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

Public Types

enum  position : int8_t { EAST , WEST , 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

 longitude ()
 
 longitude (const longitude &x)
 
 longitude (longitude &&x)
 
 longitude (float new_value)
 
 longitude (double new_value)
 
 longitude (long double new_value)
 
 longitude (int new_value)
 
 longitude (const string &init_longitude)
 
 longitude (const scalar_unit &x)
 
 longitude (const angle &x)
 
longitudeoperator= (const longitude &x)
 
longitudeoperator= (longitude &&x)
 
longitudeoperator= (float new_value)
 
longitudeoperator= (const string &init_longitude)
 
longitudeoperator= (const scalar_unit &x)
 
longitude::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_longitude)
 

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 longitude.hpp.

Member Enumeration Documentation

◆ position

Enumerator
EAST 
WEST 
CENTER 

Definition at line 19 of file longitude.hpp.

Constructor & Destructor Documentation

◆ longitude() [1/10]

scifir::longitude::longitude ( )

Definition at line 18 of file longitude.cpp.

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

◆ longitude() [2/10]

scifir::longitude::longitude ( const longitude x)

Definition at line 21 of file longitude.cpp.

21 : angle(x.get_value())
22 {}

◆ longitude() [3/10]

scifir::longitude::longitude ( longitude &&  x)

Definition at line 24 of file longitude.cpp.

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

◆ longitude() [4/10]

scifir::longitude::longitude ( float  new_value)
explicit

Definition at line 27 of file longitude.cpp.

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

◆ longitude() [5/10]

scifir::longitude::longitude ( double  new_value)
explicit

Definition at line 33 of file longitude.cpp.

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

◆ longitude() [6/10]

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

Definition at line 39 of file longitude.cpp.

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

◆ longitude() [7/10]

scifir::longitude::longitude ( int  new_value)
explicit

Definition at line 45 of file longitude.cpp.

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

◆ longitude() [8/10]

scifir::longitude::longitude ( const string init_longitude)
explicit

Definition at line 51 of file longitude.cpp.

51 : angle()
52 {
53 initialize_from_string(init_longitude);
54 }
void initialize_from_string(string init_longitude)

◆ longitude() [9/10]

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

Definition at line 56 of file longitude.cpp.

57 {
58 if (x.has_empty_dimensions())
59 {
60 value = float(x);
62 }
63 else
64 {
65 cerr << "A longitude cannot be initialized with dimensions" << endl;
66 value = 0.0f;
67 }
68 }

◆ longitude() [10/10]

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

Definition at line 70 of file longitude.cpp.

71 {
73 }
void initialize_from_angle(const angle &x)

Member Function Documentation

◆ get_position()

longitude::position scifir::longitude::get_position ( ) const

Definition at line 114 of file longitude.cpp.

115 {
116 if (value > 0.0f)
117 {
118 return longitude::EAST;
119 }
120 else if (value < 0.0f)
121 {
122 return longitude::WEST;
123 }
124 else if (value == 0.0f)
125 {
126 return longitude::CENTER;
127 }
128 return longitude::CENTER;
129 }

◆ initialize_from_angle()

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

Definition at line 158 of file longitude.cpp.

159 {
160 if (x > 180.0f)
161 {
162 value = -180.0f + std::abs(x.get_value() - 180.0f);
163 }
164 else if (x <= 180.0f)
165 {
166 value = x.get_value();
167 }
168 }

◆ initialize_from_string()

void scifir::longitude::initialize_from_string ( string  init_longitude)
private

Definition at line 170 of file longitude.cpp.

171 {
172 if (init_longitude.length() >= 3)
173 {
174 if (init_longitude.substr(init_longitude.length() - 1) == "E")
175 {
176 value = stof(init_longitude.substr(0,init_longitude.length() - 2));
178 return;
179 }
180 else if (init_longitude.substr(init_longitude.length() - 1) == "W")
181 {
182 value = -1.0f * stof(init_longitude.substr(0,init_longitude.length() - 2));
184 return;
185 }
186 }
187 icu::UnicodeString init_longitude_unicode = icu::UnicodeString(init_longitude.c_str());
188 if (init_longitude_unicode.endsWith(0x00B0) or init_longitude_unicode.endsWith(0x00BA))
189 {
190 value = stof(init_longitude);
192 }
193 }

◆ invert()

void scifir::longitude::invert ( )

Definition at line 131 of file longitude.cpp.

132 {
133 if (value > 0.0f)
134 {
135 value = -180.0f + std::abs(value);
136 }
137 else if (value < 0.0f)
138 {
139 value = 180.0f - std::abs(value);
140 }
141 }

◆ normalize_value()

void scifir::longitude::normalize_value ( )
private

Definition at line 143 of file longitude.cpp.

144 {
145 if(isfinite(value))
146 {
147 if (value > 180.0f)
148 {
149 value = 0.0f;
150 }
151 else if (value < -180.0f)
152 {
153 value = 0.0f;
154 }
155 }
156 }

◆ operator=() [1/5]

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

Definition at line 75 of file longitude.cpp.

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

◆ operator=() [2/5]

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

Definition at line 100 of file longitude.cpp.

101 {
102 if (x.has_empty_dimensions())
103 {
104 value = x.get_value();
106 }
107 else
108 {
109 cerr << "A longitude cannot be initialized with dimensions" << endl;
110 }
111 return *this;
112 }

◆ operator=() [3/5]

longitude & scifir::longitude::operator= ( const string init_longitude)

Definition at line 94 of file longitude.cpp.

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

◆ operator=() [4/5]

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

Definition at line 87 of file longitude.cpp.

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

◆ operator=() [5/5]

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

Definition at line 81 of file longitude.cpp.

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

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