//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Bozhidar Stanchev

#pragma once

namespace VWFC
{
	namespace Math
	{
		class VWCubicInterpolation
		{
			public:
				//construction
								VWCubicInterpolation( const VWCubicInterpolation& cubicBezier );

								VWCubicInterpolation( const VWPoint2D&	point0, 
													  const VWPoint2D&	point1, 
													  const VWPoint2D&	point2, 
													  const VWPoint2D&	point3 );

				void			Set( const VWPoint2D& point0, 
									 const VWPoint2D& point1, 
									 const VWPoint2D& point2, 
									 const VWPoint2D& point3 );

				VWPoint2D		Pt0()		const;
				VWPoint2D		Pt1()		const;
				VWPoint2D		Pt2()		const;
				VWPoint2D		Pt3()		const;

				VWPoint2D		StartPt()	const;
				VWPoint2D		EndPt()		const;

				bool			PtOn( double tX, double tY,
									  const VWPoint2D& prevAddedPt, const double& addInterval,
									  const VWPoint2D& nextPt, VWPoint2D& result );

			private:
				bool			SolveLSystem( double LSystem[4][5], double& a0, double& a1, double& a2, double& a3 );
				bool			FindPolynomialXtoY( double& a0, double& a1, double& a2, double& a3 );
				bool			FindPolynomialYtoX( double& a0, double& a1, double& a2, double& a3 );
				void			FindIntervals();

			private:
				VWPoint2D		fPoint0;
				VWPoint2D		fPoint1;
				VWPoint2D		fPoint2;
				VWPoint2D		fPoint3;
				// x limits
				double			fMinX;
				double			fMaxX;
				// y limits
				double			fMinY;
				double			fMaxY;
		};
	}
}