/*************************************************************************
 *
 *  $RCSfile: bxdintpo.hxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000/09/18 16:30:08 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _BXD_INTERPOLATOR_HXX
#define _BXD_INTERPOLATOR_HXX

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif

#ifndef _SV_COLOR_HXX
#include <vcl/color.hxx>
#endif

#ifndef _SVX_VECTOR3D_HXX
#include <goodies/vector3d.hxx>
#endif

#ifndef _SV_VECTOR2D_HXX
#include <vcl/vector2d.hxx>
#endif

/*************************************************************************
|*
|* Standard-Interpolierer
|*
\************************************************************************/

class BxdInterpolator
{
private:
	double		fPos;
	double		fInc;

public:
	BxdInterpolator(long nS, long nE, long nSteps)
	:	fPos(nSteps ? ((double)nS) + 0.5 : ((double)nE) + 0.5),
	fInc((double)(nE - nS)/(double)(nSteps == 0 ? 1 : nSteps)) {}

	BxdInterpolator(UINT8 nS, UINT8 nE, long nSteps)
	:	fPos(nSteps ? ((double)nS) + 0.5 : ((double)nE) + 0.5),
		fInc((double)(nE - nS)/(double)(nSteps == 0 ? 1 : nSteps)) {}

	BxdInterpolator(double fS, double fE, long nSteps)
	:	fPos(nSteps ? fS : fE),
		fInc((fE - fS)/(double)(nSteps == 0 ? 1 : nSteps)) {}

	BxdInterpolator() {}

	void Increment() { fPos += fInc; }

	void Load(long nS, long nE, long nSteps)
	{
		fPos = (nSteps) ? ((double)nS) + 0.5 : ((double)nE) + 0.5;
		fInc = (double)(nE - nS)/(double)(nSteps == 0 ? 1 : nSteps);
	}

	void Load(UINT8 nS, UINT8 nE, long nSteps)
	{
		fPos = (nSteps) ? ((double)nS) + 0.5 : ((double)nE) + 0.5;
		fInc = (double)(nE - nS)/(double)(nSteps == 0 ? 1 : nSteps);
	}

	void Load(double fS, double fE, long nSteps)
	{
		fPos = (nSteps) ? fS : fE;
		fInc = (fE - fS)/(double)(nSteps == 0 ? 1 : nSteps);
	}

	long GetLongValue() { return (long)fPos; }
	UINT32 GetUINT32Value() { return (UINT32)fPos; }
	UINT8 GetUINT8Value() { return (UINT8)fPos; }
	double GetDoubleValue() { return fPos; }
	double GetStepSize() { return fInc; }
};

/*************************************************************************
|*
|* Interpolierer fuer Color
|*
\************************************************************************/

class BxdColorInterpolator
{
private:
	BxdInterpolator			aRed;
	BxdInterpolator			aGreen;
	BxdInterpolator			aBlue;
	UINT8					nTransparency;

public:
	BxdColorInterpolator(Color aS, Color aE, long nSteps)
	:	aRed(aS.GetRed(), aE.GetRed(), nSteps),
		aGreen(aS.GetGreen(), aE.GetGreen(), nSteps),
		aBlue(aS.GetBlue(), aE.GetBlue(), nSteps),
		nTransparency(aS.GetTransparency()) {}

	BxdColorInterpolator() {}

	void Increment()
	{
		aRed.Increment();
		aGreen.Increment();
		aBlue.Increment();
	}

	void Load(Color aS, Color aE, long nSteps)
	{
		aRed.Load(aS.GetRed(), aE.GetRed(), nSteps);
		aGreen.Load(aS.GetGreen(), aE.GetGreen(), nSteps);
		aBlue.Load(aS.GetBlue(), aE.GetBlue(), nSteps);
		nTransparency = aS.GetTransparency();
	}

	Color GetColorValue()
	{
		return Color(nTransparency,
			aRed.GetUINT8Value(),
			aGreen.GetUINT8Value(),
			aBlue.GetUINT8Value());
	}
};

/*************************************************************************
|*
|* Interpolierer fuer Vector3D
|*
\************************************************************************/

class B3dVectorInterpolator
{
private:
	BxdInterpolator			aX;
	BxdInterpolator			aY;
	BxdInterpolator			aZ;

public:
	B3dVectorInterpolator(Vector3D& rS, Vector3D& rE, long nSteps)
	:	aX(rS.X(), rE.X(), nSteps),
		aY(rS.Y(), rE.Y(), nSteps),
		aZ(rS.Z(), rE.Z(), nSteps) {}

	B3dVectorInterpolator()	{}

	void Increment() { aX.Increment(); aY.Increment(); aZ.Increment(); }

	void Load(Vector3D& rS, Vector3D& rE, long nSteps)
	{
		aX.Load(rS.X(), rE.X(), nSteps);
		aY.Load(rS.Y(), rE.Y(), nSteps);
		aZ.Load(rS.Z(), rE.Z(), nSteps);
	}

	void GetVector3DValue(Vector3D& rVec)
	{
		rVec.X() = aX.GetDoubleValue();
		rVec.Y() = aY.GetDoubleValue();
		rVec.Z() = aZ.GetDoubleValue();
	}
};

/*************************************************************************
|*
|* Interpolierer fuer Vector2D
|*
\************************************************************************/

class B2dVectorInterpolator
{
private:
	BxdInterpolator			aX;
	BxdInterpolator			aY;

public:
	B2dVectorInterpolator(Vector2D& rS, Vector2D& rE, long nSteps)
	:	aX(rS.X(), rE.X(), nSteps),
		aY(rS.Y(), rE.Y(), nSteps) {}

	B2dVectorInterpolator()	{}

	void Increment() { aX.Increment(); aY.Increment(); }

	void Load(Vector2D& rS, Vector2D& rE, long nSteps)
	{
		aX.Load(rS.X(), rE.X(), nSteps);
		aY.Load(rS.Y(), rE.Y(), nSteps);
	}

	void GetVector2DValue(Vector2D& rVec)
	{
		rVec.X() = aX.GetDoubleValue();
		rVec.Y() = aY.GetDoubleValue();
	}
};

#endif          // _BXD_INTERPOLATOR_HXX
