| 73 | {} |
| 74 | |
| 75 | void RulerHelper::Update(ScreenBase const & screen) |
| 76 | { |
| 77 | m2::PointD pivot = screen.PixelRect().Center(); |
| 78 | long const minPxWidth = std::lround(kMinPixelWidth * df::VisualParams::Instance().GetVisualScale()); |
| 79 | m2::PointD pt1 = screen.PtoG(pivot); |
| 80 | m2::PointD pt0 = screen.PtoG(pivot - m2::PointD(minPxWidth, 0)); |
| 81 | |
| 82 | double const distanceInMeters = mercator::DistanceOnEarth(pt0, pt1); |
| 83 | |
| 84 | // convert metres to units for calculating m_metresDiff. |
| 85 | double metersDiff = CalcMetersDiff(distanceInMeters); |
| 86 | |
| 87 | bool const higherThanMax = metersDiff > kMaxMetersWidth; |
| 88 | ASSERT_GREATER_OR_EQUAL(metersDiff, kMinMetersWidth, ()); |
| 89 | m_pixelLength = static_cast<float>(minPxWidth); |
| 90 | |
| 91 | if (higherThanMax) |
| 92 | m_pixelLength = static_cast<float>(minPxWidth) * 3.0f / 2.0f; |
| 93 | else |
| 94 | { |
| 95 | double const a = ang::AngleTo(pt1, pt0); |
| 96 | pt0 = mercator::GetSmPoint(pt1, cos(a) * metersDiff, sin(a) * metersDiff); |
| 97 | |
| 98 | m_pixelLength = std::round(pivot.Length(screen.GtoP(pt0))); |
| 99 | } |
| 100 | |
| 101 | int drawScale = df::GetDrawTileScale(screen); |
| 102 | if (m_currentDrawScale < kVisibleRulerBottomScale && drawScale >= kVisibleRulerBottomScale) |
| 103 | SetTextDirty(); |
| 104 | |
| 105 | m_currentDrawScale = drawScale; |
| 106 | } |
| 107 | |
| 108 | // static |
| 109 | bool RulerHelper::IsVisible(ScreenBase const & screen) |
nothing calls this directly
no test coverage detected