aboutsummaryrefslogtreecommitdiff
path: root/geometry.h
blob: d7a10b89d2ee3f5f13869186da4b75afd94c139f (plain)
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
#ifndef GEOMETRY_H
#define GEOMETRY_H

struct vec2
{
    float x, y;

    void set(float _x, float _y) {
        x = _x;
        y = _y;
    }
};

class RectF
{
public:
    RectF(float, float, float, float);
    RectF(const RectF &);
    RectF(const vec2 &, const vec2 &);

    float x() const { return m_x; }
    float y() const { return m_y; }
    float width() const { return m_width; }
    float height() const { return m_height; }

    bool contains(float x, float y) const;
    bool contains(const vec2 &) const;
    bool intersects(const RectF &) const;

private:
    float m_x, m_y, m_width, m_height;
};

class Geometry
{
public:
    Geometry();

    int vertexCount() const;
    vec2 *vertexDataAsPoint2D();

private:
};

// Circle
int calculateCircleVertexCount(float radius);
void updateCircleGeometry(Geometry *geometry, float radius, float cx, float cy);

// Rect
void updateRectGeometry(Geometry *geometry, float x, float y, float w, float h);

// Crosshair
void updateCrossHairGeometry(Geometry *geometry,
                             float x,
                             float y,
                             float thickness,
                             float length);
#endif // GEOMETRY_H