-
Notifications
You must be signed in to change notification settings - Fork 12
/
Vec.h
55 lines (49 loc) · 1.14 KB
/
Vec.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
#pragma once
#include "Point.h"
#include "constants.h"
class Vec {
public:
Point points[MAX_VEC_SIZE];
int size;
public:
Vec() : size(0) {
}
Vec(const Vec &o) : size(o.size) {
for (int i = 0; i < size; ++i) {
points[i] = o.points[i];
}
}
Point operator[](const int &i) const {
return points[i];
}
Point& operator[](const int &i) {
return points[i];
}
void push(const Point &p) {
points[size++] = p;
}
Point remove(int idx) {
Point ret = points[idx];
points[idx] = points[--size];
return ret;
}
Vec& operator+=(const Vec &o) {
for (int i=0; i < o.size; ++i) {
push(o[i]);
}
return *this;
}
};
#ifdef DEBUG
# include "constants.h"
# include <iostream>
inline std::ostream& operator<<(std::ostream &o, const Vec &vec) {
for (int i=0; i < vec.size; ++i) {
if (i > 0) {
o << ", ";
}
o << vec[i];
}
return o;
}
#endif