diff --git a/barinov.egor/T3/commands.cpp b/barinov.egor/T3/commands.cpp new file mode 100644 index 00000000..170894fb --- /dev/null +++ b/barinov.egor/T3/commands.cpp @@ -0,0 +1,202 @@ +#include "commands.hpp" +#include +#include +#include + +bool isEven(int n) +{ + return n % 2 == 0; +} + +bool isOdd(int n) +{ + return n % 2 != 0; +} + +double getAreaEven(const std::vector& polygons) +{ + double sum = 0.0; + for (const auto& polygon : polygons) + { + if (isEven(polygon.points.size())) + { + sum += getArea(polygon); + } + } + return sum; +} + +double getAreaOdd(const std::vector& polygons) +{ + double sum = 0.0; + for (const auto& polygon : polygons) + { + if (isOdd(polygon.points.size())) + { + sum += getArea(polygon); + } + } + return sum; +} + +double getAreaMean(const std::vector& polygons) +{ + if (polygons.empty()) + { + return 0.0; + } + double sum = 0.0; + for (const auto& polygon : polygons) + { + sum += getArea(polygon); + } + return sum / static_cast(polygons.size()); +} + +double getAreaByVertexCount(const std::vector& polygons, size_t vertexCount) +{ + double sum = 0.0; + for (const auto& polygon : polygons) + { + if (polygon.points.size() == vertexCount) + { + sum += getArea(polygon); + } + } + return sum; +} + +double getMaxArea(const std::vector& polygons) +{ + if (polygons.empty()) + { + return 0.0; + } + double maxArea = getArea(polygons[0]); + for (const auto& polygon : polygons) + { + double area = getArea(polygon); + if (area > maxArea) + { + maxArea = area; + } + } + return maxArea; +} + +size_t getMaxVertexes(const std::vector& polygons) +{ + if (polygons.empty()) + { + return 0; + } + size_t maxVertexes = polygons[0].points.size(); + for (const auto& polygon : polygons) + { + if (polygon.points.size() > maxVertexes) + { + maxVertexes = polygon.points.size(); + } + } + return maxVertexes; +} + +double getMinArea(const std::vector& polygons) +{ + if (polygons.empty()) + { + return 0.0; + } + double minArea = getArea(polygons[0]); + for (const auto& polygon : polygons) + { + double area = getArea(polygon); + if (area < minArea) + { + minArea = area; + } + } + return minArea; +} + +size_t getMinVertexes(const std::vector& polygons) +{ + if (polygons.empty()) + { + return 0; + } + size_t minVertexes = polygons[0].points.size(); + for (const auto& polygon : polygons) + { + if (polygon.points.size() < minVertexes) + { + minVertexes = polygon.points.size(); + } + } + return minVertexes; +} + +size_t countEven(const std::vector& polygons) +{ + size_t count = 0; + for (const auto& polygon : polygons) + { + if (isEven(polygon.points.size())) + { + ++count; + } + } + return count; +} + +size_t countOdd(const std::vector& polygons) +{ + size_t count = 0; + for (const auto& polygon : polygons) + { + if (isOdd(polygon.points.size())) + { + ++count; + } + } + return count; +} + +size_t countByVertexCount(const std::vector& polygons, size_t vertexCount) +{ + size_t count = 0; + for (const auto& polygon : polygons) + { + if (polygon.points.size() == vertexCount) + { + ++count; + } + } + return count; +} + +size_t echoCommand(std::vector& polygons, const Polygon& target) +{ + size_t added = 0; + for (size_t i = 0; i < polygons.size(); ++i) + { + if (polygons[i] == target) + { + polygons.insert(polygons.begin() + i + 1, target); + ++added; + ++i; + } + } + return added; +} + +bool inframeCommand(const std::vector& polygons, const Polygon& target) +{ + if (polygons.empty()) + { + return false; + } + Point bottomLeft, topRight; + getBoundingBox(polygons, bottomLeft, topRight); + return isPolygonInBoundingBox(target, bottomLeft, topRight); +} diff --git a/barinov.egor/T3/commands.hpp b/barinov.egor/T3/commands.hpp new file mode 100644 index 00000000..b90cd191 --- /dev/null +++ b/barinov.egor/T3/commands.hpp @@ -0,0 +1,28 @@ +#ifndef COMMANDS_HPP +#define COMMANDS_HPP + +#include "polygon.hpp" +#include +#include + +bool isEven(int n); +bool isOdd(int n); + +double getAreaEven(const std::vector& polygons); +double getAreaOdd(const std::vector& polygons); +double getAreaMean(const std::vector& polygons); +double getAreaByVertexCount(const std::vector& polygons, size_t vertexCount); + +double getMaxArea(const std::vector& polygons); +size_t getMaxVertexes(const std::vector& polygons); +double getMinArea(const std::vector& polygons); +size_t getMinVertexes(const std::vector& polygons); + +size_t countEven(const std::vector& polygons); +size_t countOdd(const std::vector& polygons); +size_t countByVertexCount(const std::vector& polygons, size_t vertexCount); + +size_t echoCommand(std::vector& polygons, const Polygon& target); +bool inframeCommand(const std::vector& polygons, const Polygon& target); + +#endif diff --git a/barinov.egor/T3/main.cpp b/barinov.egor/T3/main.cpp new file mode 100644 index 00000000..f080f6f8 --- /dev/null +++ b/barinov.egor/T3/main.cpp @@ -0,0 +1,267 @@ +#include "polygon.hpp" +#include "commands.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool readPolygonsFromFile(const std::string& filename, std::vector& polygons) +{ + std::ifstream file(filename); + if (!file.is_open()) + { + return false; + } + std::string line; + while (std::getline(file, line)) + { + if (line.empty()) + { + continue; + } + std::istringstream iss(line); + Polygon polygon; + if (iss >> polygon) + { + polygons.push_back(polygon); + } + } + return true; +} + +bool parsePolygon(const std::vector& tokens, size_t start, Polygon& polygon) +{ + if (start >= tokens.size()) + { + return false; + } + size_t vertexCount = 0; + std::istringstream countStream(tokens[start]); + countStream >> vertexCount; + if (vertexCount < 3 || start + 1 + vertexCount > tokens.size()) + { + return false; + } + polygon.points.clear(); + for (size_t i = 0; i < vertexCount; ++i) + { + Point p; + std::istringstream pointStream(tokens[start + 1 + i]); + if (!(pointStream >> p)) + { + return false; + } + polygon.points.push_back(p); + } + return true; +} + +int main(int argc, char* argv[]) +{ + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return 1; + } + std::vector polygons; + if (!readPolygonsFromFile(argv[1], polygons)) + { + std::cerr << "Error: cannot read file" << std::endl; + return 1; + } + std::cout << std::fixed << std::setprecision(1); + std::string line; + while (std::getline(std::cin, line)) + { + if (line.empty()) + { + continue; + } + std::istringstream iss(line); + std::string command; + iss >> command; + if (command == "AREA") + { + std::string param; + iss >> param; + if (param == "EVEN") + { + std::cout << getAreaEven(polygons) << std::endl; + } + else if (param == "ODD") + { + std::cout << getAreaOdd(polygons) << std::endl; + } + else if (param == "MEAN") + { + if (polygons.empty()) + { + std::cout << "" << std::endl; + } + else + { + std::cout << getAreaMean(polygons) << std::endl; + } + } + else + { + size_t vertexCount = 0; + std::istringstream countStream(param); + countStream >> vertexCount; + if (vertexCount >= 3) + { + std::cout << getAreaByVertexCount(polygons, vertexCount) << std::endl; + } + else + { + std::cout << "" << std::endl; + } + } + } + else if (command == "MAX") + { + std::string param; + iss >> param; + if (param == "AREA") + { + if (polygons.empty()) + { + std::cout << "" << std::endl; + } + else + { + std::cout << getMaxArea(polygons) << std::endl; + } + } + else if (param == "VERTEXES") + { + if (polygons.empty()) + { + std::cout << "" << std::endl; + } + else + { + std::cout << getMaxVertexes(polygons) << std::endl; + } + } + else + { + std::cout << "" << std::endl; + } + } + else if (command == "MIN") + { + std::string param; + iss >> param; + if (param == "AREA") + { + if (polygons.empty()) + { + std::cout << "" << std::endl; + } + else + { + std::cout << getMinArea(polygons) << std::endl; + } + } + else if (param == "VERTEXES") + { + if (polygons.empty()) + { + std::cout << "" << std::endl; + } + else + { + std::cout << getMinVertexes(polygons) << std::endl; + } + } + else + { + std::cout << "" << std::endl; + } + } + else if (command == "COUNT") + { + std::string param; + iss >> param; + if (param == "EVEN") + { + std::cout << countEven(polygons) << std::endl; + } + else if (param == "ODD") + { + std::cout << countOdd(polygons) << std::endl; + } + else + { + size_t vertexCount = 0; + std::istringstream countStream(param); + countStream >> vertexCount; + if (vertexCount >= 3) + { + std::cout << countByVertexCount(polygons, vertexCount) << std::endl; + } + else + { + std::cout << "" << std::endl; + } + } + } + else if (command == "ECHO") + { + std::vector tokens; + std::string token; + std::istringstream tokenStream(line); + while (tokenStream >> token) + { + tokens.push_back(token); + } + if (tokens.size() < 2) + { + std::cout << "" << std::endl; + continue; + } + Polygon target; + if (!parsePolygon(tokens, 1, target)) + { + std::cout << "" << std::endl; + continue; + } + size_t added = echoCommand(polygons, target); + std::cout << added << std::endl; + } + else if (command == "INFRAME") + { + std::vector tokens; + std::string token; + std::istringstream tokenStream(line); + while (tokenStream >> token) + { + tokens.push_back(token); + } + if (tokens.size() < 2) + { + std::cout << "" << std::endl; + continue; + } + Polygon target; + if (!parsePolygon(tokens, 1, target)) + { + std::cout << "" << std::endl; + continue; + } + bool result = inframeCommand(polygons, target); + std::cout << (result ? "" : "") << std::endl; + } + else + { + std::cout << "" << std::endl; + } + } + return 0; +} diff --git a/barinov.egor/T3/polygon.cpp b/barinov.egor/T3/polygon.cpp new file mode 100644 index 00000000..21d99a49 --- /dev/null +++ b/barinov.egor/T3/polygon.cpp @@ -0,0 +1,150 @@ +#include "polygon.hpp" +#include +#include +#include +#include +#include + +bool operator==(const Point& a, const Point& b) +{ + return a.x == b.x && a.y == b.y; +} + +bool operator!=(const Point& a, const Point& b) +{ + return !(a == b); +} + +bool operator==(const Polygon& a, const Polygon& b) +{ + if (a.points.size() != b.points.size()) + { + return false; + } + for (size_t i = 0; i < a.points.size(); ++i) + { + if (a.points[i] != b.points[i]) + { + return false; + } + } + return true; +} + +bool operator!=(const Polygon& a, const Polygon& b) +{ + return !(a == b); +} + +std::istream& operator>>(std::istream& in, Point& point) +{ + char c = '\0'; + in >> c; + if (c != '(') + { + in.setstate(std::ios::failbit); + return in; + } + in >> point.x; + in >> c; + if (c != ';') + { + in.setstate(std::ios::failbit); + return in; + } + in >> point.y; + in >> c; + if (c != ')') + { + in.setstate(std::ios::failbit); + return in; + } + return in; +} + +std::istream& operator>>(std::istream& in, Polygon& polygon) +{ + polygon.points.clear(); + size_t vertexCount = 0; + in >> vertexCount; + if (!in || vertexCount < 3) + { + in.setstate(std::ios::failbit); + return in; + } + for (size_t i = 0; i < vertexCount; ++i) + { + Point p; + in >> p; + if (!in) + { + in.setstate(std::ios::failbit); + return in; + } + polygon.points.push_back(p); + } + return in; +} + +double getArea(const Polygon& polygon) +{ + double area = 0.0; + size_t n = polygon.points.size(); + for (size_t i = 0; i < n; ++i) + { + const Point& p1 = polygon.points[i]; + const Point& p2 = polygon.points[(i + 1) % n]; + area += static_cast(p1.x * p2.y - p2.x * p1.y); + } + return std::fabs(area) / 2.0; +} + +void getBoundingBox(const std::vector& polygons, + Point& bottomLeft, + Point& topRight) +{ + if (polygons.empty()) + { + bottomLeft = Point{0, 0}; + topRight = Point{0, 0}; + return; + } + int minX = std::numeric_limits::max(); + int minY = std::numeric_limits::max(); + int maxX = std::numeric_limits::lowest(); + int maxY = std::numeric_limits::lowest(); + for (const auto& polygon : polygons) + { + for (const auto& point : polygon.points) + { + if (point.x < minX) minX = point.x; + if (point.y < minY) minY = point.y; + if (point.x > maxX) maxX = point.x; + if (point.y > maxY) maxY = point.y; + } + } + bottomLeft = Point{minX, minY}; + topRight = Point{maxX, maxY}; +} + +bool isPointInBoundingBox(const Point& point, + const Point& bottomLeft, + const Point& topRight) +{ + return point.x >= bottomLeft.x && point.x <= topRight.x && + point.y >= bottomLeft.y && point.y <= topRight.y; +} + +bool isPolygonInBoundingBox(const Polygon& polygon, + const Point& bottomLeft, + const Point& topRight) +{ + for (const auto& point : polygon.points) + { + if (!isPointInBoundingBox(point, bottomLeft, topRight)) + { + return false; + } + } + return true; +} diff --git a/barinov.egor/T3/polygon.hpp b/barinov.egor/T3/polygon.hpp new file mode 100644 index 00000000..05ac8813 --- /dev/null +++ b/barinov.egor/T3/polygon.hpp @@ -0,0 +1,42 @@ +#ifndef POLYGON_HPP +#define POLYGON_HPP + +#include +#include + +struct Point +{ + int x, y; +}; + +struct Polygon +{ + std::vector points; +}; + +bool operator==(const Point& a, const Point& b); +bool operator!=(const Point& a, const Point& b); + +bool operator==(const Polygon& a, const Polygon& b); +bool operator!=(const Polygon& a, const Polygon& b); + +std::istream& operator>>(std::istream& in, Point& point); +std::istream& operator>>(std::istream& in, Polygon& polygon); + +double getArea(const Polygon& polygon); + +void getBoundingBox( + const std::vector& polygons, + Point& bottomLeft, + Point& topRight +); + +bool isPointInBoundingBox(const Point& point, + const Point& bottomLeft, + const Point& topRight); + +bool isPolygonInBoundingBox(const Polygon& polygon, + const Point& bottomLeft, + const Point& topRight); + +#endif diff --git a/barinov.egor/T4/compositeshape.cpp b/barinov.egor/T4/compositeshape.cpp deleted file mode 100644 index 0861ea96..00000000 --- a/barinov.egor/T4/compositeshape.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "compositeshape.h" -#include -#include - -void CompositeShape::addShape(std::unique_ptr 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::max(); - double minY = std::numeric_limits::max(); - double maxX = std::numeric_limits::lowest(); - double maxY = std::numeric_limits::lowest(); - - for (const auto& shape : shapes) { - BoundingBox box = shape->getBoundingBox(); - - minX = std::min(minX, box.bottomLeft.x); - minY = std::min(minY, box.bottomLeft.y); - maxX = std::max(maxX, box.topRight.x); - maxY = std::max(maxY, box.topRight.y); - } - - return Point((minX + maxX) / 2, (minY + maxY) / 2); -} - -BoundingBox CompositeShape::getBoundingBox() const { - if (shapes.empty()) { - BoundingBox emptyBox; - emptyBox.bottomLeft = Point(0, 0); - emptyBox.topRight = Point(0, 0); - return emptyBox; - } - - double minX = std::numeric_limits::max(); - double minY = std::numeric_limits::max(); - double maxX = std::numeric_limits::lowest(); - double maxY = std::numeric_limits::lowest(); - - for (const auto& shape : shapes) { - BoundingBox box = shape->getBoundingBox(); - - minX = std::min(minX, box.bottomLeft.x); - minY = std::min(minY, box.bottomLeft.y); - maxX = std::max(maxX, box.topRight.x); - maxY = std::max(maxY, box.topRight.y); - } - - BoundingBox resultBox; - resultBox.bottomLeft = Point(minX, minY); - resultBox.topRight = Point(maxX, maxY); - return resultBox; -} - -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"; -} - -const std::vector>& CompositeShape::getShapes() const { - return shapes; -} - diff --git a/barinov.egor/T4/compositeshape.h b/barinov.egor/T4/compositeshape.h deleted file mode 100644 index af50c41f..00000000 --- a/barinov.egor/T4/compositeshape.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef COMPOSITESHAPE_H -#define COMPOSITESHAPE_H - -#include "shape.h" -#include -#include - -class CompositeShape : public Shape { -private: - std::vector> shapes; - -public: - void addShape(std::unique_ptr 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; - BoundingBox getBoundingBox() const override; - - const std::vector>& getShapes() const; -}; - -#endif - diff --git a/barinov.egor/T4/main.cpp b/barinov.egor/T4/main.cpp deleted file mode 100644 index e537d417..00000000 --- a/barinov.egor/T4/main.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include -#include "rectangle.h" -#include "ring.h" -#include "rhombus.h" -#include "compositeshape.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() << "]"; -} - -void printCompositeInfo(const CompositeShape& composite) { - Point center = composite.getCenter(); - std::cout << std::fixed << std::setprecision(2); - std::cout << "[COMPOSITE, (" << center.x << ", " << center.y << "), " << composite.getArea() << ":\n"; - - for (const auto& shape : composite.getShapes()) { - std::cout << " "; - printShapeInfo(*shape); - std::cout << "\n"; - } - std::cout << "]"; -} - -int main() { - std::vector> shapes; - - shapes.push_back(std::make_unique( - Point(0, 0), Point(6, 4))); - - shapes.push_back(std::make_unique( - Point(10, 5), 5.0, 2.0)); - - shapes.push_back(std::make_unique( - Point(-5, -2), 8.0, 6.0)); - - shapes.push_back(std::make_unique( - Point(-10, 2), Point(-6, 5))); - - shapes.push_back(std::make_unique( - Point(0, 10), 3.0, 1.0)); - - auto composite = std::make_unique(); - - composite->addShape(std::make_unique( - Point(15, 15), Point(20, 18))); - - composite->addShape(std::make_unique( - Point(18, 20), 2.5, 1.0)); - - composite->addShape(std::make_unique( - Point(22, 17), 5.0, 4.0)); - - shapes.push_back(std::move(composite)); - - std::cout << "=== Фигуры до масштабирования ===\n"; - std::cout << "Варианты: 0 - Прямоугольник, 2 - Кольцо, 5 - Ромб\n\n"; - - for (size_t i = 0; i < shapes.size(); ++i) { - std::cout << "Фигура " << i + 1 << ": "; - if (shapes[i]->getName() == "COMPOSITE") { - printCompositeInfo(dynamic_cast(*shapes[i])); - } else { - printShapeInfo(*shapes[i]); - } - std::cout << "\n\n"; - } - - std::cout << "\n=== Масштабирование всех фигур в 2 раза ===\n\n"; - for (auto& shape : shapes) { - shape->scale(2.0); - } - - std::cout << "=== Фигуры после масштабирования (x2) ===\n\n"; - for (size_t i = 0; i < shapes.size(); ++i) { - std::cout << "Фигура " << i + 1 << ": "; - if (shapes[i]->getName() == "COMPOSITE") { - printCompositeInfo(dynamic_cast(*shapes[i])); - } else { - printShapeInfo(*shapes[i]); - } - std::cout << "\n\n"; - } - - return 0; -} - diff --git a/barinov.egor/T4/point.h b/barinov.egor/T4/point.h deleted file mode 100644 index e053a5d7..00000000 --- a/barinov.egor/T4/point.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef POINT_H -#define POINT_H - -struct Point { - double x; - double y; - - Point(double x = 0, double y = 0) : x(x), y(y) {} -}; - -#endif - diff --git a/barinov.egor/T4/rectangle.cpp b/barinov.egor/T4/rectangle.cpp deleted file mode 100644 index 82dcfc30..00000000 --- a/barinov.egor/T4/rectangle.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "rectangle.h" -#include - -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 - (center.x - bottomLeft.x) * factor; - bottomLeft.y = center.y - (center.y - bottomLeft.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"; -} - -BoundingBox Rectangle::getBoundingBox() const { - BoundingBox box; - box.bottomLeft = bottomLeft; - box.topRight = topRight; - return box; -} - diff --git a/barinov.egor/T4/rectangle.h b/barinov.egor/T4/rectangle.h deleted file mode 100644 index b97c7533..00000000 --- a/barinov.egor/T4/rectangle.h +++ /dev/null @@ -1,23 +0,0 @@ -#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; - BoundingBox getBoundingBox() const override; -}; - -#endif - diff --git a/barinov.egor/T4/rhombus.cpp b/barinov.egor/T4/rhombus.cpp deleted file mode 100644 index 0eb688db..00000000 --- a/barinov.egor/T4/rhombus.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "rhombus.h" -#include - -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) { - if (factor <= 0) { - throw std::invalid_argument("Scale factor must be positive"); - } - verticalDiagonal *= factor; - horizontalDiagonal *= factor; -} - -std::string Rhombus::getName() const { - return "RHOMBUS"; -} - -BoundingBox Rhombus::getBoundingBox() const { - BoundingBox box; - box.bottomLeft = Point(center.x - horizontalDiagonal / 2, center.y - verticalDiagonal / 2); - box.topRight = Point(center.x + horizontalDiagonal / 2, center.y + verticalDiagonal / 2); - return box; -} - -Point Rhombus::getTop() const { - return Point(center.x, center.y + verticalDiagonal / 2.0); -} - -Point Rhombus::getBottom() const { - return Point(center.x, center.y - verticalDiagonal / 2.0); -} - -Point Rhombus::getLeft() const { - return Point(center.x - horizontalDiagonal / 2.0, center.y); -} - -Point Rhombus::getRight() const { - return Point(center.x + horizontalDiagonal / 2.0, center.y); -} diff --git a/barinov.egor/T4/rhombus.h b/barinov.egor/T4/rhombus.h deleted file mode 100644 index 17355390..00000000 --- a/barinov.egor/T4/rhombus.h +++ /dev/null @@ -1,29 +0,0 @@ -#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; - BoundingBox getBoundingBox() const override; - - Point getTop() const; - Point getBottom() const; - Point getLeft() const; - Point getRight() const; -}; - -#endif - diff --git a/barinov.egor/T4/ring.cpp b/barinov.egor/T4/ring.cpp deleted file mode 100644 index dbf59836..00000000 --- a/barinov.egor/T4/ring.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "ring.h" -#include -#include - -const double PI = 3.14159265358979323846; - -Ring::Ring(const Point& center, double outerRadius, double innerRadius) - : center(center), outerRadius(outerRadius), innerRadius(innerRadius) { - if (innerRadius >= outerRadius) { - throw std::invalid_argument("Inner radius must be less than outer radius"); - } - if (innerRadius <= 0 || outerRadius <= 0) { - throw std::invalid_argument("Radii must be positive"); - } -} - -double Ring::getArea() const { - return PI * (outerRadius * outerRadius - innerRadius * innerRadius); -} - -Point Ring::getCenter() const { - return center; -} - -void Ring::move(double dx, double dy) { - center.x += dx; - center.y += dy; -} - -void Ring::scale(double factor) { - if (factor <= 0) { - throw std::invalid_argument("Scale factor must be positive"); - } - outerRadius *= factor; - innerRadius *= factor; -} - -std::string Ring::getName() const { - return "RING"; -} - -BoundingBox Ring::getBoundingBox() const { - BoundingBox box; - box.bottomLeft = Point(center.x - outerRadius, center.y - outerRadius); - box.topRight = Point(center.x + outerRadius, center.y + outerRadius); - return box; -} - diff --git a/barinov.egor/T4/ring.h b/barinov.egor/T4/ring.h deleted file mode 100644 index 82493c20..00000000 --- a/barinov.egor/T4/ring.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef RING_H -#define RING_H - -#include "shape.h" - -class Ring : public Shape { -private: - Point center; - double outerRadius; - double innerRadius; - -public: - Ring(const Point& center, double outerRadius, double innerRadius); - - 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; - BoundingBox getBoundingBox() const override; -}; - -#endif - diff --git a/barinov.egor/T4/shape.h b/barinov.egor/T4/shape.h deleted file mode 100644 index 38a0b4a0..00000000 --- a/barinov.egor/T4/shape.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SHAPE_H -#define SHAPE_H - -#include -#include "point.h" - -struct BoundingBox { - Point bottomLeft; - Point topRight; - - double getWidth() const { return topRight.x - bottomLeft.x; } - double getHeight() const { return topRight.y - bottomLeft.y; } - Point getCenter() const { - return Point((bottomLeft.x + topRight.x) / 2, (bottomLeft.y + topRight.y) / 2); - } -}; - -class Shape { -public: - virtual ~Shape() = default; - - virtual double getArea() const = 0; - virtual Point getCenter() const = 0; - virtual void move(double dx, double dy) = 0; - virtual void scale(double factor) = 0; - virtual std::string getName() const = 0; - virtual BoundingBox getBoundingBox() const = 0; -}; - -#endif -