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_ndr.cpp
Go to the documentation of this file.
1
#include "
./coordinates_ndr.hpp
"
2
3
using namespace
std;
4
5
namespace
scifir
6
{
7
angle
coordinates_ndr_no_angle
=
angle
();
8
float
coordinates_ndr<float>::no_value
= 0;
9
10
string
to_string
(
const
coordinates_ndr<float>
& x)
11
{
12
if
(x.get_values().size() > 0)
13
{
14
ostringstream
out
;
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
48
float
distance
(
const
coordinates_ndr<float>
& x,
const
coordinates_ndr<float>
& y)
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
65
float
distance
(
const
coordinates_ndr<float>
& x,
const
coordinates_nd<float>
& y)
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
82
float
distance
(
const
coordinates_nd<float>
& x,
const
coordinates_ndr<float>
& y)
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
100
ostream&
operator <<
(ostream& os,
const
scifir::coordinates_ndr<float>
& x)
101
{
102
return
os <<
scifir::to_string
(x);
103
}
scifir::angle
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition
angle.hpp:77
scifir::coordinates_1d
Definition
coordinates_1d.hpp:18
scifir::coordinates_ndr
Definition
coordinates_ndr.hpp:21
operator<<
ostream & operator<<(ostream &os, const scifir::coordinates_ndr< float > &x)
Definition
coordinates_ndr.cpp:100
coordinates_ndr.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
scifir::coordinates_ndr_no_angle
angle coordinates_ndr_no_angle
Definition
coordinates_ndr.cpp:7
Generated by
1.9.8