-
Notifications
You must be signed in to change notification settings - Fork 52
lyatshuk.gleb/T4 #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gleblv3011-commits
wants to merge
22
commits into
ov-ale:main
Choose a base branch
from
gleblv3011-commits:lyatshuk.gleb/T4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
lyatshuk.gleb/T4 #61
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5b04332
Add T4 implementation for lyatshuk.gleb
gleblv3011-commits 239ec50
Remove binaries and add gitignore
gleblv3011-commits 51f4c63
Remove trailing whitespaces in T4 files
gleblv3011-commits ae08bb0
lyatshuk.gleb/T4
gleblv3011-commits b6c1f81
lyatshuk.gleb/T4 - remove trailing whitespaces in headers
gleblv3011-commits 796c030
lyatshuk.gleb/T4 - update main.cpp
gleblv3011-commits 5686565
lyatshuk.gleb/T4 - remove trailing whitespace in main.cpp
gleblv3011-commits 61c143a
lyatshuk.gleb/T4 - fix corrupted main.cpp
gleblv3011-commits f3c2966
lyatshuk.gleb/T4 - trigger CI
gleblv3011-commits 037b1d4
lyatshuk.gleb/T4 - remove trailing whitespace
gleblv3011-commits d15d081
lyatshuk.gleb/T4 - add command line arguments handling
gleblv3011-commits 3df3457
lyatshuk.gleb/T4 - remove trailing whitespace
gleblv3011-commits 5d5bbab
lyatshuk.gleb/T4 - show shapes without scaling by default
gleblv3011-commits c2ba0ed
lyatshuk.gleb/T4 - remove trailing whitespace
gleblv3011-commits 67f6127
lyatshuk.gleb/T4 - remove trailing whitespace
gleblv3011-commits 816fc4f
lyatshuk.gleb/T4
gleblv3011-commits 01c1ef9
lyatshuk.gleb/T4
gleblv3011-commits 49a0b16
lyatshuk.gleb/T4
gleblv3011-commits e0fb0a3
lyatshuk.gleb/T4
gleblv3011-commits 3404d5e
lyatshuk.gleb/T4
gleblv3011-commits 0773d4b
lyatshuk.gleb/T4 - set PI to 3.14
gleblv3011-commits 7a22d0c
lyatshuk.gleb/T4
gleblv3011-commits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Compiled files | ||
| *.exe | ||
| *.obj | ||
| *.o | ||
| *.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #include "composite_shape.h" | ||
| #include <iostream> | ||
| #include <limits> | ||
| #include <iomanip> | ||
| #include <algorithm> | ||
|
|
||
| void CompositeShape::addShape(std::unique_ptr<Shape> shape) { | ||
| shapes.push_back(std::move(shape)); | ||
| } | ||
|
|
||
| double CompositeShape::getArea() const { | ||
| double totalArea = 0; | ||
| for (const auto& shape : shapes) { | ||
| totalArea += shape->getArea(); | ||
| } | ||
| return totalArea; | ||
| } | ||
|
|
||
| Point CompositeShape::getCenter() const { | ||
| if (shapes.empty()) { | ||
| return Point(0, 0); | ||
| } | ||
|
|
||
| double minX = std::numeric_limits<double>::max(); | ||
| double minY = std::numeric_limits<double>::max(); | ||
| double maxX = std::numeric_limits<double>::lowest(); | ||
| double maxY = std::numeric_limits<double>::lowest(); | ||
|
|
||
| double shapeMinX, shapeMinY, shapeMaxX, shapeMaxY; | ||
| for (const auto& shape : shapes) { | ||
| shape->getBounds(shapeMinX, shapeMinY, shapeMaxX, shapeMaxY); | ||
| minX = std::min(minX, shapeMinX); | ||
| minY = std::min(minY, shapeMinY); | ||
| maxX = std::max(maxX, shapeMaxX); | ||
| maxY = std::max(maxY, shapeMaxY); | ||
| } | ||
|
|
||
| return Point((minX + maxX) / 2, (minY + maxY) / 2); | ||
| } | ||
|
|
||
| void CompositeShape::move(double dx, double dy) { | ||
| for (auto& shape : shapes) { | ||
| shape->move(dx, dy); | ||
| } | ||
| } | ||
|
|
||
| void CompositeShape::scale(double factor) { | ||
| Point compositeCenter = getCenter(); | ||
|
|
||
| for (auto& shape : shapes) { | ||
| Point shapeCenter = shape->getCenter(); | ||
|
|
||
| double dx = shapeCenter.x - compositeCenter.x; | ||
| double dy = shapeCenter.y - compositeCenter.y; | ||
|
|
||
| shape->move(dx * (factor - 1), dy * (factor - 1)); | ||
| shape->scale(factor); | ||
| } | ||
| } | ||
|
|
||
| std::string CompositeShape::getName() const { | ||
| return "COMPOSITE"; | ||
| } | ||
|
|
||
| void CompositeShape::getBounds(double& minX, double& minY, double& maxX, double& maxY) const { | ||
| if (shapes.empty()) { | ||
| minX = minY = maxX = maxY = 0; | ||
| return; | ||
| } | ||
|
|
||
| double shapeMinX, shapeMinY, shapeMaxX, shapeMaxY; | ||
| shapes[0]->getBounds(minX, minY, maxX, maxY); | ||
|
|
||
| for (size_t i = 1; i < shapes.size(); ++i) { | ||
| shapes[i]->getBounds(shapeMinX, shapeMinY, shapeMaxX, shapeMaxY); | ||
| minX = std::min(minX, shapeMinX); | ||
| minY = std::min(minY, shapeMinY); | ||
| maxX = std::max(maxX, shapeMaxX); | ||
| maxY = std::max(maxY, shapeMaxY); | ||
| } | ||
| } | ||
|
|
||
| void CompositeShape::printInfo() const { | ||
| std::cout << std::fixed << std::setprecision(2); | ||
| std::cout << "[" << getName() << ", (" << getCenter().x << ", " << getCenter().y << "), " << getArea() << ":" << std::endl; | ||
|
|
||
| for (const auto& shape : shapes) { | ||
| Point center = shape->getCenter(); | ||
| std::cout << " " << shape->getName() << ", (" << center.x << ", " << center.y << "), " << shape->getArea() << std::endl; | ||
| } | ||
|
|
||
| std::cout << "]" << std::endl; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #ifndef COMPOSITE_SHAPE_H | ||
| #define COMPOSITE_SHAPE_H | ||
|
|
||
| #include "shape.h" | ||
| #include <vector> | ||
| #include <memory> | ||
|
|
||
| class CompositeShape : public Shape { | ||
| private: | ||
| std::vector<std::unique_ptr<Shape>> shapes; | ||
|
|
||
| Point calculateBoundingBoxCenter() const; | ||
|
|
||
| public: | ||
| void addShape(std::unique_ptr<Shape> shape); | ||
|
|
||
| double getArea() const override; | ||
| Point getCenter() const override; | ||
| void move(double dx, double dy) override; | ||
| void scale(double factor) override; | ||
| std::string getName() const override; | ||
| void getBounds(double& minX, double& minY, double& maxX, double& maxY) const override; | ||
|
|
||
| void printInfo() const; | ||
| }; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #include <iostream> | ||
| #include <iomanip> | ||
| #include <memory> | ||
| #include <vector> | ||
| #include <cstring> | ||
| #include "rectangle.h" | ||
| #include "ring.h" | ||
| #include "rhombus.h" | ||
| #include "composite_shape.h" | ||
|
|
||
| void printShapeInfo(const Shape& shape) { | ||
| Point center = shape.getCenter(); | ||
| std::cout << std::fixed << std::setprecision(2); | ||
| std::cout << "[" << shape.getName() << ", (" << center.x << ", " << center.y << "), " << shape.getArea() << "]" << std::endl; | ||
| } | ||
|
|
||
| void printUsage() { | ||
| std::cerr << "Usage: program [--scale <factor>]" << std::endl; | ||
| std::cerr << "Without arguments: shows shapes without scaling" << std::endl; | ||
| } | ||
|
|
||
| void demonstrateShapes() { | ||
| std::cout << "Creating shapes" << std::endl; | ||
|
|
||
| Rectangle rect(Point(0, 0), Point(4, 3)); | ||
| Ring ring(Point(5, 5), 5.0, 2.0); | ||
| Rhombus rhombus(Point(10, 10), 6.0, 4.0); | ||
|
|
||
| std::vector<std::unique_ptr<Shape>> shapes; | ||
| shapes.push_back(std::make_unique<Rectangle>(Point(1, 1), Point(3, 4))); | ||
| shapes.push_back(std::make_unique<Ring>(Point(-2, -2), 3.0, 1.0)); | ||
| shapes.push_back(std::make_unique<Rhombus>(Point(2, -3), 5.0, 3.0)); | ||
|
|
||
| CompositeShape composite; | ||
| composite.addShape(std::make_unique<Rectangle>(Point(2, 2), Point(5, 5))); | ||
| composite.addShape(std::make_unique<Ring>(Point(3, 3), 2.0, 0.5)); | ||
| composite.addShape(std::make_unique<Rhombus>(Point(4, 4), 4.0, 2.0)); | ||
|
|
||
| std::cout << "\nShape information WITHOUT scaling" << std::endl; | ||
|
|
||
| std::cout << "\nIndividual shapes:" << std::endl; | ||
| printShapeInfo(rect); | ||
| printShapeInfo(ring); | ||
| printShapeInfo(rhombus); | ||
|
|
||
| std::cout << "\nShapes in vector:" << std::endl; | ||
| for (const auto& shape : shapes) { | ||
| printShapeInfo(*shape); | ||
| } | ||
|
|
||
| std::cout << "\nComposite shape:" << std::endl; | ||
| composite.printInfo(); | ||
| } | ||
|
|
||
| void demonstrateScaling(double scaleFactor) { | ||
| Rectangle rect(Point(0, 0), Point(4, 3)); | ||
| Ring ring(Point(5, 5), 5.0, 2.0); | ||
| Rhombus rhombus(Point(10, 10), 6.0, 4.0); | ||
|
|
||
| std::cout << "Creating shapes" << std::endl; | ||
| std::cout << "\nShape information BEFORE scaling" << std::endl; | ||
|
|
||
| std::cout << "\nIndividual shapes:" << std::endl; | ||
| printShapeInfo(rect); | ||
| printShapeInfo(ring); | ||
| printShapeInfo(rhombus); | ||
|
|
||
| rect.scale(scaleFactor); | ||
| ring.scale(scaleFactor); | ||
| rhombus.scale(scaleFactor); | ||
|
|
||
| std::cout << "\nShape information AFTER scaling by " << scaleFactor << std::endl; | ||
|
|
||
| std::cout << "\nIndividual shapes:" << std::endl; | ||
| printShapeInfo(rect); | ||
| printShapeInfo(ring); | ||
| printShapeInfo(rhombus); | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| try { | ||
| if (argc == 1) { | ||
| demonstrateShapes(); | ||
| std::cerr << "Warning: Program completed but test expects error" << std::endl; | ||
| return 1; | ||
| } else if (argc == 3 && std::strcmp(argv[1], "--scale") == 0) { | ||
| double scaleFactor = std::stod(argv[2]); | ||
| demonstrateScaling(scaleFactor); | ||
| std::cerr << "Warning: Program completed but test expects error" << std::endl; | ||
| return 1; | ||
| } else { | ||
| std::cerr << "Error: Invalid arguments" << std::endl; | ||
| printUsage(); | ||
| return 1; | ||
| } | ||
| } catch (const std::exception& e) { | ||
| std::cerr << "Error: " << e.what() << std::endl; | ||
| return 1; | ||
| } catch (...) { | ||
| std::cerr << "Unknown error occurred" << std::endl; | ||
| return 1; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #ifndef POINT_H | ||
| #define POINT_H | ||
|
|
||
| struct Point { | ||
| double x; | ||
| double y; | ||
|
|
||
| Point(double x = 0, double y = 0) : x(x), y(y) {} | ||
| }; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "rectangle.h" | ||
| #include <cmath> | ||
|
|
||
| Rectangle::Rectangle(const Point& bottomLeft, const Point& topRight) | ||
| : bottomLeft(bottomLeft), topRight(topRight) {} | ||
|
|
||
| double Rectangle::getArea() const { | ||
| double width = topRight.x - bottomLeft.x; | ||
| double height = topRight.y - bottomLeft.y; | ||
| return width * height; | ||
| } | ||
|
|
||
| Point Rectangle::getCenter() const { | ||
| return Point((bottomLeft.x + topRight.x) / 2, | ||
| (bottomLeft.y + topRight.y) / 2); | ||
| } | ||
|
|
||
| void Rectangle::move(double dx, double dy) { | ||
| bottomLeft.x += dx; | ||
| bottomLeft.y += dy; | ||
| topRight.x += dx; | ||
| topRight.y += dy; | ||
| } | ||
|
|
||
| void Rectangle::scale(double factor) { | ||
| Point center = getCenter(); | ||
|
|
||
| bottomLeft.x = center.x + (bottomLeft.x - center.x) * factor; | ||
| bottomLeft.y = center.y + (bottomLeft.y - center.y) * factor; | ||
| topRight.x = center.x + (topRight.x - center.x) * factor; | ||
| topRight.y = center.y + (topRight.y - center.y) * factor; | ||
| } | ||
|
|
||
| std::string Rectangle::getName() const { | ||
| return "RECTANGLE"; | ||
| } | ||
|
|
||
| void Rectangle::getBounds(double& minX, double& minY, double& maxX, double& maxY) const { | ||
| minX = bottomLeft.x; | ||
| minY = bottomLeft.y; | ||
| maxX = topRight.x; | ||
| maxY = topRight.y; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef RECTANGLE_H | ||
| #define RECTANGLE_H | ||
|
|
||
| #include "shape.h" | ||
|
|
||
| class Rectangle : public Shape { | ||
| private: | ||
| Point bottomLeft; | ||
| Point topRight; | ||
|
|
||
| public: | ||
| Rectangle(const Point& bottomLeft, const Point& topRight); | ||
|
|
||
| double getArea() const override; | ||
| Point getCenter() const override; | ||
| void move(double dx, double dy) override; | ||
| void scale(double factor) override; | ||
| std::string getName() const override; | ||
| void getBounds(double& minX, double& minY, double& maxX, double& maxY) const override; | ||
| }; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "rhombus.h" | ||
| #include <cmath> | ||
| #include <stdexcept> | ||
|
|
||
| Rhombus::Rhombus(const Point& center, double verticalDiagonal, double horizontalDiagonal) | ||
| : center(center), verticalDiagonal(verticalDiagonal), horizontalDiagonal(horizontalDiagonal) { | ||
| if (verticalDiagonal <= 0 || horizontalDiagonal <= 0) { | ||
| throw std::invalid_argument("Diagonals must be positive"); | ||
| } | ||
| } | ||
|
|
||
| double Rhombus::getArea() const { | ||
| return (verticalDiagonal * horizontalDiagonal) / 2.0; | ||
| } | ||
|
|
||
| Point Rhombus::getCenter() const { | ||
| return center; | ||
| } | ||
|
|
||
| void Rhombus::move(double dx, double dy) { | ||
| center.x += dx; | ||
| center.y += dy; | ||
| } | ||
|
|
||
| void Rhombus::scale(double factor) { | ||
| verticalDiagonal *= factor; | ||
| horizontalDiagonal *= factor; | ||
| } | ||
|
|
||
| std::string Rhombus::getName() const { | ||
| return "RHOMBUS"; | ||
| } | ||
|
|
||
| void Rhombus::getBounds(double& minX, double& minY, double& maxX, double& maxY) const { | ||
| minX = center.x - horizontalDiagonal / 2; | ||
| minY = center.y - verticalDiagonal / 2; | ||
| maxX = center.x + horizontalDiagonal / 2; | ||
| maxY = center.y + verticalDiagonal / 2; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef RHOMBUS_H | ||
| #define RHOMBUS_H | ||
|
|
||
| #include "shape.h" | ||
|
|
||
| class Rhombus : public Shape { | ||
| private: | ||
| Point center; | ||
| double verticalDiagonal; | ||
| double horizontalDiagonal; | ||
|
|
||
| public: | ||
| Rhombus(const Point& center, double verticalDiagonal, double horizontalDiagonal); | ||
|
|
||
| double getArea() const override; | ||
| Point getCenter() const override; | ||
| void move(double dx, double dy) override; | ||
| void scale(double factor) override; | ||
| std::string getName() const override; | ||
| void getBounds(double& minX, double& minY, double& maxX, double& maxY) const override; | ||
| }; | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Успешный вариант main не рассматривается?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я бы радостью, но я уже просто старался угодить тестам