2
3
4
5
6
7
8
9
10
11
12
13
14
15
17#ifndef MIR_GEOMETRY_RECTANGLE_H_
18#define MIR_GEOMETRY_RECTANGLE_H_
44
45
46
47
48
66 if (
size.width ==
decltype(
size.width){} ||
size.height ==
decltype(
size.height){})
70 return p.x >=
left() && p.x < br.x &&
71 p.y >=
top() && p.y < br.y;
75
76
77
78
79
82 return r.left() >=
left() &&
83 r.left() + as_delta(r.size.width) <=
left() + as_delta(
size.width) &&
85 r.top() + as_delta(r.size.height) <=
top() + as_delta(
size.height);
90 bool disjoint = r.left() >=
right()
93 || r.bottom() <=
top()
94 ||
size.width ==
decltype(
size.width){}
95 ||
size.height ==
decltype(
size.height){}
96 || r.size.width ==
decltype(r.size.width){}
97 || r.size.height ==
decltype(r.size.height){};
113 auto const max_left = std::max(a.left(), b.left());
114 auto const min_right = std::min(a.right(), b.right());
115 auto const max_top = std::max(a.top(), b.top());
116 auto const min_bottom = std::min(a.bottom(), b.bottom());
118 if (max_left < min_right && max_top < min_bottom)
119 return {{max_left, max_top},
120 {(min_right - max_left).as_value(),
121 (min_bottom - max_top).as_value()}};
127inline constexpr bool operator == (Rectangle<T>
const& lhs, Rectangle<T>
const& rhs)
129 return lhs.top_left == rhs.top_left && lhs.size == rhs.size;
133inline constexpr bool operator != (Rectangle<T>
const& lhs, Rectangle<T>
const& rhs)
135 return lhs.top_left != rhs.top_left || lhs.size != rhs.size;
139std::ostream& operator<<(std::ostream& out, Rectangle<T>
const& value)
141 out <<
'(' << value.top_left <<
", " << value.size <<
')';
Rectangle< T > intersection_of(Rectangle< T > const &a, Rectangle< T > const &b)
Definition: rectangle.h:111
constexpr bool operator==(Rectangle< T > const &lhs, Rectangle< T > const &rhs)
Definition: rectangle.h:127
constexpr bool operator!=(Rectangle< T > const &lhs, Rectangle< T > const &rhs)
Definition: rectangle.h:133
Basic geometry types. Types for dimensions, displacements, etc. and the operations that they support.
Definition: size.h:27
Y< T > bottom() const
Definition: rectangle.h:104
constexpr Rectangle(Point< T > const &top_left, Size< T > const &size)
Definition: rectangle.h:38
Point< T > top_left
Definition: rectangle.h:106
X< T > right() const
Definition: rectangle.h:102
Point< T > bottom_right() const
The bottom right boundary point of the rectangle.
Definition: rectangle.h:49
bool contains(Point< T > const &p) const
Definition: rectangle.h:64
X< T > left() const
Definition: rectangle.h:101
Size< T > size
Definition: rectangle.h:107
Point< T > bottom_left() const
Definition: rectangle.h:59
constexpr Rectangle()=default
bool contains(Rectangle< T > const &r) const
Test if the rectangle contains another.
Definition: rectangle.h:80
bool overlaps(Rectangle< T > const &r) const
Definition: rectangle.h:88
Y< T > top() const
Definition: rectangle.h:103
Point< T > top_right() const
Definition: rectangle.h:54