/*********************************************************************************
 JPlotFunctionBase.h
 
	Interface for the JPlotFunctionBase class.
 
	Copyright @ 1997 by Glenn W. Bach. All rights reserved.

 ********************************************************************************/
 
#ifndef _H_JPlotFunctionBase
#define _H_JPlotFunctionBase

#include <JPlotDataBase.h>
#include <JArray.h>

class JString;
class J2DPlotWidget;

class JPlotFunctionBase : public JPlotDataBase
{
public:

	JPlotFunctionBase(const PlotDataType type, J2DPlotWidget* plot,
					  const JFloat xMin, const JFloat xMax);

	virtual ~JPlotFunctionBase();

	virtual void	GetElement(const JIndex index, J2DDataPoint* data) const;

	virtual void		GetXRange(JFloat* min, JFloat* max) const;
	virtual JBoolean	GetYRange(const JFloat xMin, const JFloat xMax,
								  JFloat* yMin, JFloat* yMax) const;

	virtual JString		GetFunctionString() const = 0;
	virtual JBoolean	GetYValue(const JFloat x, JFloat* y) const = 0;

	void	SetXRange(const JFloat xMin, const JFloat xMax);

protected:

	void	UpdateFunction();
	void	UpdateFunction(const JFloat xmin, const JFloat xmax,
						   const JSize stepCount);

	virtual void	Receive(JBroadcaster* sender, const Message& message);

private:

	struct Point
	{
		JFloat x,y;
	};

private:

	J2DPlotWidget*	itsPlot;

	// values returned by GetXRange()

	JFloat	itsXMin;
	JFloat	itsXMax;

	// values returned by GetElement()

	JArray<Point>*	itsValues;
};


/*********************************************************************************
 SetXRange

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

inline void
JPlotFunctionBase::SetXRange
	(
	const JFloat min, 
	const JFloat max
	)
{
	itsXMin = min;
	itsXMax = max;
}

#endif
