Implemented util::rects_overlap and documented util
This commit is contained in:
parent
6f7fa0613e
commit
caea5b9236
3 changed files with 27 additions and 0 deletions
|
|
@ -148,6 +148,11 @@ namespace widgets {}
|
|||
*/
|
||||
namespace workspace {}
|
||||
|
||||
/**
|
||||
* The namespace of utility functions and classes.
|
||||
*/
|
||||
namespace util {}
|
||||
|
||||
} // namespace gui
|
||||
|
||||
#endif // GTK_LUMIERA_HPP
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@
|
|||
* *****************************************************/
|
||||
|
||||
#include "rectangle.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue