diff --git a/region.cpp b/region.cpp index 38008f67..b9a70ce0 100644 --- a/region.cpp +++ b/region.cpp @@ -135,6 +135,17 @@ region::overlaps (const region &rhs) const { } +//----------------------------------------------------------------------------- +template +point2 +region::constrain (const point2 &p) const { + point2 v; + v.x = std::min (std::max (static_cast (p.x), x), x + w); + v.y = std::min (std::max (static_cast (p.y), y), y + h); + + return v; +} + //----------------------------------------------------------------------------- template region diff --git a/region.hpp b/region.hpp index 73cd3011..0036255a 100644 --- a/region.hpp +++ b/region.hpp @@ -50,13 +50,15 @@ namespace util { bool empty (void) const; - point<2> base (void) const; - point<2> centre (void) const; + point2 base (void) const; + point2 centre (void) const; - bool includes (const point<2>&) const; // inclusive of borders - bool contains (const point<2>&) const; // exclusive of borders + bool includes (const point2&) const; // inclusive of borders + bool contains (const point2&) const; // exclusive of borders bool overlaps (const region&) const; // exclusive of borders + point2 constrain (const point2&) const; + region overlap (const region&) const; bool operator ==(const region& rhs) const;