Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
1.8 kB
2
Indexable
Never
#include "polygon.h"
#include <iostream>
#include <stdexcept>
using namespace std;



Polygon::Polygon(const Point *p1, const Point *p2, const Point *p3)
{
    this->pts.push_back(new Point(*p1));
    this->pts.push_back(new Point(*p2));
    this->pts.push_back(new Point(*p3));
}

Polygon::Polygon(const Point& p1, const Point& p2, const Point& p3)
{
    this->pts.push_back(new Point(p1));
    this->pts.push_back(new Point(p2));
    this->pts.push_back(new Point(p3));
}

Polygon::Polygon(vector<Point>& pts)
{
    for (Point pt : pts)
    {
        this->pts.push_back(new Point(pt));
    }
}

Polygon::Polygon(Polygon &src)
{
    this->pts.clear();
    for (Point *pt : src.pts)
    {
        this->pts.push_back(new Point(*pt));
    }
}

Polygon::~Polygon()
{
    for (auto pt: this->pts)
    {
        delete pt;
    }
}

void Polygon::ShowPolygon(void)
{
    cout << "[";
    for (auto pt : this->pts)
    {
        cout << *pt << endl;
    }
    cout << "]" << endl;
}

void Polygon::AddPoint(const Point *pt)
{
    this->pts.push_back(new Point(*pt));
}

void Polygon::AddPoint(const Point & pt)
{
    this->pts.push_back(new Point(pt));
}

Point &Polygon::operator[](const int index)
{
    if (index >= pts.size())
    {
        throw std::out_of_range("Index Out of Range");
    }

    return *pts[index];
}

void Polygon::Move(int x, int y)
{
    for (auto pt : this->pts)
    {
        pt->Move(x, y);
    }
}
void Polygon::MoveX(int x)
{
    for (auto pt : this->pts)
    {
        pt->MoveX(x);
    }
}
void Polygon::MoveY(int y)
{
    for (auto pt : this->pts)
    {
        pt->MoveY(y);
    }
}

void Polygon::Rotate(int angle)
{
    for (auto pt : this->pts)
    {
        pt->Rotate(angle);
    }
}
void Polygon::Rotate3D(int x, int y, int z)
{
    for (auto pt : this->pts)
    {
        pt->Rotate3D(x, y, z);
    }
}
Leave a Comment