#include <math.h>
#include "vector.h"

float Vdist(vector *v1, vector *v2)
{
    float r = sqrt((v2->x - v1->x)*(v2->x - v1->x) + (v2->y - v1->y)*(v2->y - v1->y));
    return r;
}

void Vadd(vector *v1, vector *v2, vector *v)
{
    v->x = v1->x + v2->x;
    v->y = v1->y + v2->y;
}

void Vsub(vector *v1, vector *v2, vector *v)
{
    v->x = v1->x - v2->x;
    v->y = v1->y - v2->y;
}

void Vscale(vector *v1, vector *v, float z)
{
    v->x = v1->x * z;
    v->y = v1->y * z;
}

void Vneg(vector *v1, vector *v)
{
    v->x = - v1->x;
    v->y = - v1->y;
}

void Vrotate (vector *v1, vector *v, float r)
{
    v->x = v1->x * cos(r) + v1->y * sin(r);
    v->y = -v1->x * sin(r) + v1->y * cos(r);
}

void Vset (vector *v1, vector *v2)
{
    v1->x = v2->x;
    v1->y = v2->y;
}

void Vnormalize (vector *v)
{
	float r = sqrt(v->x * v->x + v->y * v->y);
	if (r!=0)
	{
		v->x /= r;
		v->y /= r;
	}
}
