From b0d21459b7ec552fe6f9690d3d172bf6412551a9 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 13 Nov 2009 22:09:35 +0100 Subject: Reimplement radius_iterator on the basis of circle_def. --- crawl-ref/source/coordit.h | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'crawl-ref/source/coordit.h') diff --git a/crawl-ref/source/coordit.h b/crawl-ref/source/coordit.h index 60fbf1a669..da17c67a7b 100644 --- a/crawl-ref/source/coordit.h +++ b/crawl-ref/source/coordit.h @@ -1,6 +1,8 @@ #ifndef COORDIT_H #define COORDIT_H +#include "coord-circle.h" + class rectangle_iterator : public std::iterator { @@ -17,33 +19,53 @@ private: coord_def current, topleft, bottomright; }; +class circle_iterator +{ + const circle_def &circle; + rectangle_iterator iter; + +public: + circle_iterator(const circle_def &circle_); + + operator bool() const; + coord_def operator*() const; + + void operator++(); + void operator++(int); +}; + class los_def; class radius_iterator : public std::iterator { public: + radius_iterator(const coord_def& center, int param, + circle_type ctype, + const los_def* los = NULL, + bool exclude_center = false); radius_iterator(const coord_def& center, int radius, bool roguelike_metric = true, bool require_los = true, bool exclude_center = false, const los_def* los = NULL); - bool done() const; - void reset(); - operator bool() const { return !done(); } + radius_iterator(const los_def* los, + bool exclude_center = false); + operator bool() const; coord_def operator *() const; const coord_def* operator->() const; const radius_iterator& operator ++ (); radius_iterator operator ++ (int); + private: - void step(); - bool on_valid_square() const; + void advance(bool may_stay); + bool is_valid_square(const coord_def& p) const; - coord_def location, center; - int radius; - bool roguelike_metric, require_los, exclude_center; + circle_def circle; + circle_iterator iter; + bool exclude_center; const los_def* los; - bool iter_done; + coord_def current; }; class adjacent_iterator : public radius_iterator -- cgit v1.2.3-54-g00ecf