Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
border.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef BORDER_H
24 #define BORDER_H
25 
26 #include <QRectF>
27 
28 class Border {
29 
30 public:
31 
32  Border()
33  :first(true),
34  border(0., 0., 0., 0.)
35  {}
36 
37  ~Border()
38  {}
39 
40  void reset() {
41  border = {0., 0., 0., 0.};
42  first = true;
43  }
44 
45  void update(QRectF rect) {
46  if (first) {
47  border = rect;
48  first = false;
49  return;
50  }
51  if (rect.x() < border.x())
52  border.setX(rect.x());
53  if (rect.y() < border.y())
54  border.setY(rect.y());
55  if (rect.x() + rect.width() > border.x() + border.width())
56  border.setWidth(rect.x() + rect.width() - border.x());
57  if (rect.y() + rect.height() > border.y() + border.height())
58  border.setHeight(rect.y() + rect.height() - border.y());
59  }
60 
61  QRectF getBorder() const {
62  QRectF res(border);
63 
64  return res;
65  }
66 
67 private:
68 
69  bool first;
70  QRectF border;
71 };
72 
73 #endif // BORDER_H
Definition: border.h:28