Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
rectangle.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  * Alexandros Frantzis <alexandros.frantzis@canonical.com>
18  */
19 
20 #ifndef MIR_GEOMETRY_RECTANGLE_H_
21 #define MIR_GEOMETRY_RECTANGLE_H_
22 
23 #include "mir/geometry/point.h"
24 #include "size.h"
25 
26 #include <iosfwd>
27 
28 namespace mir
29 {
30 namespace geometry
31 {
32 
33 struct Rectangle
34 {
35  Rectangle() = default;
36 
37  Rectangle(Point const& top_left, Size const& size)
38  : top_left{top_left}, size{size}
39  {
40  }
41 
44 
51  Point bottom_right() const;
52  Point top_right() const;
53  Point bottom_left() const;
54  bool contains(Point const& p) const;
55 
62  bool contains(Rectangle const& r) const;
63 
64  bool overlaps(Rectangle const& r) const;
65 
66  Rectangle intersection_with(Rectangle const& r) const;
67 };
68 
69 inline bool operator == (Rectangle const& lhs, Rectangle const& rhs)
70 {
71  return lhs.top_left == rhs.top_left && lhs.size == rhs.size;
72 }
73 
74 inline bool operator != (Rectangle const& lhs, Rectangle const& rhs)
75 {
76  return lhs.top_left != rhs.top_left || lhs.size != rhs.size;
77 }
78 
79 std::ostream& operator<<(std::ostream& out, Rectangle const& value);
80 }
81 }
82 
83 #endif /* MIR_GEOMETRY_RECTANGLE_H_ */
Definition: size.h:30
Point bottom_right() const
The bottom right boundary point of the rectangle.
Definition: rectangle.cpp:25
All things Mir.
Definition: aging_buffer.h:24
bool overlaps(Rectangle const &r) const
Definition: rectangle.cpp:61
Definition: point.h:30
Point top_left
Definition: rectangle.h:42
Size size
Definition: rectangle.h:43
Rectangle(Point const &top_left, Size const &size)
Definition: rectangle.h:37
bool contains(Point const &p) const
Definition: rectangle.cpp:51
bool operator!=(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:55
Rectangle intersection_with(Rectangle const &r) const
Definition: rectangle.cpp:80
bool operator==(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:50
Point top_right() const
Definition: rectangle.cpp:31
std::ostream & operator<<(std::ostream &out, Displacement const &value)
Definition: ostream.cpp:29
Definition: rectangle.h:33
Point bottom_left() const
Definition: rectangle.cpp:36

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014