Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Formatting gone wrong, again.
Browse files Browse the repository at this point in the history
Signed-off-by: Tymofii Baga <3448+fester@users.noreply.github.com>
  • Loading branch information
fester committed Feb 12, 2019
1 parent 1d965aa commit c9a11ec
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/RasterOverviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,34 @@ RasterOverviews::RasterOverviews(UniqueRasterPointer input_raster, int min_zoom,
// Guesses (numerically) maximal zoom level from a raster resolution
int RasterOverviews::guess_max_zoom_level(double resolution)
{
// pixel_size_z0 is a magic number that is number of meters per pixel on zoom level 0, given tile size is 256 pixels.
// This number is approximate and does not account for latitude, i.e. uses pixel size on equator.
// The formula is: earth circumference * 2 * pi / 256
// "Real" number can be off up to 30% depending on the latitude. More details here: https://msdn.microsoft.com/en-us/library/aa940990.aspx
const double pixel_size_z0 = 156543.04;
// pixel_size_z0 is a magic number that is number of meters per pixel on zoom level 0, given tile size is 256 pixels.
// This number is approximate and does not account for latitude, i.e. uses pixel size on equator.
// The formula is: earth circumference * 2 * pi / 256
// "Real" number can be off up to 30% depending on the latitude. More details here: https://msdn.microsoft.com/en-us/library/aa940990.aspx
const double pixel_size_z0 = 156543.04;
return static_cast<int>(round(log2(pixel_size_z0 / resolution)));
}

// Guesses (numerically) minimal zoom level from a raster resolution and it's size
int RasterOverviews::guess_min_zoom_level(int max_zoom_level)
{
// This constant is an arbitrary number representing some minimal size to which the raster can be downsized when 'zooming out' a map.
// Math is simple:
// 2**max_zoom = raster_size; 2**min_zoom = 128
// Solve it in regards to min_zoom and there you have it.
const int MINIMAL_RASTER_SIZE = 128;
// This constant is an arbitrary number representing some minimal size to which the raster can be downsized when 'zooming out' a map.
// Math is simple:
// 2**max_zoom = raster_size; 2**min_zoom = 128
// Solve it in regards to min_zoom and there you have it.
const int MINIMAL_RASTER_SIZE = 128;
const double quotient = MINIMAL_RASTER_SIZE * (1 << max_zoom_level);

int raster_width = m_base_raster->get_width();
int raster_height = m_base_raster->get_height();

TNTN_LOG_DEBUG("guess_min_zoom_level: raster_width: {}, raster_height: {}",
raster_width,
raster_height);
TNTN_LOG_DEBUG(
"guess_min_zoom_level: raster_width: {}, raster_height: {}", raster_width, raster_height);

int zoom_x = static_cast<int>(floor(log2(quotient / raster_width)));
int zoom_y = static_cast<int>(floor(log2(quotient / raster_height)));

// Cap the resulting value so it won't go below 0 and we wouldn't end up with negative zoom levels
// Cap the resulting value so it won't go below 0 and we wouldn't end up with negative zoom levels
return std::max(0, std::min(zoom_x, zoom_y));
}

Expand All @@ -71,7 +70,10 @@ void RasterOverviews::compute_zoom_levels()
std::swap(m_min_zoom, m_max_zoom);
}

TNTN_LOG_INFO("After checking with data, tiles will be generated in a range between {} and {}", m_min_zoom, m_max_zoom);
TNTN_LOG_INFO(
"After checking with data, tiles will be generated in a range between {} and {}",
m_min_zoom,
m_max_zoom);
}

bool RasterOverviews::next(RasterOverview& overview)
Expand All @@ -94,11 +96,12 @@ bool RasterOverviews::next(RasterOverview& overview)
overview.resolution = output_raster->get_cell_size();
overview.raster = std::move(output_raster);

TNTN_LOG_DEBUG("Generated next overview at zoom {}, window size {}, min zoom level {}, max zoom level {}",
m_current_zoom + 1,
window_size,
m_min_zoom,
m_max_zoom);
TNTN_LOG_DEBUG(
"Generated next overview at zoom {}, window size {}, min zoom level {}, max zoom level {}",
m_current_zoom + 1,
window_size,
m_min_zoom,
m_max_zoom);

return true;
}
Expand Down

0 comments on commit c9a11ec

Please sign in to comment.