diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-03-25 09:41:36 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-03-25 09:41:36 +0000 |
| commit | ee77b3cf5f59f775e75e628aa28e8f2f9f941530 (patch) | |
| tree | bbf9ab4ef1f0f633591889cbbd6b7b65de8f5a57 /src/lib/rect.h | |
| parent | e6f28e7cda23c1ba3c49cc1bf2dc1491c2f87160 (diff) | |
It builds.
Diffstat (limited to 'src/lib/rect.h')
| -rw-r--r-- | src/lib/rect.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/lib/rect.h b/src/lib/rect.h index 6f4709c08..1feb8ad4f 100644 --- a/src/lib/rect.h +++ b/src/lib/rect.h @@ -42,6 +42,13 @@ public: , height (0) {} + Rect (Position<T> 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<T> position () const { + Position<T> position () const + { return Position<T> (x, y); } - Rect<T> intersection (Rect<T> const & other) const { + Rect<T> intersection (Rect<T> 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<T> p) const { + void extend (Rect<T> 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<T> p) const + { return (p.x >= x && p.x <= (x + width) && p.y >= y && p.y <= (y + height)); } }; |
