Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. #include <string>
  5. #include <algorithm>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. class OrtoFigure
  10. {
  11. public:
  12. OrtoFigure(float x, float y, float xe, float ye) :
  13. xb_(x),
  14. yb_(y),
  15. xe_(xe),
  16. ye_(ye)
  17. {
  18.  
  19. }
  20. OrtoFigure(const OrtoSegm& obj) :
  21. xb_(obj.xb_),
  22. yb_(obj.yb_),
  23. xe_(obj.xe_),
  24. ye_(obj.ye_)
  25. {
  26.  
  27. }
  28. void Reader()
  29. {
  30. string line;
  31. vector<string> strings;
  32. ifstream in("D:/text.txt");
  33. while (getline(in, line))
  34. {
  35. strings.push_back(line);
  36. }
  37. for (string t : strings)
  38. {
  39. cout << t << "\n";
  40. }
  41. }
  42. protected:
  43. float xb_{ std::numeric_limits<float>::denorm_min() };
  44. float xe_{ std::numeric_limits<float>::denorm_min() };
  45. float yb_{ std::numeric_limits<float>::denorm_min() };
  46. float ye_{ std::numeric_limits<float>::denorm_min() };
  47. };
  48.  
  49. class OrtoSegm : private OrtoFigure
  50. {
  51. public:
  52. OrtoSegm() = default;
  53. OrtoSegm(const OrtoSegm& obj):OrtoFigure()
  54. {
  55. if (xb_ != xe_ || yb_ != ye_)
  56. {
  57. throw invalid_argument("Segment aren't orto");
  58. }
  59. }
  60. OrtoSegm(float x, float y, float xe, float ye):OrtoFigure(x,y,xe,ye)
  61. {
  62. if (xb_ != xe_ && yb_ != ye_)
  63. {
  64. throw invalid_argument("Segment aren't orto");
  65. }
  66. }
  67. ~OrtoSegm() = default;
  68.  
  69. float width() const
  70. {
  71. if (yb_ == ye_)
  72. {
  73. return abs(xe_ - xb_);
  74. }
  75. else if (xb_ == xe_)
  76. {
  77. return abs(ye_ - yb_);
  78. }
  79. }
  80. OrtoSegm& operator=(const OrtoSegm& obj)
  81. {
  82. xb_ = obj.xb_;
  83. xe_ = obj.xe_;
  84. yb_ = obj.yb_;
  85. ye_ = obj.ye_;
  86. return *this;
  87. }
  88. void move(const float x, const float y, const float xe, const float ye)
  89. {
  90. if (y != ye && x != xe)
  91. {
  92. throw invalid_argument("Segment aren't orto");
  93. }
  94. else
  95. {
  96. xb_ = x;
  97. yb_ = y;
  98. xe_ = xe;
  99. ye_ = ye;
  100. }
  101. }
  102. bool operator==(const OrtoSegm& obj) const
  103. {
  104. if (xbegin_ == obj.xbegin_ && ybegin_ == obj.ybegin_ && yend_ == obj.yend_ && xend_ == obj.xend_)
  105. {
  106. return true;
  107. }
  108. else
  109. return false;
  110. }
  111. bool operator!= (const OrtoSegm& obj) const
  112. {
  113. return !operator==(obj);
  114. }
  115. OrtoSegm InterSect(const OrtoSegm& obj)
  116. {
  117. if (yb_ = obj.yb_)
  118. {
  119. if (obj.xb_ >= xb_ && obj.xe_ <= xe_)
  120. {
  121. return OrtoSegm(obj.xb_,yb_,obj.xe_,yb_);
  122. }
  123. else if (obj.xb_ >= xb_ && obj.xe_ >= xe_)
  124. {
  125. return OrtoSegm(obj.xb_,yb_,xe_,yb_);
  126. }
  127. else if (obj.xb_ <= xb_ && obj.xe_ >= xe_)
  128. {
  129. return OrtoSegm(xb_,yb_,xe_,yb_);
  130. }
  131. else if (obj.xb_ <= xb_ && obj.xe_ <= xe_)
  132. {
  133. return OrtoSegm(xb_,yb_,obj.xe_,yb_);
  134. }
  135. else
  136. {
  137. OrtoSegm b;
  138. return b;
  139. }
  140. }
  141. else if (xb_ = obj.xb_)
  142. {
  143. if (obj.yb_ > yb_ && obj.ye_ < ye_)
  144. {
  145. return OrtoSegm(obj.yb_, xb_,obj.ye_ ,xb_);
  146. }
  147. else if (obj.xb_ < xb_ && obj.xe_ > xe_)
  148. {
  149. return OrtoSegm(yb_, xb_,ye_ , xb_);
  150. }
  151. else
  152. {
  153. OrtoSegm b;
  154. return b;
  155. }
  156. }
  157. }
  158. bool IsGood(string line)
  159. {
  160.  
  161. }
  162. };
  163.  
  164.  
  165. class OrtoRect : private OrtoFigure
  166. {
  167. public:
  168. OrtoRect() = default;
  169. OrtoRect(float x, float y, float xe, float ye) :
  170. xb_(x),
  171. xe_(xe),
  172. yb_(y),
  173. ye_(ye)
  174. {
  175. }
  176. OrtoRect(const OrtoRect& obj) = default;
  177. ~OrtoRect() = default;
  178.  
  179. float width() const
  180. {
  181. return abs(xe_ - xb_);
  182. }
  183. float height() const
  184. {
  185. return abs(ye_ - yb_);
  186. }
  187. OrtoRect operator=(const OrtoRect& obj)
  188. {
  189. xb_ = obj.xb_;
  190. xe_ = obj.xe_;
  191. yb_ = obj.yb_;
  192. ye_ = obj.ye_;
  193. return *this;
  194. }
  195. void move(const float x, const float y, const float xe, const float ye)
  196. {
  197. xb_ = x;
  198. xe_ = y;
  199. yb_ = xe;
  200. ye_ = ye;
  201. }
  202. bool operator==(const OrtoRect& obj) const
  203. {
  204. if (xb_ == obj.xb_ && yb_ == obj.yb_ && ye_ == obj.ye_ && xe_ == obj.xe_)
  205. {
  206. return true;
  207. }
  208. else
  209. return false;
  210. }
  211. bool operator!=(const OrtoRect& obj)
  212. {
  213. return !operator==(obj);
  214. }
  215. OrtoRect Intersect(const OrtoRect& or2) {
  216. float x1{ 0 };
  217. float y1{ 0 };
  218. float x2{ 0 };
  219. float y2{ 0 };
  220. x1 = std::max(xb_, or2.xb_);
  221. y1 = std::max(yb_, or2.yb_);
  222. x2 = std::max(xb_ + width(), or2.xb_ + or2.width());
  223. y2 = std::max(yb_ + height(), or2.yb_ + or2.height());
  224. return OrtoRect(x1, y1, x2 - x1, y1 - y2);
  225. }
  226. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement