| 225 | } |
| 226 | |
| 227 | void ClipPathByRectBeforeSmooth(m2::RectD const & rect, std::vector<m2::PointD> const & path, |
| 228 | GuidePointsForSmooth & guidePoints, std::vector<std::vector<m2::PointD>> & clippedPaths) |
| 229 | { |
| 230 | if (path.size() < 2) |
| 231 | return; |
| 232 | |
| 233 | auto const rectCase = GetRectCase(rect, path); |
| 234 | if (rectCase == RectCase::Outside) |
| 235 | return; |
| 236 | |
| 237 | m2::PointD guideFront; |
| 238 | m2::PointD guideBack; |
| 239 | double constexpr kEps = 1e-5; |
| 240 | if (path.front().EqualDxDy(path.back(), kEps)) |
| 241 | { |
| 242 | guideFront = path[path.size() - 2]; |
| 243 | guideBack = path[1]; |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | guideFront = path[0] + (path[0] - path[1]) * 2.0; |
| 248 | guideBack = path.back() + (path.back() - path[path.size() - 2]) * 2.0; |
| 249 | } |
| 250 | |
| 251 | if (rectCase == RectCase::Inside) |
| 252 | { |
| 253 | clippedPaths.push_back(path); |
| 254 | guidePoints.push_back({guideFront, guideBack}); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | // Divide spline into parts. |
| 259 | clippedPaths.reserve(2); |
| 260 | std::vector<m2::PointD> currentPath; |
| 261 | m2::PointD currentGuideFront; |
| 262 | m2::PointD currentGuideBack; |
| 263 | |
| 264 | auto const startCurrentPath = [&](size_t pos) |
| 265 | { |
| 266 | if (pos > 0) |
| 267 | currentPath.push_back(path[pos - 1]); |
| 268 | currentGuideFront = pos > 1 ? path[pos - 2] : guideFront; |
| 269 | }; |
| 270 | |
| 271 | auto const finishCurrentPath = [&](size_t pos) |
| 272 | { |
| 273 | currentPath.push_back(path[pos]); |
| 274 | currentGuideBack = pos < path.size() - 1 ? path[pos + 1] : guideBack; |
| 275 | |
| 276 | clippedPaths.emplace_back(std::move(currentPath)); |
| 277 | guidePoints.push_back({currentGuideFront, currentGuideBack}); |
| 278 | |
| 279 | currentPath = {}; |
| 280 | }; |
| 281 | |
| 282 | for (size_t pos = 0; pos < path.size(); ++pos) |
| 283 | { |
| 284 | if (rect.IsPointInside(path[pos])) |
no test coverage detected