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
coordinates_nd.cpp
Go to the documentation of this file.
2
3using namespace std;
4
5namespace scifir
6{
8 {
9 if (x.values.size() > 0)
10 {
12 out << "(";
13 for (int i = 0; i < x.values.size(); i++)
14 {
15 out << display_float(x.values[i]);
16 if ((i + 1) != x.values.size())
17 {
18 out << ",";
19 }
20 }
21 out << ")";
22 return out.str();
23 }
24 else
25 {
26 return "[empty]";
27 }
28 }
29
31 {
32 if (x.get_nd() == y.get_nd())
33 {
34 float x_length = 0;
35 for (unsigned int i = 0; i < x.values.size(); i++)
36 {
37 x_length += float(std::pow(x.values[i] - y.values[i],2));
38 }
39 return std::sqrt(x_length);
40 }
41 else
42 {
43 return 0.0f;
44 }
45 }
46}
47
48ostream& operator <<(ostream& os,const scifir::coordinates_nd<float>& x)
49{
50 return os << scifir::to_string(x);
51}
ostream & operator<<(ostream &os, const scifir::coordinates_nd< 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