#include "Vec2d.h"
Vec2d::Vec2d( float pX, float pY )
{
x = pX;
y = pY;
}
Vec2d::Vec2d(void)
{
x = 0;
y = 0;
}
void Vec2d::print()
{
printf( "%f %f\n", x,y );
}
void Vec2d::operator=(Vec2d B)
{
x = B.x;
y = B.y;
}
Vec2d Vec2d::operator+(Vec2d B)
{
Vec2d C;
C.x = x + B.x;
C.y = y + B.y;
return C;
}
Vec2d Vec2d::operator-(Vec2d B)
{
Vec2d C;
C.x = x - B.x;
C.y = y - B.y;
return C;
}
Vec2d Vec2d::operator*(float M)
{
Vec2d C;
C.x = x * M;
C.y = y * M;
return C;
}
Vec2d Vec2d::operator/(float M)
{
//don't divide by zero
Vec2d C;
if(M == 0) { C.x = C.y = 0; return C; }
C.x = x / M;
C.y = y / M;
return C;
}
//Calculate the length of a vector using Pythagorean theorem and return the resulting float.
float Vec2d::getLength(float a, float b)
{
float len = pow(a,2) + pow(b,2);
return sqrt (len);
}