#include "polygon_3d.h" #include //Constructor Polygon_3D::Polygon_3D () { *this += Point_3D(); *this += Point_3D(); *this += Point_3D(); } //Constructor from one line and one point Polygon_3D::Polygon_3D (const Line_3D &l, const Point_3D &p) { *this += l.getStartPoint(); *this += l.getEndPoint(); *this += p; } //Constructor from one point and one line Polygon_3D::Polygon_3D (const Point_3D &p, const Line_3D &l) { *this += p; *this += l.getStartPoint(); *this += l.getEndPoint(); } //Constructor from two lines Polygon_3D::Polygon_3D (const Line_3D &l1, const Line_3D &l2) { *this += l1.getStartPoint(); *this += l1.getEndPoint(); *this += l2.getStartPoint(); *this += l2.getEndPoint(); } std::list Polygon_3D::getPoints() const { return m_lstPoints; } //Overload Polygon_3D + Point_3D operator Polygon_3D Polygon_3D::operator+(const Point_3D &p) { Polygon_3D _copy = Polygon_3D(*this); _copy += p; return _copy; } //Overload Polygon_3D + Line_3D operator Polygon_3D Polygon_3D::operator+(const Line_3D &l) { Polygon_3D _copy(*this); _copy += l.getStartPoint(); _copy += l.getEndPoint(); return _copy; } //Overload Polygon_3D + Polygon_3D operator Polygon_3D Polygon_3D::operator+(const Polygon_3D &poly) { std::list _lstPoints = poly.getPoints(); std::list::iterator _it = _lstPoints.begin(); Polygon_3D _copy(*this); while(_it != _lstPoints.end()) { _copy += *_it; _it++; } return _copy; } //Overload Polygon_3D += Point_3D operator Polygon_3D& Polygon_3D::operator+=(const Point_3D &p) { m_lstPoints.push_back(p); return *this; } //Overload Polygon_3D += Line_3D operator Polygon_3D& Polygon_3D::operator+=(const Line_3D &l) { *this += l.getStartPoint(); *this += l.getEndPoint(); return *this; } //Overload Polygon_3D += Polygon_3D operator Polygon_3D& Polygon_3D::operator+=(const Polygon_3D &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_3D + Point_3D operator Polygon_3D operator+(const Line_3D &l, const Point_3D &p) { return Polygon_3D(l, p); } //Overload Point_3D + Line_3D operator Polygon_3D operator+(const Point_3D &p, const Line_3D &l) { return Polygon_3D(p, l); } //Overload Line_3D + Line_3D operator Polygon_3D operator+(const Line_3D &l1, const Line_3D &l2) { return Polygon_3D(l1, l2); } //Overload Point_3D + Polygon_3D operator Polygon_3D operator+(const Point_3D &p, const Polygon_3D &poly) { Polygon_3D _copy(poly); _copy += p; return _copy; } //Overload Line_3D + Polygon_3D operator Polygon_3D operator+(const Line_3D &l, const Polygon_3D &poly) { Polygon_3D _copy(poly); _copy += l.getStartPoint(); _copy += l.getEndPoint(); return _copy; } //Overload << operator std::ostream &operator<<(std::ostream &os, const Polygon_3D &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 << ")"; }