File: coord-circle.h

package info (click to toggle)
crawl 2%3A0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 100,188 kB
  • sloc: cpp: 363,709; ansic: 27,765; javascript: 9,516; python: 8,463; perl: 3,293; java: 3,132; xml: 2,380; makefile: 1,835; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (69 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (5)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

enum circle_type
{
    C_CIRCLE,      // circle specified by pre-squared radius
    C_POINTY,      // circle with square radius r*r
    C_ROUND,       // circle with square radius r*r+1
    C_SQUARE,      // square with radius r
};

class rectangle_iterator;
class rect_def
{
    coord_def min;
    coord_def max;

public:
    rect_def() {}
    rect_def(const coord_def &min_, const coord_def &max_)
        : min(min_), max(max_) {}

    bool contains(const coord_def& p) const PURE;
    rect_def intersect(const rect_def& other) const PURE;
    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)))

/*
 * Circles of different shapes; see circle_type for these.
 *
 * radius/radius_sq don't have meaning when global_los_radius is set.
 */
class circle_def
{
    // Are we tracking global LOS radius?
    bool global_los_radius;

    // Check against map bounds for containment?
    bool check_bounds;

    coord_def origin;

    int radius;
    int radius_sq;
    rect_def bbox;
    bool is_square;

public:
    // Circle around (0,0) with radius that tracks global LOS radius.
    // No bounds checking.
    circle_def();
    // Circle around origin with shape of given circle.
    circle_def(const coord_def &origin_, const circle_def &bds);
    // Circle around (0,0) of specified shape and size.
    // No bounds checking.
    explicit circle_def(int param, circle_type ctype);
    // Circle around given origin of specified shape and size.
    circle_def(const coord_def &origin_, int param, circle_type ctype);

    bool contains(const coord_def &p) const PURE;
    const rect_def& get_bbox() const PURE;
    const coord_def& get_center() const PURE;

private:
    void init(int param, circle_type ctype);
    void init_bbox();
};