#include "polygon_2d.h" #include //Constructor Polygon_2D::Polygon_2D () { *this += Point_2D(); *this += Point_2D(); *this += Point_2D(); } //Constructor from one line and one point Polygon_2D::Polygon_2D (const Line_2D &l, const Point_2D &p) { *this += l.getStartPoint(); *this += l.getEndPoint(); *this += p; } //Constructor from one point and one line Polygon_2D::Polygon_2D (const Point_2D &p, const Line_2D &l) { *this += p; *this += l.getStartPoint(); *this += l.getEndPoint(); } //Constructor from two lines Polygon_2D::Polygon_2D (const Line_2D &l1, const Line_2D &l2) { *this += l1.getStartPoint(); *this += l1.getEndPoint(); *this += l2.getStartPoint(); *this += l2.getEndPoint(); } //Get list of points std::list Polygon_2D::getPoints() const { return m_lstPoints; } //Overload Polygon_2D + Point_2D operator Polygon_2D Polygon_2D::operator+(const Point_2D &p) { Polygon_2D _copy(*this); _copy += p; return _copy; } //Overload Polygon_2D + Line_2D operator Polygon_2D Polygon_2D::operator+(const Line_2D &l) { Polygon_2D _copy(*this); _copy += l.getStartPoint(); _copy += l.getEndPoint(); return _copy; } //Overload Polygon_2D + Polygon_2D operator Polygon_2D Polygon_2D::operator+(const Polygon_2D &poly) { std::list _lstPoints = poly.getPoints(); std::list::iterator _it = _lstPoints.begin(); Polygon_2D _copy(*this); while(_it != _lstPoints.end()) { _copy += *_it; _it++; } return _copy; } //Overload Polygon_2D += Point_2D operator Polygon_2D& Polygon_2D::operator+=(const Point_2D &p) { m_lstPoints.push_back(p); return *this; } //Overload Polygon_2D += Line_2D operator Polygon_2D& Polygon_2D::operator+=(const Line_2D &l) { *this += l.getStartPoint(); *this += l.getEndPoint(); return *this; } //Overload Polygon_2D += Polygon_2D operator Polygon_2D& Polygon_2D::operator+=(const Polygon_2D &poly) { std::list _lstPoints = poly.getPoints(); std::list::iterator _it = _lstPoints.begin(); while(_it != _lstPoints.end()) { *this += *_it; _it++; } return *this; } ////OUTSIDE OF CLASS //Overload Line_2D + Line_2D operator Polygon_2D operator+(const Line_2D &l1, const Line_2D &l2) { return Polygon_2D(l1, l2); } //Overload Line_2D + Point_2D operator Polygon_2D operator+(const Line_2D &l, const Point_2D &p) { return Polygon_2D(l, p); } //Overload Point_2D + Line_2D operator Polygon_2D operator+(const Point_2D &p, const Line_2D &l) { return Polygon_2D(p, l); } //Overload Point_2D + Polygon_2D operator Polygon_2D operator+(const Point_2D &p, const Polygon_2D &poly) { Polygon_2D _copy(poly); _copy += p; return _copy; } //Overload Line_2D + Polygon_2D operator Polygon_2D operator+(const Line_2D &l, const Polygon_2D &poly) { Polygon_2D _copy(poly); _copy += l.getStartPoint(); _copy += l.getEndPoint(); return _copy; } //Overload << operator std::ostream &operator<<(std::ostream &os, const Polygon_2D &poly) { std::list _lstPoints = poly.getPoints(); std::list::iterator _it = _lstPoints.begin(); os << "("; if (!_lstPoints.empty()) { os << *_it++; while(_it != _lstPoints.end()) { os << ", " << *_it; _it++; } } return os << ")"; }