libipa: pwl: Fix single point Pwl

Fix the eval() function for Pwls that contain only a single point.
Remove the should_fail from the corresponding test case.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-07-18 13:55:40 +02:00
parent e33814c65b
commit 75ad3c84a1
2 changed files with 5 additions and 1 deletions
+4
View File
@@ -210,6 +210,10 @@ double Pwl::eval(double x, int *span, bool updateSpan) const
: points_.size() / 2 - 1);
if (span && updateSpan)
*span = index;
if (points_.size() == 1)
return points_[0].y();
return points_[index].y() +
(x - points_[index].x()) * (points_[index + 1].y() - points_[index].y()) /
(points_[index + 1].x() - points_[index].x());
+1 -1
View File
@@ -4,7 +4,7 @@ libipa_test = [
{'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},
{'name': 'histogram', 'sources': ['histogram.cpp']},
{'name': 'interpolator', 'sources': ['interpolator.cpp']},
{'name': 'pwl', 'sources': ['pwl.cpp'], 'should_fail': true },
{'name': 'pwl', 'sources': ['pwl.cpp'] },
]
foreach test : libipa_test