X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Frect.h;h=1feb8ad4fed460d19a9f83439e21bdd0abcc1ea0;hb=7979aeb87a83de31c4cf25f88eef4fbca4b56553;hp=df18698419135176c6426b010e1c254d5146ee42;hpb=320a74efb8d9c8aacded2799459a92d5b7235d90;p=dcpomatic.git diff --git a/src/lib/rect.h b/src/lib/rect.h index df1869841..1feb8ad4f 100644 --- a/src/lib/rect.h +++ b/src/lib/rect.h @@ -17,8 +17,8 @@ */ -#ifndef DVDOMATIC_RECT_H -#define DVDOMATIC_RECT_H +#ifndef DCPOMATIC_RECT_H +#define DCPOMATIC_RECT_H #include "position.h" @@ -42,6 +42,13 @@ public: , height (0) {} + Rect (Position p, T w_, T h_) + : x (p.x) + , y (p.y) + , width (w_) + , height (h_) + {} + Rect (T x_, T y_, T w_, T h_) : x (x_) , y (y_) @@ -54,11 +61,13 @@ public: T width; T height; - Position position () const { + Position position () const + { return Position (x, y); } - Rect intersection (Rect const & other) const { + Rect intersection (Rect const & other) const + { T const tx = max (x, other.x); T const ty = max (y, other.y); @@ -69,7 +78,16 @@ public: ); } - bool contains (Position p) const { + void extend (Rect const & other) + { + 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; + } + + bool contains (Position p) const + { return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height)); } };