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> template <typename T>
util::region<T>& util::region<T>&
util::region<T>::expand (T mag) util::region<T>::expand (T _w, T _h)
{ {
x -= mag; x -= _w;
y -= mag; y -= _h;
w += mag * 2; w += _w * 2;
h += mag * 2; h += _h * 2;
return *this; 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> template <typename T>
util::region<T> util::region<T>
util::region<T>::expanded (T mag) const util::region<T>::expanded (T mag) const
{ {
return { return expanded (mag, mag);
x - mag,
y - mag,
w + mag * 2,
h + mag * 2,
};
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

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