From 8efe95e2f4f80879499021d7f1739fc414955064 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 18 Apr 2012 20:21:13 +0300 Subject: [PATCH] Some code review. --- map/framework.cpp | 2 +- map/location_state.cpp | 35 +++++++++++++++++------------------ map/location_state.hpp | 5 +++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index a9b041a9e8..37899c715f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -614,7 +614,7 @@ void Framework::DrawAdditionalInfo(shared_ptr const & e) m_informationDisplay.doDraw(pDrawer); - m_locationState.DrawMyPosition(*pDrawer, m_navigator.Screen()); + m_locationState.DrawMyPosition(*pDrawer, m_navigator); if (m_drawPlacemark) m_informationDisplay.drawPlacemark(pDrawer, "placemark", m_navigator.GtoP(m_placemark)); diff --git a/map/location_state.cpp b/map/location_state.cpp index 31238d0bd3..bffa15415c 100644 --- a/map/location_state.cpp +++ b/map/location_state.cpp @@ -1,11 +1,13 @@ #include "location_state.hpp" #include "drawer_yg.hpp" +#include "navigator.hpp" #include "../platform/location.hpp" #include "../platform/platform.hpp" #include "../indexer/mercator.hpp" + namespace location { @@ -27,39 +29,35 @@ namespace location { m_flags |= ECompass; - m_headingRad = ((info.m_trueHeading >= 0.0) ? info.m_trueHeading : info.m_magneticHeading) - / 180 * math::pi - - math::pi / 2; // 0 angle is for North ("up"), but in our coordinates it's to the right. + m_headingRad = ((info.m_trueHeading >= 0.0) ? info.m_trueHeading : info.m_magneticHeading); + // 0 angle is for North ("up"), but in our coordinates it's to the right. + m_headingRad = my::DegToRad(m_headingRad) - math::pi / 2.0; + // Avoid situations when offset between magnetic north and true north is too small - static double const MIN_SECTOR_DEG = 10.; - m_headingHalfSectorRad = (info.m_accuracy < MIN_SECTOR_DEG ? MIN_SECTOR_DEG : info.m_accuracy) - / 180 * math::pi; + static double const MIN_SECTOR_DEG = 10.0; + m_headingHalfSectorRad = (info.m_accuracy < MIN_SECTOR_DEG ? MIN_SECTOR_DEG : info.m_accuracy); + m_headingHalfSectorRad = my::DegToRad(m_headingHalfSectorRad); } - void State::DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen) + void State::DrawMyPosition(DrawerYG & drawer, Navigator const & nav) { - double pxErrorRadius; - m2::PointD pxPosition; - m2::PointD pxShift(screen.PixelRect().minX(), screen.PixelRect().minY()); - if ((m_flags & State::EGps) || (m_flags & State::ECompass)) { - pxPosition = screen.GtoP(Position()); - pxErrorRadius = pxPosition.Length(screen.GtoP(Position() + m2::PointD(m_errorRadiusMercator, 0.0))); - - pxPosition -= pxShift; + m2::PointD const pxPosition = nav.GtoP(Position()); + double const pxErrorRadius = pxPosition.Length(nav.GtoP(Position() + m2::PointD(m_errorRadiusMercator, 0.0))); if (m_flags & State::EGps) { // my position symbol drawer.drawSymbol(pxPosition, "current-position", yg::EPosCenter, yg::maxDepth); + // my position circle - drawer.screen()->fillSector(pxPosition, 0, math::pi * 2, pxErrorRadius, + drawer.screen()->fillSector(pxPosition, 0, 2.0 * math::pi, pxErrorRadius, yg::Color(0, 0, 255, 32), yg::maxDepth - 3); - // display compass only if position is available - double orientationRadius = max(pxErrorRadius, 30 * GetPlatform().VisualScale()); + // display compass only if position is available + double orientationRadius = max(pxErrorRadius, 30.0 * GetPlatform().VisualScale()); if (m_flags & State::ECompass) { @@ -69,6 +67,7 @@ namespace location orientationRadius, yg::Color(255, 255, 255, 192), yg::maxDepth); + drawer.screen()->fillSector(pxPosition, m_headingRad - m_headingHalfSectorRad, m_headingRad + m_headingHalfSectorRad, diff --git a/map/location_state.hpp b/map/location_state.hpp index 37fb5fb9b2..fe592113db 100644 --- a/map/location_state.hpp +++ b/map/location_state.hpp @@ -1,9 +1,10 @@ #pragma once #include "../geometry/point2d.hpp" -#include "../geometry/screenbase.hpp" +#include "../geometry/rect2d.hpp" class DrawerYG; +class Navigator; namespace location { @@ -41,7 +42,7 @@ namespace location void UpdateGps(m2::RectD const & rect); void UpdateCompass(CompassInfo const & info); - void DrawMyPosition(DrawerYG & drawer, ScreenBase const & screen); + void DrawMyPosition(DrawerYG & drawer, Navigator const & nav); operator int() const {