-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPolygone.h
66 lines (56 loc) · 1.14 KB
/
Polygone.h
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
#if !defined(POLYGONE)
#define POLYGONE
#include "./Point.h"
#include "./Line.h"
#include <vector>
template <typename T>
struct Polygone
{
std::vector<Point<T>> points;
int iteratorIndex;
Polygone()
{
iteratorIndex = 0;
}
Polygone(std::vector<Point<T>> points)
{
iteratorIndex = 0;
this->points = points;
}
void addPoint(Point<T> point)
{
points.push_back(point);
}
void addPointOffset(int index, T dx, T dy)
{
if (index >= points.size())
return;
points[index].x += dx;
points[index].y += dy;
}
void resetIterator()
{
iteratorIndex = 0;
}
bool hasNext()
{
return iteratorIndex < points.size();
}
Point<T> getNext()
{
if (!hasNext())
return Point<T>();
return points[iteratorIndex++];
}
Point<T> getPoint(int index)
{
if (index >= points.size())
return Point<T>();
return points[index++];
}
Line<T> getConnectedLine(int i, int j)
{
return Line<T>(getPoint(i), getPoint(j));
}
};
#endif // POLYGONE