#include "Point2d.h"
#include <math.h>
#include "MemoryManager/debugNew.h"

Point2D::Point2D(void){
	x = 0.0f;
	y = 0.0f;
}

Point2D::Point2D(float x, float y){
	this->x = x;
	this->y = y;
}
Point2D::Point2D(int x, int y){
	this->x = (float)x;
	this->y = (float)y;
}
Point2D::~Point2D(){
}
float Point2D::getX()const{
	return x;
}
void Point2D::setX(float x){
	this->x = x;
}
float Point2D::getY()const{
	return y;
}
void Point2D::setY(float y){
	this->y = y;
}
void Point2D::setCoord(float x,float y){
	this->x = x;
	this->y = y;
}
void Point2D::setCoord(int x,int y){
	this->x = (float)x;
	this->y = (float)y;
}

bool Point2D::operator==(const Point2D& p)const{
	return x == p.x && y == p.y;
}

Point2D Point2D::operator+(const Point2D& p)const{
	return Point2D(x+p.x,y+p.y);
}

Point2D Point2D::operator-(const Point2D& p)const{
	return Point2D(x-p.x,y-p.y);
}

Point2D Point2D::operator*(const float factor)const{
	return Point2D(x*factor,y*factor);
}

Point2D& Point2D::operator+=(const Point2D& p){
	x+= p.x;
	y+= p.y;
	return *this;
}

Point2D& Point2D::operator*=(const float factor){
	x*=factor;
	y*=factor;
	return *this;
}

bool Point2D::equals(const Point2D& p)const{
	return x == p.x && y == p.y;
}

float Point2D::getLength()const{
	return sqrt(x*x+y*y);
}

void Point2D::normalise(){
	float length = sqrt(x*x+y*y);
	if (length != 0){
		x/= length;
		y/= length;
	}
}

float Point2D::getAngle(const Point2D& destination){
	float vectX = destination.x - x;
	float vectY = destination.y - y;
	if (vectX == 0 && vectY == 0){
		return 0.0f;
	}
	float length = sqrt(vectX*vectX + vectY*vectY);
	if (vectY < 0){
		return -acos((float)vectX / length)*(180 / 3.141f);
	}else{
		return acos((float)vectX / length)*(180 / 3.141f);
	}
}

std::string Point2D::toString(){
	std::string ret;
	ret = "Le point a pour coordonnees : ";
	ret += Converter::floatToString(x);
	ret += ", ";
	ret += Converter::floatToString(y);

	return ret;
}

