| 26 | int constexpr kMaxStepsCount = 7; |
| 27 | |
| 28 | bool 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 | |
| 71 | void ReplaceLastCorner(std::vector<m2::PointD> const & roundedCorner, m2::SplineEx & spline) |
| 72 | { |
no test coverage detected