Fixed calculation of scale and zoom level.

This commit is contained in:
Daria Volvenkova 2018-07-09 18:31:51 +03:00 committed by Vlad Mihaylenko
parent 62a2f1edf7
commit 19cc3b7ac4
8 changed files with 28 additions and 33 deletions

View file

@ -58,7 +58,7 @@ std::string LocationModeStatisticsName(location::EMyPositionMode mode)
int GetZoomLevel(ScreenBase const & screen)
{
return static_cast<int>(df::GetZoomLevel(screen.GetScale()));
return static_cast<int>(df::GetTileBasedZoomLevel(screen.GetScale()));
}
int GetZoomLevel(ScreenBase const & screen, m2::PointD const & position, double errorRadius)
@ -139,7 +139,7 @@ MyPositionController::MyPositionController(Params && params)
, m_oldDrawDirection(0.0)
, m_enablePerspectiveInRouting(false)
, m_enableAutoZoomInRouting(params.m_isAutozoomEnabled)
, m_autoScale2d(GetScale(kDefaultAutoZoom))
, m_autoScale2d(GetTileBasedScale(kDefaultAutoZoom))
, m_autoScale3d(m_autoScale2d)
, m_lastGPSBearing(false)
, m_lastLocationTimestamp(0.0)
@ -360,7 +360,7 @@ void MyPositionController::NextMode(ScreenBase const & screen)
if (m_mode == location::FollowAndRotate)
{
if (m_isInRouting && screen.isPerspective())
preferredZoomLevel = static_cast<int>(GetZoomLevel(ScreenBase::GetStartPerspectiveScale() * 1.1));
preferredZoomLevel = static_cast<int>(GetTileBasedZoomLevel(ScreenBase::GetStartPerspectiveScale() * 1.1));
ChangeMode(location::Follow);
ChangeModelView(m_position, 0.0, m_visiblePixelRect.Center(), preferredZoomLevel);
}

View file

@ -392,7 +392,7 @@ bool UserEventStream::OnSetCenter(ref_ptr<SetCenterEvent> centerEvent)
}
else
{
screen.SetFromParams(center, screen.GetAngle(), GetScale(zoom));
screen.SetFromParams(center, screen.GetAngle(), GetTileBasedScale(zoom));
screen.MatchGandP3d(center, m_visibleViewport.Center());
}
@ -554,7 +554,7 @@ bool UserEventStream::SetFollowAndRotate(m2::PointD const & userPos, m2::PointD
}
else
{
screen.SetFromParams(userPos, -azimuth, isAutoScale ? autoScale : GetScale(preferredZoomLevel));
screen.SetFromParams(userPos, -azimuth, isAutoScale ? autoScale : GetTileBasedScale(preferredZoomLevel));
}
screen.MatchGandP3d(userPos, pixelPos);

View file

