region: add per-axis expansion calls

This commit is contained in:
Danny Robson 2015-02-04 15:44:51 +11:00
parent 3e9f5efbe0
commit 1db9057c95
2 changed files with 33 additions and 11 deletions

View File

@ -225,28 +225,46 @@ util::region<T>::inset (T mag)
//-----------------------------------------------------------------------------
template <typename T>
util::region<T>&
util::region<T>::expand (T mag)
util::region<T>::expand (T _w, T _h)
{
x -= mag;
y -= mag;
w += mag * 2;
h += mag * 2;
x -= _w;
y -= _h;
w += _w * 2;
h += _h * 2;
return *this;
}
//-----------------------------------------------------------------------------
template <typename T>
util::region<T>&
util::region<T>::expand (T mag)
{
return expand (mag, mag);
}
//-----------------------------------------------------------------------------
template <typename T>
util::region<T>
util::region<T>::expanded (T _w, T _h) const
{
return {
x - _w,
y - _h,
w + _w * 2,
h + _h * 2,
};
}
//-----------------------------------------------------------------------------
template <typename T>
util::region<T>
util::region<T>::expanded (T mag) const
{
return {
x - mag,
y - mag,
w + mag * 2,
h + mag * 2,
};
return expanded (mag, mag);
}
//-----------------------------------------------------------------------------

View File

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