forked from psemiletov/eko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibretta_interpolator.cpp
58 lines (42 loc) · 1 KB
/
libretta_interpolator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "libretta_interpolator.h"
#include <cmath>
#include <iostream>
CFloatInterpolator::CFloatInterpolator (size_t x_1, float y_1, size_t x_2, float y_2)
{
y1 = y_1;
y2 = y_2;
x1 = x_1;
x2 = x_2;
}
CFloatInterpolatorSimple::CFloatInterpolatorSimple (size_t x_1, float y_1, size_t x_2, float y_2):
CFloatInterpolator (x_1, y_1, x_2, y_2)
{
size_t elements_between = x_2 - x_1;
//cout << "y1: " << y1 << endl;
//cout << "y2: " << y2 << endl;
if (y2 > y1)
{
values_diff = y2 - y1;
if (values_diff == 0)
part = 0.0f;
else
part = (float) values_diff / elements_between;
}
else
{
float values_diff = y1 - y2;
if (values_diff == 0)
part = 0;
else
part = (float) values_diff / elements_between;
}
}
float CFloatInterpolatorSimple::get_y_at_x (size_t x)
{
if (y2 > y1)
{
return (y1 + ((x - x1) * part));
}
else
return (y1 - ((x - x1) * part));
}