From 0d4dcdc1c4717c88e79dfd0b7d4ebe34ff7cc548 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 6 Jun 2019 00:22:10 +0300 Subject: [PATCH] Add a simple linearly interpolated "spline" --- source/interpolate/linearspline.h | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 source/interpolate/linearspline.h diff --git a/source/interpolate/linearspline.h b/source/interpolate/linearspline.h new file mode 100644 index 0000000..2c88ceb --- /dev/null +++ b/source/interpolate/linearspline.h @@ -0,0 +1,42 @@ +#ifndef MSP_INTERPOLATE_LINEARSPLINE_H_ +#define MSP_INTERPOLATE_LINEARSPLINE_H_ + +#include +#include "spline.h" + +namespace Msp { +namespace Interpolate { + +/** +A very simple type of spline. It interpolates the value linearly between +knots. +*/ +template +class LinearSpline: public Spline +{ +public: + using typename Spline::Value; + using typename Spline::Knot; + + LinearSpline(const std::vector &k): + Spline(k.front()) + { + typedef SplineValue SV; + + this->reserve(k.size()-1); + for(unsigned i=1; i p[N]; + for(unsigned j=0; j(LinAl::Vector(SV::get(slope, j), SV::get(k[i-1].y, j)-k[i-1].x*SV::get(slope, j))); + this->add_segment(p, k[i].x); + } + } +}; + +} // namespace Interpolate +} // namespace Msp + +#endif -- 2.45.2