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
coordinates_nd.cpp
Go to the documentation of this file.
1
#include "
./coordinates_nd.hpp
"
2
3
using namespace
std;
4
5
namespace
scifir
6
{
7
string
to_string
(
const
coordinates_nd<float>
& x)
8
{
9
if
(x.values.size() > 0)
10
{
11
ostringstream
out
;
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
30
float
distance
(
const
coordinates_nd<float>
& x,
const
coordinates_nd<float>
& y)
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
48
ostream&
operator <<
(ostream& os,
const
scifir::coordinates_nd<float>
& x)
49
{
50
return
os <<
scifir::to_string
(x);
51
}
scifir::coordinates_1d
Definition
coordinates_1d.hpp:18
operator<<
ostream & operator<<(ostream &os, const scifir::coordinates_nd< float > &x)
Definition
coordinates_nd.cpp:48
coordinates_nd.hpp
scifir
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition
address.cpp:6
scifir::to_string
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
scifir::distance
float distance(const coordinates_1d< float > &x, const coordinates_1d< float > &y)
Definition
coordinates_1d.cpp:13
scifir::display_float
string display_float(const float &value, int number_of_decimals)
Definition
types.cpp:36
Generated by
1.9.8