-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilemodel.cpp
executable file
·96 lines (83 loc) · 2.1 KB
/
tilemodel.cpp
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
#include "tilemodel.h"
#include <QPainter>
#include <QDebug>
#include <QTimer>
#include <QTime>
TileModel::TileModel(QObject *parent) :
QObject(parent)
{
}
void TileModel::adjustNodes(int times)
{
for (int i = 0; i < times; ++i) {
bool temp = this->north;
this->north = this->west;
this->west = this->south;
this->south = this->east;
this->east = temp;
}
}
QVector<bool> TileModel::getNodeVector()
{
return {this->north, this->east, this->south, this->west};
}
void TileModel::rotate90()
{
this->adjustNodes();
this->rotateAngle += 90;
}
QString TileModel::getNodeString()
{
QString nodeString = "";
if (this->north)
nodeString += "0";
if (this->east)
nodeString += "1";
if (this->south)
nodeString += "2";
if (this->west)
nodeString += "3";
return nodeString;
}
QString TileModel::getNodeString(const QVector<bool>& tile)
{
QString nodeString = "";
if (tile[TileModel::North])
nodeString += "0";
if (tile[TileModel::East])
nodeString += "1";
if (tile[TileModel::South])
nodeString += "2";
if (tile[TileModel::West])
nodeString += "3";
return nodeString;
}
QString TileModel::getTileTypeByVector(const QVector<bool>& tile)
{
QString nodeString = TileModel::getNodeString(tile);
if (nodeString.size() == 1) {
return "EndTile";
} else if (nodeString.size() == 3) {
return "JunctionTile";
} else {
int first = nodeString[0].digitValue(), second = nodeString[1].digitValue();
if (first > second) {
int temp = first;
first = second;
second = temp;
}
if (second - first == 1 || second - first == 3)
return "CornerTile";
else
return "LineTile";
}
return "Tile";
}
size_t TileModel::countNodes(const QVector<bool>& tile)
{
int count = 0;
for (const bool &node : tile)
if (node)
++count;
return count;
}