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< T > Class Template Reference

Class that allows to store and calculate size in 2D, with width and height. The template parameter T allows to select any scalar_unit or numeric type to be the type of width and height (they always have the same type in the same instance). The width and height can be any scalar_unit, usually length, but imaginary spaces with custom dimensions are also allowed. Initialization string example: "1 m * 2 m". More...

#include <size_2d.hpp>

Public Member Functions

 size_2d ()
 Default constructor. Both width and height are initialized to 0, with the dimensions to the default of their base unit.
 
 size_2d (const size_2d< T > &x)
 Copy constructor. The width and height are copied from the size_2d<T> x.
 
 size_2d (size_2d< T > &&x)
 Move constructor. The width and height are moved from the size_2d<T> x.
 
 size_2d (const scalar_unit &new_width, const scalar_unit &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.
 
size_2d< T > & operator= (const size_2d< T > &x)
 Copy assignment. The width and height are copied from the size_2d<T> x.
 
size_2d< T > & operator= (size_2d< T > &&x)
 Move assignment. The width and height are moved from the size_2d<T> x.
 
size_2d< T > & operator= (const string &init_size_2d)
 Assignment. The member-variables are initialized by the initialization string init_size_2d.
 
template<typename U >
size_2d< Toperator+ (const size_2d< U > &x) const
 Creates a new size_2d<T> by the addition of two size_2d<T> classes. The width is the result of the addition of the two width of the size_2d<T> classes and the height the result of the addition of the two height of the size_2d<T> classes.
 
template<typename U >
size_2d< Toperator- (const size_2d< U > &x) const
 Creates a new size_2d<T> by the difference of two size_2d<T> classes. The width is the result of the difference of the two width of the size_2d<T> classes and the height the result of the difference of the two height of the size_2d<T> classes.
 
template<typename U >
void operator+= (const size_2d< U > &x)
 Sums the width of size_2d<T> x to the width and sums the height of size_2d<T> x to the height.
 
template<typename U >
void operator-= (const size_2d< U > &x)
 Substracts the width of size_2d<T> x to the width and substracts the height of size_2d<T> x to the height.
 
scalar_unit get_area () const
 Calculates the area as the multiplication of the width and height.
 
string display () const
 Returns a string representation of size_2d<T>, with his width and height.
 

Public Attributes

T width
 Width, usually stored as length.
 
T height
 Height, usually stored as length.
 

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<T>.
 

Detailed Description

template<typename T = length>
class scifir::size_2d< T >

Class that allows to store and calculate size in 2D, with width and height. The template parameter T allows to select any scalar_unit or numeric type to be the type of width and height (they always have the same type in the same instance). The width and height can be any scalar_unit, usually length, but imaginary spaces with custom dimensions are also allowed. Initialization string example: "1 m * 2 m".

Definition at line 16 of file size_2d.hpp.

Constructor & Destructor Documentation

◆ size_2d() [1/6]

template<typename T = length>
size_2d::size_2d ( )
inline

Default constructor. Both width and height are initialized to 0, with the dimensions to the default of their base unit.

Definition at line 19 of file size_2d.hpp.

19 : width(),height()
20 {}
T height
Height, usually stored as length.
Definition size_2d.hpp:98
T width
Width, usually stored as length.
Definition size_2d.hpp:97

◆ size_2d() [2/6]

template<typename T = length>
size_2d::size_2d ( const size_2d< T > &  x)
inline

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

Definition at line 22 of file size_2d.hpp.

22 : width(x.width),height(x.height)
23 {}

◆ size_2d() [3/6]

template<typename T = length>
size_2d::size_2d ( size_2d< T > &&  x)
inline

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

Definition at line 25 of file size_2d.hpp.

25 : width(std::move(x.width)),height(std::move(x.height))
26 {}

◆ size_2d() [4/6]

template<typename T = length>
scifir::size_2d< T >::size_2d ( const scalar_unit new_width,
const scalar_unit new_height 
)
inlineexplicit

Definition at line 28 of file size_2d.hpp.

28 : width(new_width),height(new_height)
29 {}

◆ size_2d() [5/6]

template<typename T = length>
size_2d::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 31 of file size_2d.hpp.

31 : width(new_width),height(new_height)
32 {}

◆ size_2d() [6/6]

template<typename T = length>
size_2d::size_2d ( const string init_size_2d)
inlineexplicit

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

Definition at line 34 of file size_2d.hpp.

34 : size_2d()
35 {
36 initialize_from_string(init_size_2d);
37 }
size_2d()
Default constructor. Both width and height are initialized to 0, with the dimensions to the default o...
Definition size_2d.hpp:19
void initialize_from_string(const string &init_size_2d)
Internal function. Initializes the member-variables with an initialization string of size_2d<T>.
Definition size_2d.hpp:101

Member Function Documentation

◆ display()

template<typename T = length>
string size_2d::display ( ) const
inline

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

Definition at line 90 of file size_2d.hpp.

91 {
92 ostringstream output;
93 output << width << " * " << height;
94 return output.str();
95 }

◆ get_area()

template<typename T = length>
scalar_unit size_2d::get_area ( ) const
inline

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

Definition at line 85 of file size_2d.hpp.

86 {
87 return scalar_unit(width * height);
88 }

◆ initialize_from_string()

template<typename T = length>
void size_2d::initialize_from_string ( const string init_size_2d)
inlineprivate

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

Definition at line 101 of file size_2d.hpp.

102 {
103 vector<string> widths;
104 boost::split(widths,init_size_2d,boost::is_any_of("*"));
105 if (widths.size() == 2)
106 {
107 boost::trim(widths[0]);
108 boost::trim(widths[1]);
109 width = T(widths[0]);
110 height = T(widths[1]);
111 }
112 }

◆ operator+()

template<typename T = length>
template<typename U >
size_2d< T > size_2d::operator+ ( const size_2d< U > &  x) const
inline

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

Definition at line 60 of file size_2d.hpp.

61 {
62 return size_2d<T>(width + x.width,height + x.height);
63 }

◆ operator+=()

template<typename T = length>
template<typename U >
void size_2d::operator+= ( const size_2d< U > &  x)
inline

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

Definition at line 72 of file size_2d.hpp.

73 {
74 width += x.width;
75 height += x.height;
76 }

◆ operator-()

template<typename T = length>
template<typename U >
size_2d< T > size_2d::operator- ( const size_2d< U > &  x) const
inline

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

Definition at line 66 of file size_2d.hpp.

67 {
68 return size_2d<T>(width - x.width,height - x.height);
69 }

◆ operator-=()

template<typename T = length>
template<typename U >
void size_2d::operator-= ( const size_2d< U > &  x)
inline

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

Definition at line 79 of file size_2d.hpp.

80 {
81 width -= x.width;
82 height -= x.height;
83 }

◆ operator=() [1/3]

template<typename T = length>
size_2d< T > & size_2d::operator= ( const size_2d< T > &  x)
inline

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

Definition at line 39 of file size_2d.hpp.

40 {
41 width = x.width;
42 height = x.height;
43 return *this;
44 }

◆ operator=() [2/3]

template<typename T = length>
size_2d< T > & size_2d::operator= ( const string init_size_2d)
inline

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

Definition at line 53 of file size_2d.hpp.

54 {
55 initialize_from_string(init_size_2d);
56 return *this;
57 }

◆ operator=() [3/3]

template<typename T = length>
size_2d< T > & size_2d::operator= ( size_2d< T > &&  x)
inline

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

Definition at line 46 of file size_2d.hpp.

47 {
48 width = std::move(x.width);
49 height = std::move(x.height);
50 return *this;
51 }

Member Data Documentation

◆ height

template<typename T = length>
T size_2d::height

Height, usually stored as length.

Definition at line 98 of file size_2d.hpp.

◆ width

template<typename T = length>
T size_2d::width

Width, usually stored as length.

Definition at line 97 of file size_2d.hpp.


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