From 46d8063d5ceb41d1ae6109405189b7c1baf2c211 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 13 Nov 2009 21:50:51 +0100 Subject: Add method to intersect rectangles. Also define rectangle RECT_MAP_BOUNDS and add containment check to rect_def. --- crawl-ref/source/coord-circle.cc | 15 +++++++++++++++ crawl-ref/source/coord-circle.h | 5 +++++ 2 files changed, 20 insertions(+) (limited to 'crawl-ref/source') 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 +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)); diff --git a/crawl-ref/source/coord-circle.h b/crawl-ref/source/coord-circle.h index 9cf52acbe8..9a8dc088d2 100644 --- a/crawl-ref/source/coord-circle.h +++ b/crawl-ref/source/coord-circle.h @@ -26,9 +26,14 @@ public: rect_def(const coord_def &min_, const coord_def &max_) : min(min_), max(max_) {} + bool contains(const coord_def& p) const; + rect_def intersect(const rect_def& other) const; rectangle_iterator iter() const; }; +#define RECT_MAP_BOUNDS (rect_def(coord_def(X_BOUND_1, Y_BOUND_1), \ + coord_def(X_BOUND_2, Y_BOUND_2))) + class circle_iterator; class circle_def { -- cgit v1.2.3-54-g00ecf