File: geometry.hpp

package info (click to toggle)
videolink 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 368 kB
  • ctags: 502
  • sloc: cpp: 3,210; ansic: 880; makefile: 121
file content (51 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
// See the file "COPYING" for licence details.

#ifndef INC_GEOMETRY_HPP
#define INC_GEOMETRY_HPP

struct rectangle
{
    int left, top;     // inclusive
    int right, bottom; // exclusive

    rectangle operator|=(const rectangle & other)
	{
	    if (other.empty())
	    {
		// use current extents unchanged
	    }
	    else if (empty())
	    {
		// use other extents
		*this = other;
	    }
	    else
	    {
		// find rectangle enclosing both extents
		left = std::min(left, other.left);
		top = std::min(top, other.top);
		right = std::max(right, other.right);
		bottom = std::max(bottom, other.bottom);
	    }

	    return *this;
	}

    rectangle operator&=(const rectangle & other)
	{
	    // find rectangle enclosed in both extents
	    left = std::max(left, other.left);
	    top = std::max(top, other.top);
	    right = std::max(left, std::min(right, other.right));
	    bottom = std::max(top, std::min(bottom, other.bottom));
	    return *this;
	}

    bool empty() const
	{
	    return left == right || bottom == top;
	}
};

#endif // !INC_GEOMETRY_HPP