/****************************************************************************************************

		NaturalSpline.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Pierre-Sylvain
		Date:	3/23/2005

****************************************************************************************************/

#ifndef __NaturalSpline__
#define __NaturalSpline__

#if CP_PRAGMA_ONCE
#pragma once
#endif


struct IShTokenStream;


class TNaturalSpline : public TMCObject
{
public:
	TNaturalSpline();

	void			Clear();
	int32			GetNumPoints();
	const TVector2&	GetPoint(int32 index) const { return fPoints[index]; }
	void			InsertPoint(const TVector2& point);
	void			DeletePoint(int32 index);
	real32			GetValue(real32 x);
	real32			GetMax();
	real32			GetMin();
	void			Validate();

	void			Read(IShTokenStream* stream);
	void			Write(IShTokenStream* stream, int32 token);

protected:
	boolean			IsValid();
	void			Invalidate();
	void			ComputeExtrema();

protected:
	TMCArray<TVector2>	fPoints;
	TMCArray<real32>	fdY2;		// second derivative of y
	real32				fMax;
	real32				fMin;
};


#endif
