4 const std::vector<float>& yPositions,
float x)
6 jassert(xPositions.size() == yPositions.size());
8 const int numPoints =
static_cast<int>(xPositions.size());
19 for (
int i = 0; i < numPoints - 1; ++i)
21 if (xPositions[i + 1] >= x)
28 const float x0 = xPositions[index];
29 const float x1 = xPositions[index + 1];
30 const float y0 = yPositions[index];
31 const float y1 = yPositions[index + 1];
33 const float dx = x1 - x0;
34 const float dy = y1 - y0;
35 const float h0 = (index > 0) ? x0 - xPositions[index - 1] : dx;
36 const float h1 = (index < numPoints - 2) ? xPositions[index + 2] - x1 : dx;
38 const float t = (x - x0) / dx;
39 const float t2 = t * t;
41 const float p = (1.0f - t) * y0 + t * y1;
43 if (dy * h0 > 0.0f && dy * h1 > 0.0f)
45 const float a = (2.0f * dy - h0 * (y1 - y0) / dx) / h0;
46 const float b = (2.0f * dy - h1 * (y1 - y0) / dx) / h1;
48 return t * (1.0f - t) * (a * h0 + b * h1) + p;
57 const Eigen::VectorXf& yPositions,
float x)
59 jassert(xPositions.size() == yPositions.size());
61 const int numPoints =
static_cast<int>(xPositions.size());
72 for (
int i = 0; i < numPoints - 1; ++i)
74 if (xPositions[i + 1] >= x)
81 const float x0 = xPositions[index];
82 const float x1 = xPositions[index + 1];
83 const float y0 = yPositions[index];
84 const float y1 = yPositions[index + 1];
86 const float dx = x1 - x0;
87 const float dy = y1 - y0;
88 const float h0 = (index > 0) ? x0 - xPositions[index - 1] : dx;
89 const float h1 = (index < numPoints - 2) ? xPositions[index + 2] - x1 : dx;
91 const float t = (x - x0) / dx;
92 const float t2 = t * t;
94 const float p = (1.0f - t) * y0 + t * y1;
96 if (dy * h0 > 0.0f && dy * h1 > 0.0f)
98 const float a = (2.0f * dy - h0 * (y1 - y0) / dx) / h0;
99 const float b = (2.0f * dy - h1 * (y1 - y0) / dx) / h1;
101 return t * (1.0f - t) * (a * h0 + b * h1) + p;
110 const std::vector<float>& xValues,
const std::vector<std::vector<float>>& yValues,
111 const std::vector<float>& vals)
114 if (xValues.size() != yValues[0].size() || yValues[0].size() == 0)
120 std::vector<std::vector<float>> resultMatrix;
122 for (
int row = 0; row < yValues.size(); ++row)
125 std::vector<float> interpolatedValues =
interpolateVector(xValues, yValues[row], vals);
127 resultMatrix.push_back(interpolatedValues);
134 const Eigen::MatrixXf yValues,
135 const Eigen::VectorXf& vals)
138 if (xValues.size() != yValues.rows() || yValues.rows() == 0)
144 Eigen::MatrixXf resultMatrix(vals.size(), yValues.cols());
146 for (
int col = 0; col < yValues.cols(); ++col)
151 resultMatrix.col(col) = interpolatedValues;
158 const std::vector<float>& yPositions,
159 const std::vector<float>& xValues)
161 jassert(xPositions.size() == yPositions.size());
163 const int numPoints =
static_cast<int>(xPositions.size());
168 return std::vector<float>(xValues.size(), 0.0f);
171 std::vector<float> interpolatedValues;
172 interpolatedValues.reserve(xValues.size());
174 for (
float x : xValues)
179 for (
int i = 0; i < numPoints - 1; ++i)
181 if (xPositions[i + 1] >= x)
188 const float x0 = xPositions[index];
189 const float x1 = xPositions[index + 1];
190 const float y0 = yPositions[index];
191 const float y1 = yPositions[index + 1];
193 const float dx = x1 - x0;
194 const float dy = y1 - y0;
195 const float h0 = (index > 0) ? x0 - xPositions[index - 1] : dx;
196 const float h1 = (index < numPoints - 2) ? xPositions[index + 2] - x1 : dx;
198 const float t = (x - x0) / dx;
199 const float t2 = t * t;
201 const float p = (1.0f - t) * y0 + t * y1;
203 if (dy * h0 > 0.0f && dy * h1 > 0.0f)
205 const float a = (2.0f * dy - h0 * (y1 - y0) / dx) / h0;
206 const float b = (2.0f * dy - h1 * (y1 - y0) / dx) / h1;
208 interpolatedValues.push_back(t * (1.0f - t) * (a * h0 + b * h1) + p);
212 interpolatedValues.push_back(p);
216 return interpolatedValues;
220 const Eigen::VectorXf& yPositions,
221 const Eigen::VectorXf& xValues)
223 jassert(xPositions.size() == yPositions.size());
225 const int numPoints =
static_cast<int>(xPositions.size());
230 return Eigen::VectorXf::Zero(xValues.size());
233 Eigen::VectorXf interpolatedValues(xValues.size());
235 for (
int k = 0; k < xValues.size(); ++k)
237 float x = xValues[k];
241 for (
int i = 0; i < numPoints - 1; ++i)
243 if (xPositions[i + 1] >= x)
250 const float x0 = xPositions[index];
251 const float x1 = xPositions[index + 1];
252 const float y0 = yPositions[index];
253 const float y1 = yPositions[index + 1];
255 const float dx = x1 - x0;
256 const float dy = y1 - y0;
257 const float h0 = (index > 0) ? x0 - xPositions[index - 1] : dx;
258 const float h1 = (index < numPoints - 2) ? xPositions[index + 2] - x1 : dx;
260 const float t = (x - x0) / dx;
261 const float t2 = t * t;
263 const float p = (1.0f - t) * y0 + t * y1;
265 if (dy * h0 > 0.0f && dy * h1 > 0.0f)
267 const float a = (2.0f * dy - h0 * (y1 - y0) / dx) / h0;
268 const float b = (2.0f * dy - h1 * (y1 - y0) / dx) / h1;
270 interpolatedValues[k] = t * (1.0f - t) * (a * h0 + b * h1) + p;
274 interpolatedValues[k] = p;
278 return interpolatedValues;
284 const std::vector<float>& yValues,
285 const std::vector<float>& vals)
288 if (xValues.size() != yValues.size())
291 return std::vector<float>();
295 std::vector<float> interpolatedValues;
296 int size =
static_cast<int>(vals.size());
298 for (
int i = 0; i < size; ++i)
300 float valToInterpolateFor = vals[i];
305 int xSize =
static_cast<int>(xValues.size());
306 for (
int j = 0; j < xSize; ++j)
308 if (xValues[j] <= valToInterpolateFor)
318 float x1 = xValues[index1];
319 float x2 = xValues[index2];
320 float y1 = yValues[index1];
321 float y2 = yValues[index2];
324 if (std::isnan(valToInterpolateFor))
326 interpolatedValues.push_back(std::numeric_limits<float>::quiet_NaN());
328 else if (std::isnan(x1) || std::isnan(x2) || std::isnan(y1) || std::isnan(y2))
331 interpolatedValues.push_back(std::numeric_limits<float>::quiet_NaN());
338 interpolatedValues.push_back(0.0f);
342 float interpolatedValue = y1 + ((valToInterpolateFor - x1) * (y2 - y1)) / (x2 - x1);
343 interpolatedValues.push_back(interpolatedValue);
348 return interpolatedValues;
352 const Eigen::VectorXf& vals)
355 if (xValues.size() != yValues.size())
358 return Eigen::VectorXf::Zero(xValues.size());
361 Eigen::VectorXf interpolatedValues(vals.size());
363 for (
int i = 0; i < vals.size(); ++i)
365 float valToInterpolateFor = vals[i];
370 int xSize =
static_cast<int>(xValues.size());
371 for (
int j = 0; j < xSize; ++j)
373 if (xValues[j] <= valToInterpolateFor)
383 float x1 = xValues[index1];
384 float x2 = xValues[index2];
385 float y1 = yValues[index1];
386 float y2 = yValues[index2];
388 if (valToInterpolateFor < x1 || valToInterpolateFor > x2)
391 interpolatedValues[i] = std::numeric_limits<float>::quiet_NaN();
398 interpolatedValues.conservativeResize(interpolatedValues.size() + 1);
399 interpolatedValues(interpolatedValues.size() - 1) =
400 std::numeric_limits<float>::quiet_NaN();
404 float interpolatedValue = y1 + ((valToInterpolateFor - x1) * (y2 - y1)) / (x2 - x1);
405 interpolatedValues[i] = interpolatedValue;
410 return interpolatedValues;
414 const Eigen::MatrixXf& yValues,
const Eigen::VectorXf& vals)
417 if (xValues.size() != yValues.rows() || yValues.rows() == 0)
423 Eigen::MatrixXf resultMatrix(vals.size(), yValues.cols());
425 for (
int col = 0; col < yValues.cols(); ++col)
430 resultMatrix.col(col) = interpolatedValues;
437 const std::vector<std::vector<float>>& yValues,
438 const std::vector<float>& vals)
441 if (xValues.size() != yValues[0].size() || yValues[0].size() == 0)
448 std::vector<float> sanitizedVals = vals;
449 std::transform(sanitizedVals.begin(), sanitizedVals.end(), sanitizedVals.begin(), [&](
float val) {
450 return (val < xValues.front() || val > xValues.back()) ? std::numeric_limits<float>::quiet_NaN() : val;
453 std::vector<std::vector<float>> resultMatrix;
455 for (
int row = 0; row < yValues.size(); ++row)
458 std::vector<float> interpolatedValues =
461 resultMatrix.push_back(interpolatedValues);
static Eigen::VectorXf interpolateEigen(const Eigen::VectorXf &xValues, const Eigen::VectorXf &yValues, const Eigen::VectorXf &vals)
Definition KrotosIntrepolators.cpp:351
static Eigen::MatrixXf interpolate2DEigen(const Eigen::VectorXf &xValues, const Eigen::MatrixXf &yValues, const Eigen::VectorXf &vals)
Definition KrotosIntrepolators.cpp:413
static std::vector< std::vector< float > > interpolate2D(const std::vector< float > &xValues, const std::vector< std::vector< float > > &yValues, const std::vector< float > &vals)
Definition KrotosIntrepolators.cpp:436
static std::vector< float > interpolate(const std::vector< float > &xValues, const std::vector< float > &yValues, const std::vector< float > &vals)
Definition KrotosIntrepolators.cpp:283
static Eigen::VectorXf interpolateVectorEigen(const Eigen::VectorXf &xPositions, const Eigen::VectorXf &yPositions, const Eigen::VectorXf &xValues)
Definition KrotosIntrepolators.cpp:219
static std::vector< float > interpolateVector(const std::vector< float > &xPositions, const std::vector< float > &yPositions, const std::vector< float > &xValues)
Definition KrotosIntrepolators.cpp:157
static float interpolate(const std::vector< float > &xPositions, const std::vector< float > &yPositions, float x)
Definition KrotosIntrepolators.cpp:3
static float interpolateEigen(const Eigen::VectorXf &xPositions, const Eigen::VectorXf &yPositions, float x)
Definition KrotosIntrepolators.cpp:56
static std::vector< std::vector< float > > interpolate2D(const std::vector< float > &xValues, const std::vector< std::vector< float > > &yValues, const std::vector< float > &vals)
Definition KrotosIntrepolators.cpp:109
static Eigen::MatrixXf interpolate2DEigen(const Eigen::VectorXf &xValues, const Eigen::MatrixXf yValues, const Eigen::VectorXf &vals)
Definition KrotosIntrepolators.cpp:133
Definition AirAbsorptionFilter.cpp:2