From 1f4a744b299ec58897800ccd00e05f3d223badf2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 20 Oct 2011 23:53:18 +1100 Subject: [PATCH] Add centre method to region --- region.cpp | 10 ++++++++++ region.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/region.cpp b/region.cpp index c50239e4..5e9a67c4 100644 --- a/region.cpp +++ b/region.cpp @@ -98,6 +98,16 @@ region::empty (void) const { return almost_equal (area (), 0); } +template +point +region::centre (void) const { + double cx = x + static_cast(width / 2.0), + cy = y + static_cast(height / 2.0); + + return { cx, cy, 0.0 }; +} + + template bool region::includes (const point &p) const { diff --git a/region.hpp b/region.hpp index 788ec277..cb47d3bc 100644 --- a/region.hpp +++ b/region.hpp @@ -56,6 +56,7 @@ namespace util { T area (void) const; bool empty (void) const; + point centre (void) const; bool includes (const point&) const; // inclusive of borders bool contains (const point&) const; // exclusive of borders