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
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
coordinates_ndr.cpp
Go to the documentation of this file.
2
3using namespace std;
4
5namespace scifir
6{
9
11 {
12 if (x.get_values().size() > 0)
13 {
15 out << "(";
16 if (x.get_values().size() > 0)
17 {
18 for (int i = 0; i < x.get_values().size(); i++)
19 {
20 out << display_float(x.get_value(i));
21 if ((i + 1) != x.get_values().size())
22 {
23 out << ",";
24 }
25 }
26 }
27 if (x.get_angles().size() > 0)
28 {
29 out << ";";
30 for (int i = 0; i < x.get_angles().size(); i++)
31 {
32 out << x.get_angle(i);
33 if ((i + 1) != x.get_angles().size())
34 {
35 out << ",";
36 }
37 }
38 }
39 out << ")";
40 return out.str();
41 }
42 else
43 {
44 return "[empty]";
45 }
46 }
47
49 {
50 if (x.get_nd() == y.get_nd())
51 {
52 float x_length = 0;
53 for (unsigned int i = 0; i < x.get_values().size(); i++)
54 {
55 x_length += float(std::pow(x.get_value(i) - y.get_value(i),2));
56 }
57 return std::sqrt(x_length);
58 }
59 else
60 {
61 return 0.0f;
62 }
63 }
64
66 {
67 if (x.get_nd() == y.get_nd())
68 {
69 float x_length = 0;
70 for (unsigned int i = 0; i < x.get_values().size(); i++)
71 {
72 x_length += float(std::pow(x.get_value(i) - y.values[i],2));
73 }
74 return std::sqrt(x_length);
75 }
76 else
77 {
78 return 0.0f;
79 }
80 }
81
83 {
84 if (x.get_nd() == y.get_nd())
85 {
86 float x_length = 0;
87 for (unsigned int i = 0; i < x.values.size(); i++)
88 {
89 x_length += float(std::pow(x.values[i] - y.get_value(i),2));
90 }
91 return std::sqrt(x_length);
92 }
93 else
94 {
95 return 0.0f;
96 }
97 }
98}
99
100ostream& operator <<(ostream& os,const scifir::coordinates_ndr<float>& x)
101{
102 return os << scifir::to_string(x);
103}
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition angle.hpp:77
ostream & operator<<(ostream &os, const scifir::coordinates_ndr< float > &x)
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
float distance(const coordinates_1d< float > &x, const coordinates_1d< float > &y)
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36
angle coordinates_ndr_no_angle