20#ifndef HEADER_INTERPOLATION_ARRAY_HPP
21#define HEADER_INTERPOLATION_ARRAY_HPP
35 std::vector<float>
m_x;
38 std::vector<float>
m_y;
41 std::vector<float> m_delta;
66 const unsigned int last=(
unsigned int)
m_x.size()-1;
70 m_delta.push_back( (
m_y[last]-
m_y[last-1])
73 m_delta.push_back( (
m_y[last]-
m_y[last-1])
74 /(
m_x[last]-
m_x[last-1]) );
80 unsigned int size()
const {
return (
unsigned int)
m_x.size(); }
83 float getX(
unsigned int i)
const {
return m_x[i]; }
86 float getY(
unsigned int i)
const {
return m_y[i]; }
89 void setY(
unsigned int i,
float y)
93 m_delta[i-1] = (
m_y[i]-
m_y[i-1])
96 m_delta[i] = (
m_y[i+1]-
m_y[i])
103 if(
m_x.size()==1 || x<
m_x[0])
112 for(
unsigned int i=1; i<
m_x.size(); i++)
114 if(x >
m_x[i])
continue;
115 return m_y[i-1] + m_delta[i-1] * (x -
m_x[i-1]);
117 assert(
false);
return 0;
126 if(
m_y.size()==1)
return m_x[0];
130 if(y >
m_y[0])
return m_x[0];
132 const unsigned int last = (
unsigned int)
m_x.size();
134 for(
unsigned int i=1; i<last; i++)
136 if(y <
m_y[i])
continue;
137 return m_x[i-1] + (y-
m_y[i-1])/ m_delta[i-1];
143 if(y <
m_y[0])
return m_x[0];
145 const unsigned int last = (
unsigned int)
m_x.size();
147 for(
unsigned int i=1; i<last; i++)
149 if(y >
m_y[i])
continue;
150 return m_x[i-1] + (y-
m_y[i-1]) / m_delta[i-1];
This class manages a set of (x_i,y_i) points, x_i must be sorted.
Definition: interpolation_array.hpp:32
void setY(unsigned int i, float y)
Sets the Y value for a specified point.
Definition: interpolation_array.hpp:89
float getReverse(float y) const
Returns the X value necessary for a specified Y value.
Definition: interpolation_array.hpp:124
float getX(unsigned int i) const
Returns the X value for a specified point.
Definition: interpolation_array.hpp:83
float get(float x) const
Returns the interpolated Y value for a given x.
Definition: interpolation_array.hpp:101
unsigned int size() const
Returns the number of X/Y points.
Definition: interpolation_array.hpp:80
std::vector< float > m_y
The y values.
Definition: interpolation_array.hpp:38
float getY(unsigned int i) const
Returns the Y value for a specified point.
Definition: interpolation_array.hpp:86
std::vector< float > m_x
The sorted x values.
Definition: interpolation_array.hpp:35
int push_back(float x, float y)
Adds the value pair x/y to the list of all points.
Definition: interpolation_array.hpp:58
void clear()
Removes all saved values from this object.
Definition: interpolation_array.hpp:47