#include "Point.h"


Point::Point(int a, int b)
    : x(a), y(b)
{
    // a + 3
    // a + Point(3) 3 est converti en un Point
    //Point(3) <==> Point(3, 0)
    if (b == 0)
        cout << "constructeur de conversion" << endl;
}

Point::~Point()
{

}

Point::Point(const Point& other)
    : x(other.x), y(other.y)
{

}

Point& Point::operator=(const Point& rhs)
{
    if (this == &rhs)
        return *this; // handle self assignment p.operator(p)

    //assignment operator p2.operator(p1)
    this->x = rhs.x;
    this->y = rhs.y;

    return *this; // p2
}


 Point Point::operator+ (const Point & p) const
 {
    /*
    Point somme;

    somme.x = this->x + p.x;
    somme.y = this->y + p.y;

    return somme;
    */

    return Point(this->x + p.x, this->y + p.y );
 }

Point & Point::operator+= (const Point & p)
{
/*
    Point somme;
    somme = *this + p;

    *this = somme;
    return *this;
*/
/*
     *this = *this + p;
      return *this;
*/
/*
    return (*this = *this + p);
*/

    this->x += p.x;
    this->y += p.y;
    return *this;
}

/**
SI FRIEND
ostream & operator<< (ostream & os, const Point & p)
{
    os << "(" << p.x << "," << p.y <<")";
    return os;
}
*/

/**
FONCTION EXTERNE
*/
ostream & operator<< (ostream & os, const Point & p)
{
    os << "(" << p.Getx() << "," << p.Gety() <<")";
    return os;
}

/*
Point operator+ (int x, const Point & p)
{
    return Point(x + p.x, p.y );
}

Point operator+ (const Point & p, int x)
{
    return Point(p.x + x, p.y );
}

*/
