MCPcopy Create free account
hub / github.com/comaps/comaps / GenerateYAxisChartData

Function GenerateYAxisChartData

libs/map/chart_generator.cpp:160–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160bool GenerateYAxisChartData(uint32_t height, double minMetersPerPxl, vector<double> const & altitudeDataM,
161 vector<double> & yAxisDataPxl)
162{
163 if (altitudeDataM.empty())
164 {
165 yAxisDataPxl.clear();
166 return true;
167 }
168
169 uint32_t constexpr kHeightIndentPxl = 2;
170 uint32_t heightIndentPxl = kHeightIndentPxl;
171 if (height <= 2 * kHeightIndentPxl)
172 {
173 LOG(LERROR, ("Chart height is less or equal than 2 * kHeightIndentPxl (", 2 * kHeightIndentPxl, ")"));
174 heightIndentPxl = 0;
175 }
176
177 auto const minMaxAltitudeIt = minmax_element(altitudeDataM.begin(), altitudeDataM.end());
178 double const minAltM = *minMaxAltitudeIt.first;
179 double const maxAltM = *minMaxAltitudeIt.second;
180 double const deltaAltM = maxAltM - minAltM;
181 uint32_t const drawHeightPxl = height - 2 * heightIndentPxl;
182 double const metersPerPxl = max(minMetersPerPxl, deltaAltM / static_cast<double>(drawHeightPxl));
183 if (metersPerPxl == 0.0)
184 {
185 LOG(LERROR, ("metersPerPxl == 0.0"));
186 return false;
187 }
188 // int avoids double errors which make freeHeightSpacePxl slightly less than zero.
189 int const deltaAltPxl = deltaAltM / metersPerPxl;
190 double const freeHeightSpacePxl = drawHeightPxl - deltaAltPxl;
191 if (freeHeightSpacePxl < 0 || freeHeightSpacePxl > drawHeightPxl)
192 {
193 LOG(LERROR, ("Number of pixels free of chart points (", freeHeightSpacePxl,
194 ") is below zero or greater than the number of pixels for the chart (", drawHeightPxl, ")."));
195 return false;
196 }
197
198 double const maxAltPxl = maxAltM / metersPerPxl;
199 yAxisDataPxl.assign(altitudeDataM.cbegin(), altitudeDataM.cend());
200 ScaleChartData(yAxisDataPxl, 1.0 / metersPerPxl);
201 ReflectChartData(yAxisDataPxl);
202 ShiftChartData(yAxisDataPxl, maxAltPxl + heightIndentPxl + freeHeightSpacePxl / 2.0);
203
204 return true;
205}
206
207bool GenerateChartByPoints(uint32_t width, uint32_t height, vector<m2::PointD> const & geometry, MapStyle mapStyle,
208 vector<uint8_t> & frameBuffer)

Callers 2

GenerateChartFunction · 0.85
UNIT_TESTFunction · 0.85

Calls 10

ScaleChartDataFunction · 0.85
ReflectChartDataFunction · 0.85
ShiftChartDataFunction · 0.85
emptyMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
assignMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.68