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

Function ClipPathByRectImpl

libs/geometry/clipping.cpp:136–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134
135template <class FnT>
136void ClipPathByRectImpl(m2::RectD const & rect, std::vector<m2::PointD> const & path, FnT && fn)
137{
138 size_t const sz = path.size();
139 if (sz < 2)
140 return;
141
142 // Divide spline into parts.
143 m2::PointD p1, p2;
144 int code1 = 0;
145 int code2 = 0;
146 m2::SharedSpline s;
147
148 for (size_t i = 0; i < sz - 1; i++)
149 {
150 p1 = path[i];
151 p2 = path[i + 1];
152 if (m2::Intersect(rect, p1, p2, code1, code2))
153 {
154 if (s.IsNull())
155 s.Reset(new m2::Spline(sz - i));
156
157 s->AddPoint(p1);
158 s->AddPoint(p2);
159
160 if (code2 != 0 || i + 2 == sz)
161 {
162 if (s->GetSize() > 1)
163 fn(std::move(s));
164 s.Reset(nullptr);
165 }
166 }
167 else if (!s.IsNull() && !s->IsEmpty())
168 {
169 if (s->GetSize() > 1)
170 fn(std::move(s));
171 s.Reset(nullptr);
172 }
173 }
174}
175
176enum class RectCase
177{

Callers 2

ClipSplineByRectFunction · 0.85
ClipPathByRectFunction · 0.85

Calls 7

IsNullMethod · 0.80
IntersectFunction · 0.70
sizeMethod · 0.45
ResetMethod · 0.45
AddPointMethod · 0.45
GetSizeMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected