X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=geometry.hpp;fp=geometry.hpp;h=a26332784c8a9008574c57cfdfdcf80f9d830870;hb=f5d9069647f70b7aab8e656f59cf42176c419461;hp=0000000000000000000000000000000000000000;hpb=1c05822d40aae48b8a9a971ba909641379d0709e;p=videolink.git diff --git a/geometry.hpp b/geometry.hpp new file mode 100644 index 0000000..a263327 --- /dev/null +++ b/geometry.hpp @@ -0,0 +1,51 @@ +// Copyright 2005-6 Ben Hutchings . +// 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