Supporters update.
[dcpomatic.git] / src / lib / rect.h
index d0daec43712ab4c5cd7a0bf88cf27c3c5fc69a74..a01e0f8858ffba6d31eb6b9675d0cff571b4571d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #ifndef DCPOMATIC_RECT_H
 #define DCPOMATIC_RECT_H
 
+
 #include "position.h"
 #include <boost/optional.hpp>
 #include <algorithm>
 
+
 /* Put this inside a namespace as Apple put a Rect in the global namespace */
 
 namespace dcpomatic
 {
 
+
 /** @struct Rect
  *  @brief A rectangle.
  */
@@ -69,7 +73,7 @@ public:
                return Position<T> (x, y);
        }
 
-       boost::optional<Rect<T> > intersection (Rect<T> const & other) const
+       boost::optional<Rect<T>> intersection (Rect<T> const & other) const
        {
                /* This isn't exactly the paragon of mathematical precision */
 
@@ -83,7 +87,7 @@ public:
                        );
 
                if (r.width < 0 || r.height < 0) {
-                       return boost::optional<Rect<T> > ();
+                       return {};
                }
 
                return r;
@@ -91,10 +95,12 @@ public:
 
        void extend (Rect<T> const & other)
        {
+               T old_x = x;
+               T old_y = y;
                x = std::min (x, other.x);
                y = std::min (y, other.y);
-               width = std::max (x + width, other.x + other.width) - x;
-               height = std::max (y + height, other.y + other.height) - y;
+               width = std::max (old_x + width, other.x + other.width) - x;
+               height = std::max (old_y + height, other.y + other.height) - y;
        }
 
        Rect<T> extended (T amount) const {
@@ -112,6 +118,15 @@ public:
        }
 };
 
+
+template <class T>
+bool operator== (Rect<T> const& a, Rect<T> const& b)
+{
+       return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
 }
 
+
+}
+
+
 #endif