/
polytech_kolomna
/
aipackaging_math
Обзор
Документация
Войти
/
polytech_kolomna
/
aipackaging_math
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
intersections
src/geometry/rect2d.cpp
128 строк
2 KB
Olegh
lower case
28 окт 2025, 21:08
28 окт 2025, 21:08
037a99f
Код
Авторство
О чём код?
#include <algorithm> #include <rect2d.h> // Rect2D::Rect2D(const Point2D& first, const Point2D& second) : topLeft_({ std::min(first.x, second.x), std::max(first.y, second.y) }), bottomRight_({ std::max(first.x, second.x), std::min(first.y, second.y) }) { } // Point2D Rect2D::topLeft() const { return topLeft_; } // Point2D Rect2D::topRight() const { return Point2D{ bottomRight_.x, topLeft_.y }; } // Point2D Rect2D::bottomLeft() const { return Point2D{ topLeft_.x, bottomRight_.y }; } // Point2D Rect2D::bottomRight() const { return bottomRight_; } // Point2D Rect2D::center() const { return { (topLeft_.x + bottomRight_.x) / 2, (topLeft_.y + bottomRight_.y) / 2 }; } // double Rect2D::top() const { return topLeft_.y; } // double Rect2D::left() const { return topLeft_.x; } // double Rect2D::right() const { return bottomRight_.x; } // double Rect2D::bottom() const { return bottomRight_.y; } // bool Rect2D::intersects(const Rect2D& rect) const { return !(bottomRight_.x <= rect.topLeft_.x || topLeft_.x >= rect.bottomRight_.x || bottomRight_.y >= rect.topLeft_.y || topLeft_.y <= rect.bottomRight_.y); } // bool Rect2D::contains(const Rect2D& rect) const { return topLeft_.x <= rect.topLeft_.x && topLeft_.y >= rect.topLeft_.y && bottomRight_.x >= rect.bottomRight_.x && bottomRight_.y <= rect.bottomRight_.y; } // bool Rect2D::contains(const Point2D& point) const { return point.x >= topLeft_.x && point.y <= topLeft_.y && point.x <= bottomRight_.x && point.y >= bottomRight_.y; } // bool Rect2D::operator==(const Rect2D& other) const { return topLeft_ == other.topLeft_ && bottomRight_ == other.bottomRight_; } // bool Rect2D::operator!=(const Rect2D& other) const { return !(*this == other); } // std::ostream& operator<<(std::ostream& out, const Rect2D& other) { Point2D topLeft = other.topLeft(); Point2D bottomRight = other.bottomRight(); out << "topLeft = " << topLeft << "; bottomRight = " << bottomRight<< std::endl; return out; }