Simpact Cyan
Population based event driven simulation using mNRM
piecewiselinearfunction.h
1 #ifndef PIECEWISELINEARFUNCTION_H
2 
3 #define PIECEWISELINEARFUNCTION_H
4 
5 #include "function.h"
6 #include "point2d.h"
7 #include <vector>
8 #include <limits>
9 
10 // TODO: this is a slow, trivial implementation for now. Not suited for a large
11 // number of points since at every evaluation all points will be scanned
12 // to find the right interval
13 class PieceWiseLinearFunction : public Function
14 {
15 public:
16  PieceWiseLinearFunction(const std::vector<Point2D> &points,
17  double leftValue = std::numeric_limits<double>::quiet_NaN(),
18  double rightValue = std::numeric_limits<double>::quiet_NaN());
19  ~PieceWiseLinearFunction();
20 
21  double evaluate(double x);
22 
23  double getLeftValue() const { return m_leftValue; }
24  double getRightValue() const { return m_rightValue; }
25  const std::vector<Point2D> &getPoints() const { return m_points; }
26 private:
27  std::vector<Point2D> m_points;
28  double m_leftValue;
29  double m_rightValue;
30 };
31 
32 #endif // PIECEWISELINEARFUNCTION_H