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

Function RoundCorner

libs/drape_frontend/path_text_handle.cpp:28–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26int constexpr kMaxStepsCount = 7;
27
28bool RoundCorner(m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3, int leftStepsCount,
29 std::vector<m2::PointD> & roundedCorner)
30{
31 roundedCorner.clear();
32
33 double p1p2Length = (p2 - p1).Length();
34 double const p2p3Length = (p3 - p2).Length();
35
36 auto const dir1 = (p2 - p1) / p1p2Length;
37 auto const dir2 = (p3 - p2) / p2p3Length;
38
39 if (IsValidSplineTurn(dir1, dir2))
40 return false;
41
42 double const vs = df::VisualParams::Instance().GetVisualScale();
43 double constexpr kMinCornerDist = 1.0;
44 if ((p3 - p1).SquaredLength() < kMinCornerDist * vs)
45 {
46 roundedCorner.push_back(p1);
47 return false;
48 }
49 m2::PointD const np1 =
50 p2 - dir1 * std::min(kRoundStep * vs, p1p2Length - p1p2Length / std::max(leftStepsCount - 1, 2));
51 p1p2Length = (p2 - np1).Length();
52 double const cosCorner = m2::DotProduct(-dir1, dir2);
53 double const sinCorner = fabs(m2::CrossProduct(-dir1, dir2));
54
55 double const p2p3IntersectionLength = (p1p2Length * kSinTurn) / (kSinTurn * cosCorner + kCosTurn * sinCorner);
56
57 if (p2p3IntersectionLength >= p2p3Length)
58 {
59 roundedCorner.push_back(np1);
60 return false;
61 }
62 else
63 {
64 m2::PointD const p = p2 + dir2 * p2p3IntersectionLength;
65 roundedCorner.push_back(np1);
66 roundedCorner.push_back(p);
67 return !IsValidSplineTurn((p - np1).Normalize(), dir2);
68 }
69}
70
71void ReplaceLastCorner(std::vector<m2::PointD> const & roundedCorner, m2::SplineEx & spline)
72{

Callers 1

AddPointAndRoundFunction · 0.85

Calls 9

IsValidSplineTurnFunction · 0.85
GetVisualScaleMethod · 0.80
SquaredLengthMethod · 0.80
DotProductFunction · 0.50
CrossProductFunction · 0.50
clearMethod · 0.45
LengthMethod · 0.45
push_backMethod · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected