Release versions 1.2.11 and 1.2.11-1
[videolink.git] / geometry.hpp
1 // Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #ifndef INC_GEOMETRY_HPP
5 #define INC_GEOMETRY_HPP
6
7 struct rectangle
8 {
9     int left, top;     // inclusive
10     int right, bottom; // exclusive
11
12     rectangle operator|=(const rectangle & other)
13         {
14             if (other.empty())
15             {
16                 // use current extents unchanged
17             }
18             else if (empty())
19             {
20                 // use other extents
21                 *this = other;
22             }
23             else
24             {
25                 // find rectangle enclosing both extents
26                 left = std::min(left, other.left);
27                 top = std::min(top, other.top);
28                 right = std::max(right, other.right);
29                 bottom = std::max(bottom, other.bottom);
30             }
31
32             return *this;
33         }
34
35     rectangle operator&=(const rectangle & other)
36         {
37             // find rectangle enclosed in both extents
38             left = std::max(left, other.left);
39             top = std::max(top, other.top);
40             right = std::max(left, std::min(right, other.right));
41             bottom = std::max(top, std::min(bottom, other.bottom));
42             return *this;
43         }
44
45     bool empty() const
46         {
47             return left == right || bottom == top;
48         }
49 };
50
51 #endif // !INC_GEOMETRY_HPP