From 9c47eb040313b9183c5382f448e666f6d1f99e79 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 24 Jul 2012 12:55:39 -0700 Subject: [PATCH] Minor changes (replace pow(2, X) with 1 << X). --- map/basic_tiling_render_policy.cpp | 30 +++++++++++++----------------- yg/render_state.cpp | 4 ++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/map/basic_tiling_render_policy.cpp b/map/basic_tiling_render_policy.cpp index ae8bc4e9f5..ecf5707afd 100644 --- a/map/basic_tiling_render_policy.cpp +++ b/map/basic_tiling_render_policy.cpp @@ -11,31 +11,27 @@ size_t BasicTilingRenderPolicy::CalculateTileSize(size_t screenWidth, size_t screenHeight) { - /// getting maximum screenSize - size_t maxScreenSize = max(screenWidth, screenHeight); + int const maxSz = max(screenWidth, screenHeight); - /// we're calculating the tileSize based on - /// (maxScreenSize > 1024 ? rounded : ceiled) to the nearest power of two value - /// of the maxScreenSize + // we're calculating the tileSize based on (maxSz > 1024 ? rounded : ceiled) + // to the nearest power of two value of the maxSz - double const log2 = log(2.0); + int const ceiledSz = 1 << static_cast(ceil(log(double(maxSz + 1)) / log(2.0))); + int res = 0; - size_t ceiledScreenSize = static_cast(pow(2.0, ceil(log(double(maxScreenSize + 1)) / log2))); - size_t flooredScreenSize = ceiledScreenSize / 2; - size_t resScreenSize = 0; - - if (maxScreenSize < 1024) - resScreenSize = ceiledScreenSize; + if (maxSz < 1024) + res = ceiledSz; else { - /// rounding to the nearest power of two. - if (ceiledScreenSize - maxScreenSize < maxScreenSize - flooredScreenSize) - resScreenSize = ceiledScreenSize; + int const flooredSz = ceiledSz / 2; + // rounding to the nearest power of two. + if (ceiledSz - maxSz < maxSz - flooredSz) + res = ceiledSz; else - resScreenSize = flooredScreenSize; + res = flooredSz; } - return min(max(resScreenSize / 2, (size_t)128), (size_t)1024); + return min(max(res / 2, 128), 1024); } BasicTilingRenderPolicy::BasicTilingRenderPolicy(Params const & p, diff --git a/yg/render_state.cpp b/yg/render_state.cpp index 49ad5f9a6e..4799ab2f29 100644 --- a/yg/render_state.cpp +++ b/yg/render_state.cpp @@ -51,6 +51,7 @@ namespace yg m_surfaceWidth = w; m_surfaceHeight = h; + /* double const log2 = log(2.0); m_textureWidth = static_cast(pow(2, ceil(log(double(w)) / log2))); @@ -58,6 +59,9 @@ namespace yg m_textureWidth = max(m_textureWidth, m_textureHeight); m_textureHeight = max(m_textureWidth, m_textureHeight); + */ + m_textureWidth = m_textureHeight = + 1 << static_cast(ceil(log(double(max(w, h))) / log(2.0))); } }