@ -461,7 +461,7 @@ void CacheUserLines(TileKey const & tileKey, ref_ptr<dp::TextureManager> texture
double sqrScale = 1.0;
if (simplify)
{
double const currentScaleGtoP = 1.0 / GetScale(tileKey.m_zoomLevel);
double const currentScaleGtoP = 1.0 / GetTileBasedScale(tileKey.m_zoomLevel);
sqrScale = currentScaleGtoP * currentScaleGtoP;
}

View file

@ -170,8 +170,7 @@ int GetTileScaleBase(ScreenBase const & s, uint32_t tileSize)
ScreenBase tmpS = s;
tmpS.Rotate(-tmpS.GetAngle());
// slightly smaller than original to produce "antialiasing" effect using bilinear filtration.
int const halfSize = static_cast<int>(tileSize / 1.05 / 2.0);
auto const halfSize = tileSize / 2;
m2::RectD glbRect;
m2::PointD const pxCenter = tmpS.PixelRect().Center();
@ -233,15 +232,6 @@ m2::RectD GetRectForDrawScale(double drawScale, m2::PointD const & center)
return GetRectForDrawScale(my::rounds(drawScale), center);
}
double GetTileBasedScale(double zoomLevel)
{
VisualParams const & p = VisualParams::Instance();
auto const factor = pow(2.0, zoomLevel);
auto const len = (MercatorBounds::maxX - MercatorBounds::minX) / factor;
auto const pxLen = static_cast<double>(p.GetTileSize());
return len / pxLen;
}
uint32_t CalculateTileSize(uint32_t screenWidth, uint32_t screenHeight)
{
uint32_t const maxSz = max(screenWidth, screenHeight);
@ -306,15 +296,9 @@ int GetDrawTileScale(m2::RectD const & r)
return GetDrawTileScale(r, p.GetTileSize(), p.GetVisualScale());
}
double GetZoomLevel(double scale)
{
static double const kLog2 = log(2.0);
return my::clamp(fabs(log(scale) / kLog2), 1.0, scales::GetUpperStyleScale() + 1.0);
}
void ExtractZoomFactors(ScreenBase const & s, double & zoom, int & index, float & lerpCoef)
{
double const zoomLevel = GetZoomLevel(s.GetScale());
double const zoomLevel = GetTileBasedZoomLevel(s.GetScale());
zoom = trunc(zoomLevel);
index = static_cast<int>(zoom - 1.0);
lerpCoef = static_cast<float>(zoomLevel - zoom);
@ -341,12 +325,25 @@ m2::PointF InterpolateByZoomLevels(int index, float lerpCoef, std::vector<m2::Po
double GetNormalizedZoomLevel(double scale, int minZoom)
{
double const kMaxZoom = scales::GetUpperStyleScale() + 1.0;
return my::clamp((GetZoomLevel(scale) - minZoom) / (kMaxZoom - minZoom), 0.0, 1.0);
return my::clamp((GetTileBasedZoomLevel(scale) - minZoom) / (kMaxZoom - minZoom), 0.0, 1.0);
}
double GetScale(double zoomLevel)
double GetTileBasedScale(double zoomLevel)
{
return pow(2.0, -zoomLevel);
VisualParams const & p = VisualParams::Instance();
auto const factor = pow(2.0, zoomLevel);
auto const len = (MercatorBounds::maxX - MercatorBounds::minX) / factor;
auto const pxLen = static_cast<double>(p.GetTileSize());
return len / pxLen;
}
double GetTileBasedZoomLevel(double scale)
{
VisualParams const & p = VisualParams::Instance();
auto const pxLen = static_cast<double>(p.GetTileSize());
auto const len = pxLen * scale;
auto const factor = (MercatorBounds::maxX - MercatorBounds::minX) / len;
static double const kLog2 = log(2.0);
return my::clamp(fabs(log(factor) / kLog2), 1.0, scales::GetUpperStyleScale() + 1.0);
}
} // namespace df

View file

@ -86,12 +86,10 @@ m2::RectD GetRectForDrawScale(double drawScale, m2::PointD const & center);
uint32_t CalculateTileSize(uint32_t screenWidth, uint32_t screenHeight);
double GetZoomLevel(double scale);
void ExtractZoomFactors(ScreenBase const & s, double & zoom, int & index, float & lerpCoef);
float InterpolateByZoomLevels(int index, float lerpCoef, std::vector<float> const & values);
m2::PointF InterpolateByZoomLevels(int index, float lerpCoef, std::vector<m2::PointF> const & values);
double GetNormalizedZoomLevel(double scale, int minZoom = 1);
double GetScale(double zoomLevel);
double GetTileBasedScale(double zoomLevel);
double GetTileBasedZoomLevel(double scale);
} // namespace df

View file

@ -574,7 +574,7 @@ Bookmark * BookmarkManager::CreateBookmark(kml::BookmarkData && bm, kml::MarkGro
alohalytics::Stats::Instance().LogEvent("Bookmarks_Bookmark_action", details);
bm.m_timestamp = std::chrono::system_clock::now();
bm.m_viewportScale = static_cast<uint8_t>(df::GetZoomLevel(m_viewport.GetScale()));
bm.m_viewportScale = static_cast<uint8_t>(df::GetTileBasedZoomLevel(m_viewport.GetScale()));
auto * bookmark = CreateBookmark(std::move(bm));
bookmark->Attach(groupId);

View file

@ -316,7 +316,7 @@ void LocalAdsManager::UpdateViewport(ScreenBase const & screen)
{
auto const connectionStatus = GetPlatform().ConnectionStatus();
if (kServerUrl.empty() || connectionStatus == Platform::EConnectionType::CONNECTION_NONE ||
df::GetZoomLevel(screen.GetScale()) < kRequestMinZoomLevel)
df::GetTileBasedZoomLevel(screen.GetScale()) < kRequestMinZoomLevel)
{
return;
}

View file

@ -222,7 +222,7 @@ void TrafficManager::UpdateViewport(ScreenBase const & screen)
if (!IsEnabled() || IsInvalidState() || m_isPaused)
return;
if (df::GetZoomLevel(screen.GetScale()) < df::kRoadClass0ZoomLevel)
if (df::GetTileBasedZoomLevel(screen.GetScale()) < df::kRoadClass0ZoomLevel)
return;
// Request traffic.