-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometry.h
More file actions
152 lines (82 loc) · 2.7 KB
/
geometry.h
File metadata and controls
152 lines (82 loc) · 2.7 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef GEOMETRY_H
#define GEOMETRY_H
#include <cstdint>
#include <vector>
// Classes
class BasicPair;
class Position;
class Vector;
class Rectangle;
class Rectangles;
// Usings
using grid_t = int32_t;
using area_t = uint64_t;
using recs_t = std::vector<Rectangle>;
class BasicPair {
protected:
grid_t x_val, y_val;
public:
BasicPair(grid_t x, grid_t y);
grid_t x() const;
grid_t y() const;
};
class Position : public BasicPair {
public:
Position(grid_t x, grid_t y);
explicit Position(const Vector& v);
static const Position& origin();
Position reflection() const;
bool operator==(const Position& other) const;
Position& operator+=(const Vector& rhs);
};
class Vector : public BasicPair {
public:
Vector(grid_t x, grid_t y);
explicit Vector(const Position& p);
Vector reflection() const;
bool operator==(const Vector& other) const;
Vector& operator+=(const Vector& rhs);
};
class Rectangle {
Position lower_left;
grid_t width_val, height_val;
public:
Rectangle(grid_t width, grid_t height);
Rectangle(grid_t width, grid_t height, const Position& pos);
area_t area() const;
grid_t width() const;
grid_t height() const;
Position pos() const;
Rectangle reflection() const;
bool operator==(const Rectangle& other) const;
Rectangle& operator+=(const Vector& rhs);
};
class Rectangles {
recs_t recs;
public:
Rectangles() = default;
Rectangles(std::initializer_list<Rectangle> list);
Rectangles(const Rectangles& rectangles) = default;
Rectangles(Rectangles&& rectangles) noexcept;
size_t size() const;
bool operator==(const Rectangles& other) const;
Rectangles& operator+=(const Vector& rhs);
Rectangle& operator[](size_t i);
const Rectangle& operator[](size_t i) const;
Rectangles& operator=(Rectangles&& rectangles) noexcept = default;
Rectangles& operator=(const Rectangles& rectangles) = default;
};
// Non-member functions
Position operator+(const Position& p, const Vector& v);
Position operator+(const Vector& v, const Position& p);
Vector operator+(const Vector& v1, const Vector& v2);
Rectangle operator+(const Rectangle& rec, const Vector& v);
Rectangle operator+(const Vector& v, const Rectangle& r);
Rectangles operator+(const Vector& v, const Rectangles& recs);
Rectangles operator+(const Vector& v, Rectangles&& recs);
Rectangles operator+(const Rectangles& recs, const Vector& v);
Rectangles operator+(Rectangles&& recs, const Vector& v);
Rectangle merge_horizontally(const Rectangle& r1, const Rectangle& r2);
Rectangle merge_vertically(const Rectangle& r1, const Rectangle& r2);
Rectangle merge_all(const Rectangles& recs);
#endif