| 3218 | //------------------------------------------------------------------------------ |
| 3219 | |
| 3220 | void Clipper::BuildResult2(PolyTree& polytree) |
| 3221 | { |
| 3222 | polytree.Clear(); |
| 3223 | polytree.AllNodes.reserve(m_PolyOuts.size()); |
| 3224 | //add each output polygon/contour to polytree ... |
| 3225 | for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); i++) |
| 3226 | { |
| 3227 | OutRec* outRec = m_PolyOuts[i]; |
| 3228 | int cnt = PointCount(outRec->Pts); |
| 3229 | if ((outRec->IsOpen && cnt < 2) || (!outRec->IsOpen && cnt < 3)) continue; |
| 3230 | FixHoleLinkage(*outRec); |
| 3231 | PolyNode* pn = new PolyNode(); |
| 3232 | //nb: polytree takes ownership of all the PolyNodes |
| 3233 | polytree.AllNodes.push_back(pn); |
| 3234 | outRec->PolyNd = pn; |
| 3235 | pn->Parent = 0; |
| 3236 | pn->Index = 0; |
| 3237 | pn->Contour.reserve(cnt); |
| 3238 | OutPt *op = outRec->Pts->Prev; |
| 3239 | for (int j = 0; j < cnt; j++) |
| 3240 | { |
| 3241 | pn->Contour.push_back(op->Pt); |
| 3242 | op = op->Prev; |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | //fixup PolyNode links etc ... |
| 3247 | polytree.Childs.reserve(m_PolyOuts.size()); |
| 3248 | for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); i++) |
| 3249 | { |
| 3250 | OutRec* outRec = m_PolyOuts[i]; |
| 3251 | if (!outRec->PolyNd) continue; |
| 3252 | if (outRec->IsOpen) |
| 3253 | { |
| 3254 | outRec->PolyNd->m_IsOpen = true; |
| 3255 | polytree.AddChild(*outRec->PolyNd); |
| 3256 | } |
| 3257 | else if (outRec->FirstLeft && outRec->FirstLeft->PolyNd) |
| 3258 | outRec->FirstLeft->PolyNd->AddChild(*outRec->PolyNd); |
| 3259 | else |
| 3260 | polytree.AddChild(*outRec->PolyNd); |
| 3261 | } |
| 3262 | } |
| 3263 | //------------------------------------------------------------------------------ |
| 3264 | |
| 3265 | void SwapIntersectNodes(IntersectNode &int1, IntersectNode &int2) |