Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Common.h"
- #include <algorithm>
- using namespace std;
- // Этот файл сдаётся на проверку
- // Здесь напишите реализацию необходимых классов-потомков `IShape`
- class Polygon : public IShape{
- public:
- void SetPosition(Point p) override {
- point = move(p);
- }
- Point GetPosition() const override {
- return point;
- }
- void SetSize(Size s) override {
- size = move(s);
- }
- Size GetSize() const override {
- return size;
- }
- void SetTexture(shared_ptr<ITexture> texture) override {
- itexture = move(texture);
- }
- ITexture* GetTexture() const override {
- return itexture.get();
- }
- unique_ptr<IShape> Clone() const override {
- return CloneFigure();
- }
- void Draw(Image& image) const override {
- DrawFigure(image);
- }
- protected:
- Point point;
- Size size;
- shared_ptr<ITexture> itexture;
- virtual void DrawFigure(Image& image) const =0;
- virtual unique_ptr<IShape> CloneFigure() const = 0;
- };
- class Ellipse :public Polygon {
- void DrawFigure(Image& image) const override {
- for (int y = point.y; y < point.y + size.height; y++) {
- for (int x = point.x; x < point.x + size.width; x++) {
- if (y < image.size() && x<image.begin()->size()) {//проверка, что фигура не выйдет за границу изображения
- if (GetTexture() && y - point.y < itexture->GetSize().height && x - point.x < itexture->GetSize().width) {
- if (IsPointInEllipse({ x - point.x,y - point.y }, size))
- image[y][x] = GetTexture()->GetImage()[y - point.y][x - point.x];
- }
- else {
- image[y][x] = '.';
- }
- }
- }
- }
- }
- unique_ptr<IShape> CloneFigure() const {
- Ellipse ellipse;
- ellipse.SetPosition(point);
- ellipse.SetSize(size);
- ellipse.SetTexture(itexture);
- return make_unique<Ellipse>(ellipse);
- }
- };
- class Rectangle : public Polygon {
- void DrawFigure(Image& image) const override {
- for (int y = point.y; y < point.y + size.height; y++) {
- for (int x = point.x; x < point.x + size.width; x++) {
- if (y < image.size() && x < image.begin()->size()) {//проверка, что фигура не выйдет за границу изображения
- if (GetTexture() && y - point.y < itexture->GetSize().height && x - point.x < itexture->GetSize().width) {
- image[y][x] = GetTexture()->GetImage()[y - point.y][x - point.x];
- }
- else {
- image[y][x] = '.';
- }
- }
- }
- }
- }
- unique_ptr<IShape> CloneFigure() const {
- Rectangle rec;
- rec.SetPosition(point);
- rec.SetSize(size);
- rec.SetTexture(itexture);
- return make_unique<Rectangle>(rec);
- }
- };
- // Напишите реализацию функции
- unique_ptr<IShape> MakeShape(ShapeType shape_type) {
- if (shape_type == ShapeType::Rectangle) {
- return make_unique<Rectangle>();
- }
- else if (shape_type == ShapeType::Ellipse) {
- return make_unique<Ellipse>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement