From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun/library/spline.cpp | 194 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 noatun/library/spline.cpp (limited to 'noatun/library/spline.cpp') diff --git a/noatun/library/spline.cpp b/noatun/library/spline.cpp new file mode 100644 index 00000000..d09c12dc --- /dev/null +++ b/noatun/library/spline.cpp @@ -0,0 +1,194 @@ +/* + Copyright (C) 1998 Jürgen Hochwald + Copyright (C) 2003 Charles Samuels + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + + + +#include +#include "spline.h" + +const bool Spline::natural=false; + +Spline::Spline() +{ + yp1=0.0; + ypn=0.0; + mRecalc = true; +} + +Spline::Spline(const Spline ©) +{ + operator=(copy); +} + +Spline &Spline::operator =(const Spline ©) +{ + mPoints = copy.mPoints; + mRecalc = copy.mRecalc; + yp1 = copy.yp1; + ypn = copy.ypn; + return *this; +} + +Spline::~Spline() +{ + +} + +void Spline::add(double x, double y) +{ + Group g = { x, y, 0.0 }; + mPoints.push_back(g); + mRecalc=true; +} + +std::vector Spline::points(int count) const +{ + std::vector points; + if (count == numPoints()) + { + for (int i=0; i < count; ++i) + { + points.push_back(mPoints[i].y); + } + } + else + { + double min = mPoints[0].x; + double max = mPoints[numPoints()-1].x; + double dcount = double(count); + + for (int i=0; i=0; i--) + { + mPoints[i].y2 = mPoints[i].y2 * mPoints[i+1].y2+u[i]; + } + mRecalc = false; + delete [] u; +} + +double Spline::spline(double xarg) const +{ + if (numPoints()==0) return 0.0; + if (numPoints()==1) return mPoints[0].y; + + if (mRecalc) calcSpline(); + + int klo=0; + int khi=numPoints()-1; + int k; + while (khi-klo > 1) + { + k = khi+klo; + if (k % 2) + k = (k+1) / 2; + else + k = k/2; + + if (mPoints[k].x > xarg) khi=k; + else klo=k; + } + + double h = mPoints[khi].x - mPoints[klo].x; + if (h==0) + { + // failed + return 0.0; + } + + double a = (mPoints[khi].x - xarg) / h; + double b = (xarg - mPoints[klo].x) / h; + return + a * mPoints[klo].y + b*mPoints[khi].y + + ((a*a*a-a) * mPoints[klo].y2 + + (b*b*b-b) * mPoints[khi].y2) * (h*h) / 6.0; +} + +double Spline::x(int num) const +{ + if (numPoints()