diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-14 21:06:47 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-14 21:06:47 +0100 |
| commit | 009a58293bf2e9727d544d1a2648422cc395d81e (patch) | |
| tree | c581d457104195a0219a0197c523981756bf9ecd /src/lib/util.cc | |
| parent | b5001080a3e5b414f6cad1c52926ed757f2d8574 (diff) | |
| parent | ade28a703b15af710161faa017cddf95d66c4118 (diff) | |
Merge branch 'subs'
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index 935566440..c3dd13d7c 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -600,3 +600,23 @@ Socket::read_indefinite (uint8_t* data, int size, int timeout) assert (size >= _buffer_data); memcpy (data, _buffer, size); } + +Rectangle +Rectangle::intersection (Rectangle const & other) const +{ + int const tx = max (x, other.x); + int const ty = max (y, other.y); + + return Rectangle ( + tx, ty, + min (x + w, other.x + other.w) - tx, + min (y + h, other.y + other.h) - ty + ); +} + +int +round_up (int a, int t) +{ + a += (t - 1); + return a - (a % t); +} |
