summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/coordit.h
blob: 4599eea66d7dabf9a4c7080a315d026943338803 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef COORDIT_H
#define COORDIT_H

class rectangle_iterator :
    public std::iterator<std::forward_iterator_tag, coord_def>
{
public:
    rectangle_iterator(const coord_def& corner1, const coord_def& corner2);
    explicit rectangle_iterator(int x_border_dist, int y_border_dist = -1);
    operator bool() const;
    coord_def operator *() const;
    const coord_def* operator->() const;

    rectangle_iterator& operator ++ ();
    rectangle_iterator operator ++ (int);
private:
    coord_def current, topleft, bottomright;
};

class radius_iterator : public std::iterator<std::forward_iterator_tag,
                        coord_def>
{
public:
    radius_iterator( const coord_def& center, int radius,
                     bool roguelike_metric = true,
                     bool require_los = true,
                     bool exclude_center = false,
                     const env_show_grid* losgrid = NULL );
    bool done() const;
    void reset();
    operator bool() const { return !done(); }
    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;

    coord_def location, center;
    int radius;
    bool roguelike_metric, require_los, exclude_center;
    const env_show_grid* losgrid;
    bool iter_done;
};

class adjacent_iterator : public radius_iterator
{
public:
    explicit adjacent_iterator( const coord_def& pos,
                                bool _exclude_center = true ) :
        radius_iterator(pos, 1, true, false, _exclude_center) {}
};

#endif