-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.cpp
153 lines (123 loc) · 3.33 KB
/
View.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
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
//
// Created by Admin on 6/18/2021.
//
#include <algorithm>
#include <map>
#include "Model.h"
View::View(int currentSize, const Point &origin, int scale) :
_displaySize(currentSize), _scale(scale), _origin(origin) {
}
int View::getDisplaySize() const {
return _displaySize;
}
void View::size(int currentSize) {
if (currentSize <= MAX_MAP_SIZE && currentSize >= MIN_MAP_SIZE)
_displaySize = currentSize;
}
const Point& View::getOrigin() const {
return _origin;
}
void View::pan(const Point &origin) {
_origin.x = origin.x;
_origin.y = origin.y;
}
void View::zoom(int zoom) {
_scale = zoom;
}
std::string isThereAnObjectAtInterval(Point a, int _scale) {
for (auto &i : Model::get_Instance().getSimObjectVector()) {
if (inProximity(a, i->getPosition(), _scale))
return i->getName();
}
return "";
}
void View::show() {
//print first line ;stats
cout << "Display size: " << _displaySize << ", scale: " << _scale
<< ", origin: ";
std::map<string, int> sample_map;
int interval = (3 * _scale);
_origin.print();
cout << endl;
int Min_Y = _origin.y;
int isThere_A_Negative_Y_Value = (Min_Y < 0) ? 1 : 0;
int initialY = _origin.y + interval;
int Max_y = initialY + (floor(_displaySize / 3) - 1) * interval;
int numOfSpaces = max(log10(Max_y),
log10(abs(Min_Y)) + isThere_A_Negative_Y_Value) + 1;
int D = 0;
for (int i = _displaySize + _origin.y - 1; i >= _origin.y; --i) {
//print the y values
if (D % 3 == 0) {
cout << std::right << setw(numOfSpaces) << Max_y << " ";
Max_y -= interval;
} else {
if (_origin.y < 0)
cout << setw(2 * numOfSpaces);
else
cout << setw(2 * numOfSpaces + 1);
}
D++;
//print each point
for (int j = _origin.x; j < _displaySize + _origin.x; j++) {
//find if a point is in _scale range of every point we are checking
std::string Name = isThereAnObjectAtInterval(
Point(ceil(abs(_origin.x) + j * _scale),ceil(abs(_origin.y) + i * _scale)), _scale);
if (Name.empty())
cout << ". ";
else{
if (sample_map.find(Name) == sample_map.end())
{
sample_map.insert( { Name, 1 });
}
else if (sample_map.find(Name) != sample_map.end())
{
sample_map.find(Name)->second++;
}
if(sample_map.find(Name)->second == 1)
cout << Name;
else
cout << ". ";
}
}
cout << endl;
}
cout << setw(numOfSpaces + log10(abs(_origin.y)) + 1) << std::right
<< getOrigin().x;
int initial = _origin.x + interval;
for (int j = 0; j < _displaySize / 3; j++) {
cout << std::right << setw(6) << initial;
initial += interval;
}
cout << endl;
}
int View::getScale() const {
return _scale;
}
void View::setScale(int scale) {
_scale = scale;
}
void View::setDisplaySize(int displaySize) {
_displaySize = displaySize;
}
void View::setOrigin(const Point &origin) {
_origin = origin;
}
void View::defaultSettings() {
this->size(DEFAULT_SIZE);
this->setOrigin(DEFAULT_ORIGIN);
this->zoom(DEFAULT_ZOOM);
}
View::View() {
this->size(DEFAULT_SIZE);
this->setOrigin(DEFAULT_ORIGIN);
this->zoom(DEFAULT_ZOOM);
}
std::string isThereAnObjectAt(Point a) {
for (auto &i : Model::get_Instance().getSimObjectVector()) {
if (a.x == floor(i->getPosition().x)
&& a.y == floor(i->getPosition().y))
return i->getName();
}
return "";
}