////////////////////////////////////////////////////////////////////////
//
// $Id: InterSplineFunc.h,v 1.7 2002/04/25 21:53:08 bviren Exp $
//
// inter-spline
//
// Package: elbo
//
// Do Cubic Spline interpolation
//
// Contact: bv@bnl.gov
//
// Created on: Thu Oct 25 12:30:38 2001
//
////////////////////////////////////////////////////////////////////////

#ifndef INTER_SPLINE_H
#define INTER_SPLINE_H

#include "InterFunc.h"
#include <vector>

class InterSplineFunc : public InterFunc
{

public:
    typedef enum {
        zero_runout = 0,        // is zero outside ends
        static_runout,          // goes to last value at ends
        linear_runout,          // goes to strait line at ends
        parabolic_runout,       // goes to parabola at ends
        cubic_runout            // goes to cubic at ends
    } SplineType;

    InterSplineFunc(vector<double>& vx, vector<double>& vy, 
                    SplineType s = linear_runout, bool uniform = false);
    InterSplineFunc();
    virtual ~InterSplineFunc();
    virtual void Init(vector<double>& vx, vector<double>& vy);
    virtual void InitUniform(vector<double>& vx, vector<double>& vy, SplineType s);
    virtual void InitNonUniform(vector<double>& vx, vector<double>& vy, SplineType s);
    double operator()(double x);

    void SetMin(double m) { fMin = m; fHaveMin=true; }
    void SetMax(double m) { fMax = m; fHaveMax=true; }

    bool Initialized() { return fInitialized; }

private:

    // Si = Ai(X-Xi)^3 + Bi(X-Xi)^2 + Ci(X-Xi) + Di 
    // D=Y, except len(D)=len(Y)-1.  just store both to be clearer.
    vector<double> A,B,C,D,X,Y;
    bool fInitialized;
    bool fUniform, fHaveMin, fHaveMax;
    double fMin, fMax;
    SplineType fRunout;
};                              // end of class inter-spline

#endif  // INTER-SPLINE_H
