//===========================================================================//
// File:	scalar.hpp                                                          //
// Project: MUNGA           Brick: None assigned - coding styles, etc.       //
// Contents: Base information used by all MUNGA source files                 //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc.					  //
//                      PROPRIETARY AND CONFIDENTIAL                         //
//===========================================================================//

#if !defined(SCALAR_HPP)
#	define SCALAR_HPP

#	if !defined(MEMSTRM_HPP)
#		include <memstrm.hpp>
#	endif

#	if !defined(M_PI)
#		define M_PI 3.14159265358979323846
#	endif

	typedef float Scalar;

#	define PI					((Scalar)(M_PI))
#	define PI_OVER_2			((Scalar)(M_PI/2.0))
#	define PI_OVER_3			((Scalar)(M_PI/3.0))
#	define PI_OVER_4			((Scalar)(M_PI/4.0))
#	define PI_OVER_6			((Scalar)(M_PI/6.0))
#	define TWO_PI				((Scalar)(2.0*M_PI))
#	define DEG_PER_RAD		((Scalar)(180.0/M_PI))
#	define RAD_PER_DEG		((Scalar)(M_PI/180.0))

	inline Scalar Lerp(Scalar a, Scalar b, Scalar t)
		{return a*(1.0f - t) + b*t;}
	inline Logical Small_Enough(Scalar x,Scalar e=SMALL)
		{return fabs(x) <= e;}
	inline Logical Close_Enough(Scalar x,Scalar y,Scalar e=SMALL)
		{return fabs(x-y) <= e;}

	int
		Round(Scalar value);



	void
		Find_Roots(
			Scalar a,		// a*x*x + b*x + c = 0
			Scalar b,
			Scalar c,
			Scalar *center,
			Scalar *range
		);

	inline MemoryStream&
		MemoryStream_Read(
			MemoryStream* stream,
			Scalar *output
		)
			{return stream->ReadBytes(output, sizeof(*output));}
	inline MemoryStream&
		MemoryStream_Write(
			MemoryStream* stream,
			const Scalar *input
		)
			{return stream->WriteBytes(input, sizeof(*input));}

	void
		Convert_From_Ascii(const char *str, Scalar *value);


#endif

