-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube.h
More file actions
58 lines (52 loc) · 1.32 KB
/
Copy pathcube.h
File metadata and controls
58 lines (52 loc) · 1.32 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
#include <array>
#include <deque>
#include <algorithm>
struct Point final
{
public:
std::array<size_t, 3> coordinates = {0,0,0};
Point() = default;
Point(std::array<size_t, 3> _coord) :coordinates(_coord) {};
Point(size_t byte) { coordinates[byte] = 1; }
Point operator+(Point& other)
{
return Point(std::array<size_t, 3>({ coordinates[0] + other.coordinates[0],
coordinates[1] + other.coordinates[1],
coordinates[2] + other.coordinates[2] }));
}
};
class Cube final
{
public:
std::deque<Point> vertex;
Cube()
{
vertex = halfeCube();
std::deque<Point> pointsInverted(vertex.size());
std::transform(vertex.begin(),vertex.end(),pointsInverted.begin(),[](Point point)
{
for (size_t i = 0; i < 3; ++i)
point.coordinates[i] = point.coordinates[i] ? 0 : 1;
return point;
});
vertex.insert(vertex.end(), pointsInverted.begin(), pointsInverted.end());
}
std::deque<Point> halfeCube() const
{
std::deque<Point> points;
for (size_t i = 0; i < 3; ++i)
for (size_t j = 0; j < 3; ++j)
points.emplace_back(i);
points.push_back(points.front());
points.pop_front();
size_t j = points.size();
for (size_t i = 0; i < j; ++++++i)
{
points[i] = Point();
points.push_back(points[i + 1]);
points.push_back(points[i + 2]);
points.push_back(points[i + 1] + points[i+2]);
}
return points;
}
};