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

Function ClipPathByRectBeforeSmooth

libs/geometry/clipping.cpp:227–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227void 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]))

Callers 1

ProcessLineRulesMethod · 0.85

Calls 11

GetRectCaseFunction · 0.85
frontMethod · 0.80
backMethod · 0.80
IntersectFunction · 0.70
sizeMethod · 0.45
EqualDxDyMethod · 0.45
push_backMethod · 0.45
reserveMethod · 0.45
emplace_backMethod · 0.45
IsPointInsideMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected