From 1db9057c95d6bf4836954fbce2e75dfba3600015 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 4 Feb 2015 15:44:51 +1100 Subject: [PATCH] region: add per-axis expansion calls --- region.cpp | 40 +++++++++++++++++++++++++++++----------- region.hpp | 4 ++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/region.cpp b/region.cpp index 000321b0..545a2f39 100644 --- a/region.cpp +++ b/region.cpp @@ -225,28 +225,46 @@ util::region::inset (T mag) //----------------------------------------------------------------------------- template util::region& -util::region::expand (T mag) +util::region::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 +util::region& +util::region::expand (T mag) +{ + return expand (mag, mag); +} + + +//----------------------------------------------------------------------------- +template +util::region +util::region::expanded (T _w, T _h) const +{ + return { + x - _w, + y - _h, + w + _w * 2, + h + _h * 2, + }; +} + + //----------------------------------------------------------------------------- template util::region util::region::expanded (T mag) const { - return { - x - mag, - y - mag, - w + mag * 2, - h + mag * 2, - }; + return expanded (mag, mag); } //----------------------------------------------------------------------------- diff --git a/region.hpp b/region.hpp index 18fd7918..b8509555 100644 --- a/region.hpp +++ b/region.hpp @@ -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& rhs) const;