Mir
rectangle.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, 2016 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 2 or 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  constexpr Rectangle() = default;
36 
37  constexpr Rectangle(Point const& top_left, Size const& size)
39  {
40  }
41 
44 
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 
67 
68  X left() const { return top_left.x; }
69  X right() const { return bottom_right().x; }
70  Y top() const { return top_left.y; }
71  Y bottom() const { return bottom_right().y; }
72 };
73 
74 inline constexpr bool operator == (Rectangle const& lhs, Rectangle const& rhs)
75 {
76  return lhs.top_left == rhs.top_left && lhs.size == rhs.size;
77 }
78 
79 inline constexpr bool operator != (Rectangle const& lhs, Rectangle const& rhs)
80 {
81  return lhs.top_left != rhs.top_left || lhs.size != rhs.size;
82 }
83 
84 std::ostream& operator<<(std::ostream& out, Rectangle const& value);
85 }
86 }
87 
88 #endif /* MIR_GEOMETRY_RECTANGLE_H_ */
std::ostream & operator<<(std::ostream &out, Displacement const &value)
constexpr bool operator==(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:52
constexpr bool operator!=(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:57
Definition: splash_session.h:24
Definition: point.h:31
Y y
Definition: point.h:40
X x
Definition: point.h:39
Definition: rectangle.h:34
Size size
Definition: rectangle.h:43
X right() const
Definition: rectangle.h:69
X left() const
Definition: rectangle.h:68
Y bottom() const
Definition: rectangle.h:71
constexpr Rectangle()=default
bool overlaps(Rectangle const &r) const
Point bottom_right() const
The bottom right boundary point of the rectangle.
constexpr Rectangle(Point const &top_left, Size const &size)
Definition: rectangle.h:37
Point top_left
Definition: rectangle.h:42
bool contains(Rectangle const &r) const
Test if the rectangle contains another.
bool contains(Point const &p) const
Point bottom_left() const
Rectangle intersection_with(Rectangle const &r) const
Y top() const
Definition: rectangle.h:70
Definition: size.h:32

Copyright © 2012-2021 Canonical Ltd.
Generated on Wed Mar 31 08:25:47 UTC 2021
This documentation is licensed under the GPL version 2 or 3.