From caea5b9236aab4ec5e5fa582912ef25cb964d6e1 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Mon, 16 Mar 2009 22:14:22 +0000 Subject: [PATCH] Implemented util::rects_overlap and documented util --- src/gui/gtk-lumiera.hpp | 5 +++++ src/gui/util/rectangle.cpp | 15 +++++++++++++++ src/gui/util/rectangle.hpp | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/src/gui/gtk-lumiera.hpp b/src/gui/gtk-lumiera.hpp index e8cefd7b4..3a9b17159 100644 --- a/src/gui/gtk-lumiera.hpp +++ b/src/gui/gtk-lumiera.hpp @@ -148,6 +148,11 @@ namespace widgets {} */ namespace workspace {} +/** + * The namespace of utility functions and classes. + */ +namespace util {} + } // namespace gui #endif // GTK_LUMIERA_HPP diff --git a/src/gui/util/rectangle.cpp b/src/gui/util/rectangle.cpp index 6e2b2c8f1..d627ebb75 100644 --- a/src/gui/util/rectangle.cpp +++ b/src/gui/util/rectangle.cpp @@ -22,6 +22,9 @@ * *****************************************************/ #include "rectangle.hpp" +#include + +using namespace std; namespace gui { namespace util { @@ -35,6 +38,18 @@ pt_in_rect(const Gdk::Point &point, const Gdk::Rectangle &rect) point.get_y() < rect.get_y() + rect.get_height()); } +bool +rects_overlap(const Gdk::Rectangle &a, const Gdk::Rectangle &b) +{ + return ( + max(a.get_x(), b.get_x()) < + min(a.get_x() + a.get_width(), b.get_x() + b.get_width()) + && + max(a.get_y(), b.get_y()) < + min(a.get_y() + a.get_height(), b.get_y() + b.get_height()) + ); +} + } // namespace util } // namespace gui diff --git a/src/gui/util/rectangle.hpp b/src/gui/util/rectangle.hpp index 74feedbb5..47bf56ad0 100644 --- a/src/gui/util/rectangle.hpp +++ b/src/gui/util/rectangle.hpp @@ -42,6 +42,13 @@ namespace util { **/ bool pt_in_rect(const Gdk::Point &point, const Gdk::Rectangle &rect); +/** + * Tests whether two rectangles overlap. + * @param a The first rectangle. + * @param b The second rectangle. + **/ +bool rects_overlap(const Gdk::Rectangle &a, const Gdk::Rectangle &b); + } // util } // gui