/**
 * \file Vector.cpp
 *
 * Implementation of the Vector class
 */

#include "Common/World/Vector.h"
#include "Common/World/Point.h"
#include <math.h>

void Vector::AdjustAng()
{
	if(ySize == 0)
	{
		if(xSize < 0)
		{
			length = -xSize;
			angle = DegAngle(180);
		}
		else
		{
			length = xSize;
			angle = DegAngle(0);
		}
	}
	else if(xSize == 0)
	{
		if(ySize < 0)
		{
			length = -ySize;
			angle = DegAngle(-90);
		}
		else
		{
			length = ySize;
			angle = DegAngle(90);
		}
	}
	else
	{
		length = sqrtf(xSize * xSize + ySize * ySize);
		angle = RadAngle(atan2f(ySize, xSize));
	}
}

void Vector::AdjustXY()
{
	if(length == 0)
	{
		angle = DegAngle(0);
		xSize = ySize = 0;
		return;
	}
	else if(length < 0)
	{
		length = -length;
		angle += DegAngle(180);
	}
	
	xSize = length * angle.Cos();
	ySize = length * angle.Sin();
}

void Vector::Copy(const Vector &vector)
{
	xSize = vector.xSize; ySize = vector.ySize;
	length = vector.length; angle = vector.angle;
}

//vrati cos uhla dvoch vektorov
float Vector::GetAngle2(Vector vect)
{
	float cit=this->GetX()*vect.GetX()+this->GetY()*vect.GetY();//skalarny sucin
	float men=this->GetLength()*vect.GetLength();
	return cit/men;
}