Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- class OrtoFigure
- {
- public:
- OrtoFigure(float x, float y, float xe, float ye) :
- xb_(x),
- yb_(y),
- xe_(xe),
- ye_(ye)
- {
- }
- OrtoFigure(const OrtoSegm& obj) :
- xb_(obj.xb_),
- yb_(obj.yb_),
- xe_(obj.xe_),
- ye_(obj.ye_)
- {
- }
- void Reader()
- {
- string line;
- vector<string> strings;
- ifstream in("D:/text.txt");
- while (getline(in, line))
- {
- strings.push_back(line);
- }
- for (string t : strings)
- {
- cout << t << "\n";
- }
- }
- protected:
- float xb_{ std::numeric_limits<float>::denorm_min() };
- float xe_{ std::numeric_limits<float>::denorm_min() };
- float yb_{ std::numeric_limits<float>::denorm_min() };
- float ye_{ std::numeric_limits<float>::denorm_min() };
- };
- class OrtoSegm : private OrtoFigure
- {
- public:
- OrtoSegm() = default;
- OrtoSegm(const OrtoSegm& obj):OrtoFigure()
- {
- if (xb_ != xe_ || yb_ != ye_)
- {
- throw invalid_argument("Segment aren't orto");
- }
- }
- OrtoSegm(float x, float y, float xe, float ye):OrtoFigure(x,y,xe,ye)
- {
- if (xb_ != xe_ && yb_ != ye_)
- {
- throw invalid_argument("Segment aren't orto");
- }
- }
- ~OrtoSegm() = default;
- float width() const
- {
- if (yb_ == ye_)
- {
- return abs(xe_ - xb_);
- }
- else if (xb_ == xe_)
- {
- return abs(ye_ - yb_);
- }
- }
- OrtoSegm& operator=(const OrtoSegm& obj)
- {
- xb_ = obj.xb_;
- xe_ = obj.xe_;
- yb_ = obj.yb_;
- ye_ = obj.ye_;
- return *this;
- }
- void move(const float x, const float y, const float xe, const float ye)
- {
- if (y != ye && x != xe)
- {
- throw invalid_argument("Segment aren't orto");
- }
- else
- {
- xb_ = x;
- yb_ = y;
- xe_ = xe;
- ye_ = ye;
- }
- }
- bool operator==(const OrtoSegm& obj) const
- {
- if (xbegin_ == obj.xbegin_ && ybegin_ == obj.ybegin_ && yend_ == obj.yend_ && xend_ == obj.xend_)
- {
- return true;
- }
- else
- return false;
- }
- bool operator!= (const OrtoSegm& obj) const
- {
- return !operator==(obj);
- }
- OrtoSegm InterSect(const OrtoSegm& obj)
- {
- if (yb_ = obj.yb_)
- {
- if (obj.xb_ >= xb_ && obj.xe_ <= xe_)
- {
- return OrtoSegm(obj.xb_,yb_,obj.xe_,yb_);
- }
- else if (obj.xb_ >= xb_ && obj.xe_ >= xe_)
- {
- return OrtoSegm(obj.xb_,yb_,xe_,yb_);
- }
- else if (obj.xb_ <= xb_ && obj.xe_ >= xe_)
- {
- return OrtoSegm(xb_,yb_,xe_,yb_);
- }
- else if (obj.xb_ <= xb_ && obj.xe_ <= xe_)
- {
- return OrtoSegm(xb_,yb_,obj.xe_,yb_);
- }
- else
- {
- OrtoSegm b;
- return b;
- }
- }
- else if (xb_ = obj.xb_)
- {
- if (obj.yb_ > yb_ && obj.ye_ < ye_)
- {
- return OrtoSegm(obj.yb_, xb_,obj.ye_ ,xb_);
- }
- else if (obj.xb_ < xb_ && obj.xe_ > xe_)
- {
- return OrtoSegm(yb_, xb_,ye_ , xb_);
- }
- else
- {
- OrtoSegm b;
- return b;
- }
- }
- }
- bool IsGood(string line)
- {
- }
- };
- class OrtoRect : private OrtoFigure
- {
- public:
- OrtoRect() = default;
- OrtoRect(float x, float y, float xe, float ye) :
- xb_(x),
- xe_(xe),
- yb_(y),
- ye_(ye)
- {
- }
- OrtoRect(const OrtoRect& obj) = default;
- ~OrtoRect() = default;
- float width() const
- {
- return abs(xe_ - xb_);
- }
- float height() const
- {
- return abs(ye_ - yb_);
- }
- OrtoRect operator=(const OrtoRect& obj)
- {
- xb_ = obj.xb_;
- xe_ = obj.xe_;
- yb_ = obj.yb_;
- ye_ = obj.ye_;
- return *this;
- }
- void move(const float x, const float y, const float xe, const float ye)
- {
- xb_ = x;
- xe_ = y;
- yb_ = xe;
- ye_ = ye;
- }
- bool operator==(const OrtoRect& obj) const
- {
- if (xb_ == obj.xb_ && yb_ == obj.yb_ && ye_ == obj.ye_ && xe_ == obj.xe_)
- {
- return true;
- }
- else
- return false;
- }
- bool operator!=(const OrtoRect& obj)
- {
- return !operator==(obj);
- }
- OrtoRect Intersect(const OrtoRect& or2) {
- float x1{ 0 };
- float y1{ 0 };
- float x2{ 0 };
- float y2{ 0 };
- x1 = std::max(xb_, or2.xb_);
- y1 = std::max(yb_, or2.yb_);
- x2 = std::max(xb_ + width(), or2.xb_ + or2.width());
- y2 = std::max(yb_ + height(), or2.yb_ + or2.height());
- return OrtoRect(x1, y1, x2 - x1, y1 - y2);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement