region: add expansion methods

This commit is contained in:
Danny Robson 2015-01-22 14:58:29 +11:00
parent 7934ae865b
commit 76b51e04b2
2 changed files with 30 additions and 0 deletions

View File

@ -221,6 +221,34 @@ util::region<T>::inset (T mag)
return { x + mag, y + mag, w - 2 * mag, h - 2 * mag };
}
//-----------------------------------------------------------------------------
template <typename T>
util::region<T>&
util::region<T>::expand (T mag)
{
x -= mag;
y -= mag;
w += mag * 2;
h += mag * 2;
return *this;
}
//-----------------------------------------------------------------------------
template <typename T>
util::region<T>
util::region<T>::expanded (T mag) const
{
return {
x - mag,
y - mag,
w + mag * 2,
h + mag * 2,
};
}
//-----------------------------------------------------------------------------
template <typename T>
bool

View File

@ -64,6 +64,8 @@ namespace util {
// Compute a region `mag` units into the region
region inset (T mag);
region expanded (T mag) const;
region& expand (T mag);
// Logical comparison operators
bool operator ==(const region<T>& rhs) const;