24template<
typename T,
typename U>
struct Point
45 assert(points.size() >= 2 &&
"Linear curve must have more than 1 points");
49 for (
const auto& p: pts)
52 assert(not std::isnan(p.x) &&
"invalid value in curve parameters");
53 assert(std::isfinite(p.x) &&
"invalid value in curve parameters");
54 assert(not std::isnan(p.y) &&
"invalid value in curve parameters");
55 assert(std::isfinite(p.y) &&
"invalid value in curve parameters");
62 std::sort(pts.begin(), pts.end(), lbd);
65 std::vector<point_t> nPoints;
66 nPoints.reserve(pts.size());
69 nPoints.emplace_back(lastPt);
70 for (
size_t i = 1; i < pts.size(); i++)
72 const auto& p = pts[i];
73 if (lastPt.
x != p.x and lastPt.
y != p.y)
74 nPoints.emplace_back(p);
79 assert(pts.size() >= 2 &&
"Linear curve must have more than 1 points");
91 if (x >= pts.back().x)
94 for (
size_t i = 1; i < pts.size(); ++i)
98 if (x >= lastPt.
x and x <= pt.
x)
100 return lmpd_map<U>(x, lastPt.
x, pt.
x, lastPt.
y, pt.
y);
112 std::vector<point_t> pts;
134 lowerBound(pointA.y),
137 const double div = pointA.
y /
static_cast<double>(pointB.
y);
146 const double A = exp(log(div) / exponent);
148 _a = (
static_cast<double>(pointA.
x) -
static_cast<double>(pointB.
x) * A) / (A - 1);
149 _b =
static_cast<double>(pointA.
y) / pow(
static_cast<double>(pointA.
x + _a), exponent);
159 const float res = pow(
static_cast<double>(x) + _a, _exp) * _b;
160 return lmpd_constrain<float>(res, lowerBound, upperBound);
Given two points and an exponent, fit an exponential function.
Definition: curves.h:121
ExponentialCurve(const point_t &pointA, const point_t &pointB, const double exponent=15.0)
Exponential curve fitting to two points.
Definition: curves.h:133
float sample(const T x) const
Sample the exponential curve. Be aware that the result is always casted from a floating point !...
Definition: curves.h:157
Given a set of points, will fit multiple linear segments to it.
Definition: curves.h:36
LinearCurve(const std::vector< point_t > &points)
Build a curve from a set of points.
Definition: curves.h:42
U sample(const T x) const
Sample a point Y from a given x.
Definition: curves.h:83
Program scope.
Definition: control_fixed_modes.hpp:12
Define a 2D point.
Definition: curves.h:25
T x
X coordinate of the point.
Definition: curves.h:26
U y
Y coordinate of the point.
Definition: curves.h:27