Repository navigation
Expand file tree
/
Copy pathDrivewayObject.cpp
More file actions
198 lines (182 loc) · 5.28 KB
/
Copy pathDrivewayObject.cpp
File metadata and controls
198 lines (182 loc) · 5.28 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "AllRtmClasses.h"
rtm::DrivewayObject::DrivewayObject()
: CoatingUnion{}
, angle_{ Up }
, length_{ 0.f }
, linesCount_{ 0 }
{}
rtm::DrivewayObject::DrivewayObject(CoatingType type, int column, int row, size_t width, size_t height, AngleType angle)
: CoatingUnion{ DrivewayType, column, row, std::move(DrivewayObject::DrivewayMatrix(type, column, row, width, height, angle)) }
, angle_{ angle }
, length_{ CountLength_(GetWidth(), GetHeight(), angle) }
, linesCount_{ CountLines_(GetWidth(), GetHeight(), angle) }
{}
rtm::CoatingMatrix rtm::DrivewayObject::DrivewayMatrix(CoatingType type, int column, int row, size_t width, size_t height, AngleType angle)
{
CoatingMatrix result{ width };
for (size_t i = 0; i < width; ++i) {
result[i] = CoatingVector{ height };
for (size_t j = 0; j < height; ++j) {
size_t id{ 0 };
AngleType extraDirection{ Up };
// Choose properties of road
if (angle == Up || angle == Down) {
if (width == 1) {
id = RoadTypeNo0;
}
else if (i == 0) {
id = RoadTypeNo1;
if (angle == Down) {
extraDirection = Down;
}
}
else if (i == width - 1) {
id = RoadTypeNo1;
if (angle == Up) {
extraDirection = Down;
}
}
else {
id = RoadTypeNo2;
}
}
else if (angle == Right || angle == Left) {
if (height == 1) {
id = RoadTypeNo0;
}
else if (j == 0) {
id = RoadTypeNo1;
if (angle == Right) {
extraDirection = Down;
}
}
else if (j == height - 1) {
id = RoadTypeNo1;
if (angle == Left) {
extraDirection = Down;
}
}
else {
id = RoadTypeNo2;
}
}
// Make road
result[i][j] = std::make_unique<RoadCoating>(type, id, column + i, row + j, SumAngleTypes(angle, extraDirection));
// Block backward direction
result[i][j]->SetDirectionAvailability(
SumAngleTypes(angle, DownLeft), false
);
result[i][j]->SetDirectionAvailability(
SumAngleTypes(angle, Down), false
);
result[i][j]->SetDirectionAvailability(
SumAngleTypes(angle, DownRight), false
);
}
}
return result;
}
float rtm::DrivewayObject::GetLength() const
{
return length_;
}
size_t rtm::DrivewayObject::GetLinesCount() const
{
return linesCount_;
}
bool rtm::DrivewayObject::isRightLine(int column, int row) const
{
if (angle_ == Up) {
return column == GetColumn_() + GetWidth() - 1;
}
else if (angle_ == Left) {
return row == GetRow_() + GetHeight() - 1;
}
else if (angle_ == Down) {
return column == GetColumn_();
}
else if (angle_ == Right) {
return row == GetRow_();
}
else {
return false;
}
}
bool rtm::DrivewayObject::isRightLine(float x, float y) const
{
if (angle_ == Up) {
return PixelToCell(x) == GetColumn_() + GetWidth() - 1;
}
else if (angle_ == Left) {
return PixelToCell(y) == GetRow_() + GetHeight() - 1;
}
else if (angle_ == Down) {
return PixelToCell(x) == GetColumn_();
}
else if (angle_ == Right) {
return PixelToCell(y) == GetRow_();
}
else {
return false;
}
}
bool rtm::DrivewayObject::isLeftLine(int column, int row) const
{
if (angle_ == Up) {
return column == GetColumn_();
}
else if (angle_ == Left) {
return row == GetRow_();
}
else if (angle_ == Down) {
return column == GetColumn_() + GetWidth() - 1;
}
else if (angle_ == Right) {
return row == GetRow_() + GetHeight() - 1;
}
else {
return false;
}
}
bool rtm::DrivewayObject::isLeftLine(float x, float y) const
{
if (angle_ == Up) {
return PixelToCell(x) == GetColumn_();
}
else if (angle_ == Left) {
return PixelToCell(y) == GetRow_();
}
else if (angle_ == Down) {
return PixelToCell(x) == GetColumn_() + GetWidth() - 1;
}
else if (angle_ == Right) {
return PixelToCell(y) == GetRow_() + GetHeight() - 1;
}
else {
return false;
}
}
float rtm::DrivewayObject::CountLength_(size_t width, size_t height, AngleType angle)
{
if (angle == Up || angle == Down) {
return static_cast<float>(height);
}
else if (angle == Left || angle == Right) {
return static_cast<float>(width);
}
else {
return 0.f;
}
}
size_t rtm::DrivewayObject::CountLines_(size_t width, size_t height, AngleType angle)
{
if (angle == Up || angle == Down) {
return width;
}
else if (angle == Left || angle == Right) {
return height;
}
else {
return 0;
}
}