From: Mikko Rasa Date: Wed, 5 Jun 2019 21:22:10 +0000 (+0300) Subject: Add a simple linearly interpolated "spline" X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=commitdiff_plain;h=0d4dcdc1c4717c88e79dfd0b7d4ebe34ff7cc548 Add a simple linearly interpolated "spline" --- 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