MCPcopy Create free account
hub / github.com/comaps/comaps / Update

Method Update

libs/drape_frontend/gui/ruler_helper.cpp:75–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73{}
74
75void 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
109bool RulerHelper::IsVisible(ScreenBase const & screen)

Callers

nothing calls this directly

Calls 9

AngleToFunction · 0.85
GetSmPointFunction · 0.85
GetDrawTileScaleFunction · 0.85
GetVisualScaleMethod · 0.80
DistanceOnEarthFunction · 0.50
CenterMethod · 0.45
PtoGMethod · 0.45
LengthMethod · 0.45
GtoPMethod · 0.45

Tested by

no test coverage detected