]> git.decadent.org.uk Git - videolink.git/blobdiff - geometry.hpp
Moved generation of menu VOBs from videolink_window to dvd_generator.
[videolink.git] / geometry.hpp
diff --git a/geometry.hpp b/geometry.hpp
new file mode 100644 (file)
index 0000000..a263327
--- /dev/null
@@ -0,0 +1,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