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

Specialization class of size_2d<T> that allows to store and calculate size in 2D, with width and height as float types. Initialization string example: "1 * 2". More...

#include <size_2d.hpp>

Public Member Functions

 size_2d ()
 Default constructor. Initializes width and height to 0.
 
 size_2d (const size_2d< float > &x)
 Copy constructor. The width and height are copied from the size_2d<float> x.
 
 size_2d (size_2d< float > &&x)
 Move constructor. The width and height are moved from the size_2d<float> x.
 
 size_2d (const float &new_width, const float &new_height)
 Constructor. width is new_width and height is new_height.
 
 size_2d (const string &new_width, const string &new_height)
 Constructor. width is new_width and height is new_height, they are initialized by string.
 
 size_2d (const string &init_size_2d)
 Constructor. The member-variables are initialized by the initialization string init_size_2d specialized for float.
 
size_2d< float > & operator= (const size_2d< float > &x)
 Copy assignment. The width and height are copied from the size_2d<float> x.
 
size_2d< float > & operator= (size_2d< float > &&x)
 Move assignment. The width and height are moved from the size_2d<float> x.
 
size_2d< float > & operator= (const string &init_size_2d)
 Assignment. The member-variables are initialized by the initialization string init_size_2d specialized for float.
 
size_2d< floatoperator+ (const size_2d< float > &x) const
 Creates a new size_2d<float> by the addition of two size_2d<float> classes. The width is the result of the addition of the two width of the size_2d<float> classes and the height the result of the addition of the two height of the size_2d<float> classes.
 
size_2d< floatoperator- (const size_2d< float > &x) const
 Creates a new size_2d<float> by the difference of two size_2d<float> classes. The width is the result of the difference of the two width of the size_2d<float> classes and the height the result of the difference of the two height of the size_2d<float> classes.
 
void operator+= (const size_2d< float > &x)
 Sums the width of size_2d<float> x to the width and sums the height of size_2d<float> x to the height.
 
void operator-= (const size_2d< float > &x)
 Substracts the width of size_2d<float> x to the width and substracts the height of size_2d<float> x to the height.
 
float get_area () const
 Calculates the area as the multiplication of the width and height.
 
string display () const
 Returns a string representation of size_2d<float>, with his width and height.
 

Public Attributes

float width
 Width, stored as a float. The advantage related to size_2d<float> over size_2d<T> is that it sizes less, the disadvantage is the lack of dimensions.
 
float height
 Height, stored as a float. The advantage related to size_2d<float> over size_2d<T> is that it sizes less, the disadvantage is the lack of dimensions.
 

Private Member Functions

void initialize_from_string (const string &init_size_2d)
 Internal function. Initializes the member-variables with an initialization string of size_2d<float>.
 

Detailed Description

Specialization class of size_2d<T> that allows to store and calculate size in 2D, with width and height as float types. Initialization string example: "1 * 2".

Definition at line 116 of file size_2d.hpp.

Constructor & Destructor Documentation

◆ size_2d() [1/6]

scifir::size_2d< float >::size_2d ( )
inline

Default constructor. Initializes width and height to 0.

Definition at line 119 of file size_2d.hpp.

119 : width(),height()
120 {}
float width
Width, stored as a float. The advantage related to size_2d<float> over size_2d<T> is that it sizes le...
Definition size_2d.hpp:193
float height
Height, stored as a float. The advantage related to size_2d<float> over size_2d<T> is that it sizes l...
Definition size_2d.hpp:194

◆ size_2d() [2/6]

scifir::size_2d< float >::size_2d ( const size_2d< float > &  x)
inline

Copy constructor. The width and height are copied from the size_2d<float> x.

Definition at line 122 of file size_2d.hpp.

122 : width(x.width),height(x.height)
123 {}

◆ size_2d() [3/6]

scifir::size_2d< float >::size_2d ( size_2d< float > &&  x)
inline

Move constructor. The width and height are moved from the size_2d<float> x.

Definition at line 125 of file size_2d.hpp.

125 : width(std::move(x.width)),height(std::move(x.height))
126 {}

◆ size_2d() [4/6]

scifir::size_2d< float >::size_2d ( const float new_width,
const float new_height 
)
inlineexplicit

Constructor. width is new_width and height is new_height.

Definition at line 128 of file size_2d.hpp.

128 : width(new_width),height(new_height)
129 {}

◆ size_2d() [5/6]

scifir::size_2d< float >::size_2d ( const string new_width,
const string new_height 
)
inlineexplicit

Constructor. width is new_width and height is new_height, they are initialized by string.

Definition at line 131 of file size_2d.hpp.

131 : width(stof(new_width)),height(stof(new_height))
132 {}

◆ size_2d() [6/6]

