-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_renderer.h
193 lines (139 loc) · 5.21 KB
/
map_renderer.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
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
#pragma once
#include "svg.h"
#include "geo.h"
#include "domain.h"
#include <vector>
#include <algorithm>
namespace renderer
{
//----------------RenderSettings----------------------------
struct RenderSettings
{
double width = 0.0;
double height = 0.0;
double padding = 0.0;
double line_width = 0.0;
double stop_radius = 0.0;
int bus_label_font_size = 0;
svg::Point bus_label_offset{ 0.0, 0.0 };
int stop_label_font_size = 0;
svg::Point stop_label_offset{ 0.0, 0.0 };
svg::Color underlayer_color;
double underlayer_width = 0.0;
std::vector<svg::Color> color_palette;
};
inline const double EPSILON = 1e-6;
bool IsZero(const double& value);
//----------------SphereProjector----------------------------
//êëàññ, êîòîðûé ïðîåöèðóåò òî÷êè íà êàðòó
class SphereProjector
{
public:
template <typename PointInputIt>
SphereProjector(const PointInputIt& points_begin, const PointInputIt& points_end, const double& max_width, const double& max_height, const double& padding);
svg::Point operator()(const geo::Coordinates& coords) const;
private:
double padding_;
double min_lon_ = 0;
double max_lat_ = 0;
double zoom_coeff_ = 0;
};
template<typename PointInputIt>
inline SphereProjector::SphereProjector(const PointInputIt& points_begin, const PointInputIt& points_end, const double& max_width, const double& max_height, const double& padding)
: padding_(padding)
{
if (points_begin == points_end)
{
return;
}
const auto [left_it, right_it] = std::minmax_element(points_begin, points_end, [](auto lhs, auto rhs)
{
return lhs.lng < rhs.lng;
});
min_lon_ = left_it->lng;
const double max_lon = right_it->lng;
const auto [bottom_it, top_it] = std::minmax_element(points_begin, points_end, [](auto lhs, auto rhs)
{
return lhs.lat < rhs.lat;
});
const double min_lat = bottom_it->lat;
max_lat_ = top_it->lat;
std::optional<double> width_zoom;
if (!IsZero(max_lon - min_lon_))
{
width_zoom = (max_width - 2 * padding) / (max_lon - min_lon_);
}
std::optional<double> height_zoom;
if (!IsZero(max_lat_ - min_lat))
{
height_zoom = (max_height - 2 * padding) / (max_lat_ - min_lat);
}
if (width_zoom && height_zoom)
{
zoom_coeff_ = std::min(*width_zoom, *height_zoom);
}
else if (width_zoom)
{
zoom_coeff_ = *width_zoom;
}
else if (height_zoom)
{
zoom_coeff_ = *height_zoom;
}
}
//----------------StopPointRender------------------------
class StopPointRender : svg::Drawable
{
public:
StopPointRender(const svg::Point& stop_coordinate, const RenderSettings& render_settings);
void Draw(svg::ObjectContainer& container) const override;
private:
svg::Point stop_coordinate_;
const RenderSettings& render_settings_;
};
//-----------------TextRender------------------------
class TextRender : svg::Drawable
{
public:
TextRender(const svg::Point& coordinate, const std::string_view& data, const svg::Color& fill, const bool& this_stop, const RenderSettings& render_settings);
void Draw(svg::ObjectContainer&) const override;
private:
svg::Point coordinate_;
std::string data_;
svg::Color fill_;
bool this_stop_;
const RenderSettings& render_settings_;
svg::Text CreateText() const;
svg::Text CreateBeckgraund() const;
};
//----------------RouteRender------------------------
class RouteRender : svg::Drawable
{
public:
RouteRender(const std::vector<svg::Point>& stops_coordinates, const svg::Color& stroke_color, const RenderSettings& render_settings);
void Draw(svg::ObjectContainer&) const override;
private:
std::vector<svg::Point> stops_coordinates_;
svg::Color stroke_color_;
const RenderSettings& render_settings_;
};
//---------------MapRenderer-------------------------
class MapRenderer
{
public:
void SetRenderSettings(const RenderSettings& render_settings);
const RenderSettings& GetRenderSettings() const;
void AddRoutRender(const std::vector<svg::Point>& stops_coordinates, const svg::Color& stroke_color);
void AddStopPointRender(const svg::Point& stop_coordinate);
void AddTextRender(const svg::Point& stop_coordinate, const std::string& data , const svg::Color& text_color, bool this_stop);
svg::Document GetRender() const;
const std::vector<svg::Color>& GetColorPallete() const;
private:
std::vector<RouteRender> routs_renders_;
std::vector<TextRender> routs_names_renders_;
std::vector<StopPointRender> stops_points_renders_;
std::vector<TextRender> stops_names_renders_;
RenderSettings render_settings_;
};
} // namespace renderer
//program.exe < input.json