//	TwoFloats.h - Simple struct containing two floats.
//  ----------------------------------------------------------------------------

#ifndef TWOFLOATS_H_
#define TWOFLOATS_H_

#include <cmath>

///	Simple struct containing two floats.
struct TwoFloats
{
	float x;
	float y;

	///	Default constructor.
	TwoFloats()
	{
		x = y = 0.0f;
	}

	///	Constructor, all members set to val.
	TwoFloats(float val)
	{
		x = y = val;
	}

	///	Constructor.
	TwoFloats(float xVal, float yVal)
	{
		x = xVal;
		y = yVal;
	}

	///	Assignment operator.
	TwoFloats& operator=(const TwoFloats& op2)
	{
		x = op2.x;
		y = op2.y;
		return *this;
	}

	///	Assignment operator (assigns all members the value of val).
	TwoFloats& operator=(float val)
	{
		x = val;
		y = val;
		return *this;
	}

	///	Addition operator.
	TwoFloats operator+(const TwoFloats& op2)
	{
		TwoFloats retval;

		retval.x = x + op2.x;
		retval.y = y + op2.y;

		return retval;
	}

	///	Subtraction operator.
	TwoFloats operator-(const TwoFloats& op2)
	{
		TwoFloats retval;

		retval.x = x - op2.x;
		retval.y = y - op2.y;

		return retval;
	}

	///	Multiplication operator.
	TwoFloats operator*(const TwoFloats& op2)
	{
		TwoFloats retval;

		retval.x = x * op2.x;
		retval.y = y * op2.y;

		return retval;
	}

	///	Multiplication operator (float).
	TwoFloats operator*(float val)
	{
		TwoFloats retval;

		retval.x = x * val;
		retval.y = y * val;

		return retval;
	}

	///	Addition assignment operator.
	TwoFloats& operator+=(const TwoFloats& op2)
	{
		x += op2.x;
		y += op2.y;

		return *this;
	}

	///	Subtraction assignment operator.
	TwoFloats& operator-=(const TwoFloats& op2)
	{
		x -= op2.x;
		y -= op2.y;

		return *this;
	}

	///	Multiplication assignment operator.
	TwoFloats& operator*=(const TwoFloats& op2)
	{
		x *= op2.x;
		y *= op2.y;

		return *this;
	}

	///	Multiplication assignment operator.
	TwoFloats& operator*=(float op2)
	{
		x *= op2;
		y *= op2;

		return *this;
	}

	///	Normalises the vector.
	void normalise()
	{
		float dist = 1.0f/sqrtf((x*x)+(y*y));

		x *= dist;
		y *= dist;
	};

	///	Returns the dot product with another TwoFloats.
	float dot(const TwoFloats& other)
	{
		return (x*other.x)+(y*other.y);
	};

	///	Equality operator.
	bool operator==(const TwoFloats& op2)
	{
		return (x==op2.x)&&(y==op2.y);
	}

	///	Inequality operator.
	bool operator!=(const TwoFloats& op2)
	{
		return (x!=op2.x)||(y!=op2.y);
	}

	///	Returns the distance between two TwoFloats.
	float getDistance(const TwoFloats& op2) const
	{
		float tempX = op2.x - x;
		float tempY = op2.y - y;

		return sqrtf((tempX*tempX) + (tempY*tempY));
	}

	friend TwoFloats operator*(float op1, const TwoFloats& op2);
};

#endif
