dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
rectangle.cpp
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 #include "rectangle.h"
28 
29 namespace internals {
30 Rectangle Rectangle::Empty=Rectangle();
31 Rectangle Rectangle::FromLTRB(int left, int top, int right, int bottom)
32  {
33  return Rectangle(left,
34  top,
35  right - left,
36  bottom - top);
37  }
39  {
40  Rectangle r = rect;
41  r.Inflate(x, y);
42  return r;
43  }
45  {
46  int x1 = std::max(a.X(), b.X());
47  int x2 = std::min(a.X() + a.Width(), b.X() + b.Width());
48  int y1 = std::max(a.Y(), b.Y());
49  int y2 = std::min(a.Y() + a.Height(), b.Y() + b.Height());
50 
51  if(x2 >= x1
52  && y2 >= y1)
53  {
54 
55  return Rectangle(x1, y1, x2 - x1, y2 - y1);
56  }
57  return Rectangle::Empty;
58  }
60  {
61  int x1 = std::min(a.x, b.x);
62  int x2 = std::max(a.x + a.width, b.x + b.width);
63  int y1 = std::min(a.y, b.y);
64  int y2 = std::max(a.y + a.height, b.y + b.height);
65 
66  return Rectangle(x1, y1, x2 - x1, y2 - y1);
67  }
68 bool operator==(Rectangle const& lhs,Rectangle const& rhs)
69 {
70  return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height);
71 }
72 uint qHash(Rectangle const& rect)
73  {
74  return (int) ((quint32) rect.x ^
75  (((quint32) rect.y << 13) | ((quint32) rect.y >> 19)) ^
76  (((quint32) rect.width << 26) | ((quint32) rect.width >> 6)) ^
77  (((quint32) rect.height << 7) | ((quint32) rect.height >> 25)));
78  }
79 }
static Rectangle Empty
Definition: rectangle.h:40
end a
Definition: OPPlots.m:98
static Rectangle Union(const Rectangle &a, const Rectangle &b)
Definition: rectangle.cpp:59
uint qHash(Rectangle const &rect)
Definition: rectangle.cpp:72
static Rectangle FromLTRB(qint32 left, qint32 top, qint32 right, qint32 bottom)
Definition: rectangle.cpp:31
void Inflate(const qint32 &width, const qint32 &height)
Definition: rectangle.h:102
bool operator==(LoadTask const &lhs, LoadTask const &rhs)
Definition: loadtask.cpp:31
x
Definition: OPPlots.m:100
void Intersect(const Rectangle &rect)
Definition: rectangle.h:116
y
Definition: OPPlots.m:101