diff --git a/topography_generator/generator.cpp b/topography_generator/generator.cpp index 87733f0af7..b82be52c18 100644 --- a/topography_generator/generator.cpp +++ b/topography_generator/generator.cpp @@ -67,6 +67,9 @@ private: Altitude GetMedianValue(ms::LatLon const & pos) { + if (!m_srtmManager.GetTile(pos).IsValid()) + return kInvalidAltitude; + // Look around the position with invalid altitude // and return median of surrounding valid altitudes. double const step = kTileSizeInDegree / kArcSecondsInDegree; @@ -151,7 +154,12 @@ public: { auto movedPos = pos; if (m_moveFromBorderFn(movedPos)) - return m_originalProvider.GetValue(movedPos); + { + // Check that we have original neighboring tile, use filtered if haven't. + auto const alt = m_originalProvider.GetValue(movedPos); + if (alt != kInvalidAltitude) + return alt; + } return m_filteredProvider.GetValue(pos); } diff --git a/topography_generator/marching_squares/marching_squares.hpp b/topography_generator/marching_squares/marching_squares.hpp index 2be6114bf4..dfe9d582f2 100644 --- a/topography_generator/marching_squares/marching_squares.hpp +++ b/topography_generator/marching_squares/marching_squares.hpp @@ -50,8 +50,13 @@ public: contoursBuilder.BeginLine(); for (size_t j = 0; j < m_stepsCountLon; ++j) { - auto const pos = ms::LatLon(m_leftBottom.m_lat + m_step * i, m_leftBottom.m_lon + m_step * j); - Square square(pos, m_step, result.m_minValue, m_valueStep, m_valuesProvider); + auto const leftBottom = ms::LatLon(m_leftBottom.m_lat + m_step * i, + m_leftBottom.m_lon + m_step * j); + // Use std::min to prevent floating-point number precision error. + auto const rightTop = ms::LatLon(std::min(leftBottom.m_lat + m_step, m_rightTop.m_lat), + std::min(leftBottom.m_lon + m_step, m_rightTop.m_lon)); + + Square square(leftBottom, rightTop, result.m_minValue, m_valueStep, m_valuesProvider); square.SetDebugId(m_debugId); square.GenerateSegments(contoursBuilder); } diff --git a/topography_generator/marching_squares/square.hpp b/topography_generator/marching_squares/square.hpp index 27ee94bd9b..e3d344f526 100644 --- a/topography_generator/marching_squares/square.hpp +++ b/topography_generator/marching_squares/square.hpp @@ -9,15 +9,16 @@ template class Square { public: - Square(ms::LatLon const & leftBottom, double size, + Square(ms::LatLon const & leftBottom, + ms::LatLon const & rightTop, ValueType minValue, ValueType valueStep, ValuesProvider & valuesProvider) : m_minValue(minValue) , m_valueStep(valueStep) , m_left(leftBottom.m_lon) - , m_right(leftBottom.m_lon + size) + , m_right(rightTop.m_lon) , m_bottom(leftBottom.m_lat) - , m_top(leftBottom.m_lat + size) + , m_top(rightTop.m_lat) { static_assert(std::is_integral::value, "Only integral types are supported.");