Use get_pixel_size rather than get_size which is slightly nicer as we then don't...
[dcpomatic.git] / src / lib / rect.h
index 1feb8ad4fed460d19a9f83439e21bdd0abcc1ea0..5758dd04e4496955af9b7cc994c492bf785c40b6 100644 (file)
 #define DCPOMATIC_RECT_H
 
 #include "position.h"
+#include <algorithm>
 
 /* Put this inside a namespace as Apple put a Rect in the global namespace */
 
 namespace dcpomatic
 {
-       
+
 /** @struct Rect
  *  @brief A rectangle.
  */
-template <class T>     
+template <class T>
 class Rect
 {
 public:
-       
+
        Rect ()
                : x (0)
                , y (0)
@@ -70,7 +71,7 @@ public:
        {
                T const tx = max (x, other.x);
                T const ty = max (y, other.y);
-       
+
                return Rect (
                        tx, ty,
                        min (x + width, other.x + other.width) - tx,
@@ -86,6 +87,15 @@ public:
                height = std::max (y + height, other.y + other.height) - y;
        }
 
+       Rect<T> extended (T amount) const {
+               Rect<T> c = *this;
+               c.x -= amount;
+               c.y -= amount;
+               c.width += amount * 2;
+               c.height += amount * 2;
+               return c;
+       }
+
        bool contains (Position<T> p) const
        {
                return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height));