scifir::size_2d< float >::size_2d ( const string init_size_2d)
inlineexplicit

Constructor. The member-variables are initialized by the initialization string init_size_2d specialized for float.

Definition at line 134 of file size_2d.hpp.

134 : size_2d()
135 {
136 initialize_from_string(init_size_2d);
137 }
void initialize_from_string(const string &init_size_2d)
Internal function. Initializes the member-variables with an initialization string of size_2d<float>.
Definition size_2d.hpp:197
size_2d()
Default constructor. Initializes width and height to 0.
Definition size_2d.hpp:119

Member Function Documentation

◆ display()

string scifir::size_2d< float >::display ( ) const
inline

Returns a string representation of size_2d<float>, with his width and height.

Definition at line 186 of file size_2d.hpp.

187 {
188 ostringstream output;
189 output << display_float(width,2) << " * " << display_float(height,2);
190 return output.str();
191 }
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36

◆ get_area()

float scifir::size_2d< float >::get_area ( ) const
inline

Calculates the area as the multiplication of the width and height.

Definition at line 181 of file size_2d.hpp.

182 {
183 return width * height;
184 }

◆ initialize_from_string()

void scifir::size_2d< float >::initialize_from_string ( const string init_size_2d)
inlineprivate

Internal function. Initializes the member-variables with an initialization string of size_2d<float>.

Definition at line 197 of file size_2d.hpp.

198 {
199 vector<string> widths;
200 boost::split(widths,init_size_2d,boost::is_any_of("*"));
201 if (widths.size() == 2)
202 {
203 boost::trim(widths[0]);
204 boost::trim(widths[1]);
205 width = stof(widths[0]);
206 height = stof(widths[1]);
207 }
208 }

◆ operator+()

size_2d< float > scifir::size_2d< float >::operator+ ( const size_2d< float > &  x) const
inline

Creates a new size_2d<float> by the addition of two size_2d<float> classes. The width is the result of the addition of the two width of the size_2d<float> classes and the height the result of the addition of the two height of the size_2d<float> classes.

Definition at line 159 of file size_2d.hpp.

160 {
161 return size_2d<float>(width + x.width,height + x.height);
162 }

◆ operator+=()

void scifir::size_2d< float >::operator+= ( const size_2d< float > &  x)
inline

Sums the width of size_2d<float> x to the width and sums the height of size_2d<float> x to the height.

Definition at line 169 of file size_2d.hpp.

170 {
171 width += x.width;
172 height += x.height;
173 }

◆ operator-()

size_2d< float > scifir::size_2d< float >::operator- ( const size_2d< float > &  x) const
inline

Creates a new size_2d<float> by the difference of two size_2d<float> classes. The width is the result of the difference of the two width of the size_2d<float> classes and the height the result of the difference of the two height of the size_2d<float> classes.

Definition at line 164 of file size_2d.hpp.

165 {
166 return size_2d<float>(width - x.width,height - x.height);
167 }

◆ operator-=()

void scifir::size_2d< float >::operator-= ( const size_2d< float > &  x)
inline

Substracts the width of size_2d<float> x to the width and substracts the height of size_2d<float> x to the height.

Definition at line 175 of file size_2d.hpp.

176 {
177 width -= x.width;
178 height -= x.height;
179 }

◆ operator=() [1/3]

size_2d< float > & scifir::size_2d< float >::operator= ( const size_2d< float > &  x)
inline

Copy assignment. The width and height are copied from the size_2d<float> x.

Definition at line 139 of file size_2d.hpp.

140 {
141 width = x.width;
142 height = x.height;
143 return *this;
144 }

◆ operator=() [2/3]

size_2d< float > & scifir::size_2d< float >::operator= ( const string init_size_2d)
inline

Assignment. The member-variables are initialized by the initialization string init_size_2d specialized for float.

Definition at line 153 of file size_2d.hpp.

154 {
155 initialize_from_string(init_size_2d);
156 return *this;
157 }

◆ operator=() [3/3]

size_2d< float > & scifir::size_2d< float >::operator= ( size_2d< float > &&  x)
inline

Move assignment. The width and height are moved from the size_2d<float> x.

Definition at line 146 of file size_2d.hpp.

147 {
148 width = std::move(x.width);
149 height = std::move(x.height);
150 return *this;
151 }

Member Data Documentation

◆ height

Height, stored as a float. The advantage related to size_2d<float> over size_2d<T> is that it sizes less, the disadvantage is the lack of dimensions.

Definition at line 194 of file size_2d.hpp.

◆ width

Width, stored as a float. The advantage related to size_2d<float> over size_2d<T> is that it sizes less, the disadvantage is the lack of dimensions.

Definition at line 193 of file size_2d.hpp.


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