31#ifndef _GEMA_PIECEWISECURVE_H_
32#define _GEMA_PIECEWISECURVE_H_
35#define EPSILON 2.2204460492503131e-016
38namespace GmpPiecewiseCurve
47 if (curve(0, col) < curve(curve.
n_rows - 1, col))
50 if (value < curve(0, col))
52 if (value > curve(curve.
n_rows - 1, col))
55 while (curve(i, col) < value)
62 if (value > curve(0, col))
64 if (value < curve(curve.
n_rows - 1, col))
67 while (curve(i, col) > value)
84 gmErrorMsg(logger,
"GmpPiecewiseCurve: Error 'x' value is out of the curve range.");
85 return std::numeric_limits<double>::quiet_NaN();
88 double dx = curve(i, 0) - curve(i - 1, 0);
89 double dy = curve(i, 1) - curve(i - 1, 1);
90 if (std::abs(dx) < EPSILON)
92 gmErrorMsg(logger,
"GmpPiecewiseCurve: Error the given curve has repeated x values.");
93 return std::numeric_limits<double>::quiet_NaN();
95 double y = (dy / dx) * (x - curve(i - 1, 0)) + curve(i - 1, 1);
109 gmErrorMsg(logger,
"GmpPiecewiseCurve: Error 'y' value is out of the curve range.");
110 return std::numeric_limits<double>::quiet_NaN();
114 double dx = curve(i, 0) - curve(i - 1, 0);
115 double dy = curve(i, 1) - curve(i - 1, 1);
116 if (std::abs(dx) > EPSILON)
const unsigned int n_rows
double derivativeGivenY(double y, GmCRMatrix &curve, const GmLogCategory &logger)
Returns the derivative of the curve at a given y value.
Definition gmpPiecewiseCurve.h:101
double interpolate(double x, GmCRMatrix &curve, const GmLogCategory &logger)
Returns the corresponding y value for a given x value.
Definition gmpPiecewiseCurve.h:77
int findInterval(double value, GmCRMatrix &curve, int col)
Definition gmpPiecewiseCurve.h:43