[drape] Minor fixes to avoid static double constants.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako 2022-06-17 10:02:17 +03:00
parent 6eea852012
commit 6fd7b180b2
7 changed files with 29 additions and 26 deletions

View file

@ -778,7 +778,7 @@ ApplyLineFeatureGeometry::ApplyLineFeatureGeometry(TileKey const & tileKey,
size_t pointsCount, bool smooth)
: TBase(tileKey, insertShape, id, minVisibleScale, rank, CaptionDescription())
, m_currentScaleGtoP(static_cast<float>(currentScaleGtoP))
, m_sqrScale(currentScaleGtoP * currentScaleGtoP)
, m_minSegmentSqrLength(base::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale() / currentScaleGtoP))
, m_simplify(tileKey.m_zoomLevel >= kLineSimplifyLevelStart &&
tileKey.m_zoomLevel <= kLineSimplifyLevelEnd)
, m_smooth(smooth)
@ -804,9 +804,8 @@ void ApplyLineFeatureGeometry::operator() (m2::PointD const & point)
}
else
{
static double minSegmentLength = base::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale());
if (m_simplify &&
((m_spline->GetSize() > 1 && point.SquaredLength(m_lastAddedPoint) * m_sqrScale < minSegmentLength) ||
((m_spline->GetSize() > 1 && point.SquaredLength(m_lastAddedPoint) < m_minSegmentSqrLength) ||
m_spline->IsPrelonging(point)))
{
m_spline->ReplacePoint(point);

View file

@ -173,7 +173,7 @@ private:
m2::SharedSpline m_spline;
std::vector<m2::SharedSpline> m_clippedSplines;
float m_currentScaleGtoP;
double m_sqrScale;
double m_minSegmentSqrLength;
m2::PointD m_lastAddedPoint;
bool m_simplify;
bool m_smooth;

View file

@ -324,7 +324,7 @@ void RuleDrawer::ProcessLineStyle(FeatureType & f, Stylist const & s,
TInsertShapeFn const & insertShape, int & minVisibleScale)
{
int const zoomLevel = m_context->GetTileKey().m_zoomLevel;
auto const smooth = ftypes::IsIsolineChecker::Instance()(f);
bool const smooth = ftypes::IsIsolineChecker::Instance()(f);
ApplyLineFeatureGeometry applyGeom(m_context->GetTileKey(), insertShape, f.GetID(),
m_currentScaleGtoP, minVisibleScale, f.GetRank(),

View file

@ -294,7 +294,10 @@ bool InitStylist(FeatureType & f, int8_t deviceLang, int const zoomLevel, bool b
}
}
else
{
// GetSuitable function appends 'keys' vector, so move start index accordingly.
idx = keys.size();
}
}
feature::FilterRulesByRuntimeSelector(f, zoomLevel, keys);

View file

@ -141,7 +141,9 @@ UserEventStream::UserEventStream()
, m_animationSystem(AnimationSystem::Instance())
, m_startDragOrg(m2::PointD::Zero())
, m_startDoubleTapAndHold(m2::PointD::Zero())
{}
, m_dragThreshold(base::Pow2(VisualParams::Instance().GetDragThreshold()))
{
}
void UserEventStream::AddEvent(drape_ptr<UserEvent> && event)
{
@ -812,8 +814,7 @@ bool UserEventStream::CheckDrag(array<Touch, 2> const & touches, double threshol
bool UserEventStream::TouchMove(array<Touch, 2> const & touches)
{
double const kDragThreshold = base::Pow2(VisualParams::Instance().GetDragThreshold());
size_t touchCount = GetValidTouchesCount(touches);
size_t const touchCount = GetValidTouchesCount(touches);
bool isMapTouch = true;
switch (m_state)
@ -821,7 +822,7 @@ bool UserEventStream::TouchMove(array<Touch, 2> const & touches)
case STATE_EMPTY:
if (touchCount == 1)
{
if (CheckDrag(touches, kDragThreshold))
if (CheckDrag(touches, m_dragThreshold))
BeginDrag(touches[0]);
else
isMapTouch = false;
@ -834,10 +835,12 @@ bool UserEventStream::TouchMove(array<Touch, 2> const & touches)
case STATE_TAP_TWO_FINGERS:
if (touchCount == 2)
{
auto const threshold = static_cast<float>(kDragThreshold);
float const threshold = static_cast<float>(m_dragThreshold);
if (m_twoFingersTouches[0].SquaredLength(touches[0].m_location) > threshold ||
m_twoFingersTouches[1].SquaredLength(touches[1].m_location) > threshold)
{
BeginScale(touches[0], touches[1]);
}
else
isMapTouch = false;
}
@ -848,13 +851,13 @@ bool UserEventStream::TouchMove(array<Touch, 2> const & touches)
break;
case STATE_TAP_DETECTION:
case STATE_WAIT_DOUBLE_TAP:
if (CheckDrag(touches, kDragThreshold))
if (CheckDrag(touches, m_dragThreshold))
CancelTapDetector();
else
isMapTouch = false;
break;
case STATE_WAIT_DOUBLE_TAP_HOLD:
if (CheckDrag(touches, kDragThreshold))
if (CheckDrag(touches, m_dragThreshold))
StartDoubleTapAndHold(touches[0]);
break;
case STATE_DOUBLE_TAP_HOLD:

View file

@ -408,6 +408,7 @@ public:
};
UserEventStream();
void AddEvent(drape_ptr<UserEvent> && event);
ScreenBase const & ProcessEvents(bool & modelViewChanged, bool & viewportChanged);
ScreenBase const & GetCurrentScreen() const;
@ -497,7 +498,7 @@ private:
bool DetectForceTap(Touch const & touch);
void EndTapDetector(Touch const & touch);
void CancelTapDetector();
void StartDoubleTapAndHold(Touch const & touch);
void UpdateDoubleTapAndHold(Touch const & touch);
void EndDoubleTapAndHold(Touch const & touch);
@ -556,6 +557,8 @@ private:
std::array<m2::PointF, 2> m_twoFingersTouches;
m2::PointD m_startDoubleTapAndHold;
double const m_dragThreshold;
KineticScroller m_scroller;
base::Timer m_kineticTimer;
bool m_kineticScrollEnabled = true;

View file

@ -327,17 +327,15 @@ void GenerateTextShapes(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::Textur
}
}
m2::SharedSpline SimplifySpline(UserLineRenderParams const & renderInfo, double sqrScale)
m2::SharedSpline SimplifySpline(UserLineRenderParams const & renderInfo, double minSqrLength)
{
auto const vs = static_cast<float>(df::VisualParams::Instance().GetVisualScale());
m2::SharedSpline spline;
spline.Reset(new m2::Spline(renderInfo.m_spline->GetSize()));
static double const kMinSegmentLength = base::Pow2(4.0 * vs);
m2::PointD lastAddedPoint;
for (auto const & point : renderInfo.m_spline->GetPath())
{
if (spline->GetSize() > 1 && point.SquaredLength(lastAddedPoint) * sqrScale < kMinSegmentLength)
if (spline->GetSize() > 1 && point.SquaredLength(lastAddedPoint) < minSqrLength)
{
spline->ReplacePoint(point);
}
@ -568,15 +566,13 @@ void CacheUserLines(ref_ptr<dp::GraphicsContext> context, TileKey const & tileKe
CHECK_GREATER(tileKey.m_zoomLevel, 0, ());
CHECK_LESS(tileKey.m_zoomLevel - 1, static_cast<int>(kLineWidthZoomFactor.size()), ());
auto const vs = static_cast<float>(df::VisualParams::Instance().GetVisualScale());
double const vs = df::VisualParams::Instance().GetVisualScale();
bool const simplify = tileKey.m_zoomLevel <= kLineSimplifyLevelEnd;
double sqrScale = 1.0;
// This var is used only if simplify == true.
double minSegmentSqrLength = 1.0;
if (simplify)
{
double const currentScaleGtoP = 1.0 / GetScreenScale(tileKey.m_zoomLevel);
sqrScale = currentScaleGtoP * currentScaleGtoP;
}
minSegmentSqrLength = base::Pow2(4.0 * vs * GetScreenScale(tileKey.m_zoomLevel));
for (auto id : linesId)
{
@ -604,7 +600,7 @@ void CacheUserLines(ref_ptr<dp::GraphicsContext> context, TileKey const & tileKe
m2::SharedSpline spline = renderInfo.m_spline;
if (simplify)
spline = SimplifySpline(renderInfo, sqrScale);
spline = SimplifySpline(renderInfo, minSegmentSqrLength);
if (spline->GetSize() < 2)
continue;
@ -623,8 +619,7 @@ void CacheUserLines(ref_ptr<dp::GraphicsContext> context, TileKey const & tileKe
params.m_depthTestEnabled = true;
params.m_depth = layer.m_depth;
params.m_depthLayer = renderInfo.m_depthLayer;
params.m_width = static_cast<float>(layer.m_width * vs *
kLineWidthZoomFactor[tileKey.m_zoomLevel - 1]);
params.m_width = static_cast<float>(layer.m_width * vs * kLineWidthZoomFactor[tileKey.m_zoomLevel - 1]);
params.m_minVisibleScale = 1;
params.m_rank = 0;