| 134 | |
| 135 | template <class FnT> |
| 136 | void 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 | |
| 176 | enum class RectCase |
| 177 | { |