| 988 | //------------------------------------------------------------------------------ |
| 989 | |
| 990 | bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) { |
| 991 | #ifdef use_lines |
| 992 | if (!Closed && PolyTyp == ptClip) |
| 993 | throw clipperException("AddPath: Open paths must be subject."); |
| 994 | #else |
| 995 | if (!Closed) |
| 996 | throw clipperException("AddPath: Open paths have been disabled."); |
| 997 | #endif |
| 998 | |
| 999 | int highI = (int)pg.size() - 1; |
| 1000 | if (Closed) |
| 1001 | while (highI > 0 && (pg[highI] == pg[0])) |
| 1002 | --highI; |
| 1003 | while (highI > 0 && (pg[highI] == pg[highI - 1])) |
| 1004 | --highI; |
| 1005 | if ((Closed && highI < 2) || (!Closed && highI < 1)) |
| 1006 | return false; |
| 1007 | |
| 1008 | // create a new edge array ... |
| 1009 | TEdge *edges = new TEdge[highI + 1]; |
| 1010 | |
| 1011 | bool IsFlat = true; |
| 1012 | // 1. Basic (first) edge initialization ... |
| 1013 | try { |
| 1014 | edges[1].Curr = pg[1]; |
| 1015 | RangeTest(pg[0], m_UseFullRange); |
| 1016 | RangeTest(pg[highI], m_UseFullRange); |
| 1017 | InitEdge(&edges[0], &edges[1], &edges[highI], pg[0]); |
| 1018 | InitEdge(&edges[highI], &edges[0], &edges[highI - 1], pg[highI]); |
| 1019 | for (int i = highI - 1; i >= 1; --i) { |
| 1020 | RangeTest(pg[i], m_UseFullRange); |
| 1021 | InitEdge(&edges[i], &edges[i + 1], &edges[i - 1], pg[i]); |
| 1022 | } |
| 1023 | } catch (...) { |
| 1024 | delete[] edges; |
| 1025 | throw; // range test fails |
| 1026 | } |
| 1027 | TEdge *eStart = &edges[0]; |
| 1028 | |
| 1029 | // 2. Remove duplicate vertices, and (when closed) collinear edges ... |
| 1030 | TEdge *E = eStart, *eLoopStop = eStart; |
| 1031 | for (;;) { |
| 1032 | // nb: allows matching start and end points when not Closed ... |
| 1033 | if (E->Curr == E->Next->Curr && (Closed || E->Next != eStart)) { |
| 1034 | if (E == E->Next) |
| 1035 | break; |
| 1036 | if (E == eStart) |
| 1037 | eStart = E->Next; |
| 1038 | E = RemoveEdge(E); |
| 1039 | eLoopStop = E; |
| 1040 | continue; |
| 1041 | } |
| 1042 | if (E->Prev == E->Next) |
| 1043 | break; // only two vertices |
| 1044 | else if (Closed && |
| 1045 | SlopesEqual(E->Prev->Curr, E->Curr, E->Next->Curr, |
| 1046 | m_UseFullRange) && |
| 1047 | (!m_PreserveCollinear || |
no test coverage detected