summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/coord-circle.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-13 21:50:51 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-13 22:51:34 +0100
commit46d8063d5ceb41d1ae6109405189b7c1baf2c211 (patch)
treed22ea0c1968a84715dbc02ae280f2bda3f8e6cb4 /crawl-ref/source/coord-circle.cc
parentb0d21459b7ec552fe6f9690d3d172bf6412551a9 (diff)
downloadcrawl-ref-46d8063d5ceb41d1ae6109405189b7c1baf2c211.tar.gz
crawl-ref-46d8063d5ceb41d1ae6109405189b7c1baf2c211.zip
Add method to intersect rectangles.
Also define rectangle RECT_MAP_BOUNDS and add containment check to rect_def.
Diffstat (limited to 'crawl-ref/source/coord-circle.cc')
-rw-r--r--crawl-ref/source/coord-circle.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/crawl-ref/source/coord-circle.cc b/crawl-ref/source/coord-circle.cc
index 8580313e01..135924e33f 100644
--- a/crawl-ref/source/coord-circle.cc
+++ b/crawl-ref/source/coord-circle.cc
@@ -6,6 +6,21 @@
#include <cmath>
+bool rect_def::contains(const coord_def& p) const
+{
+ return (p.x >= min.x && p.x <= max.x && p.y >= min.y && p.y <= max.y);
+}
+
+rect_def rect_def::intersect(const rect_def& other) const
+{
+ rect_def res;
+ res.min.x = std::max(min.x, other.min.x);
+ res.min.y = std::max(min.y, other.min.y);
+ res.max.x = std::min(max.x, other.max.x);
+ res.max.y = std::min(max.y, other.max.y);
+ return (res);
+}
+
rectangle_iterator rect_def::iter() const
{
return (rectangle_iterator(min, max));