diff options
Diffstat (limited to 'contrib/clipper/clipper.cpp')
-rw-r--r-- | contrib/clipper/clipper.cpp | 383 |
1 files changed, 195 insertions, 188 deletions
diff --git a/contrib/clipper/clipper.cpp b/contrib/clipper/clipper.cpp index c0a8565bb..02e0b3f97 100644 --- a/contrib/clipper/clipper.cpp +++ b/contrib/clipper/clipper.cpp @@ -135,7 +135,7 @@ struct LocMinSorter inline cInt Round(double val) { - if ((val < 0)) return static_cast<cInt>(val - 0.5); + if ((val < 0)) return static_cast<cInt>(val - 0.5); else return static_cast<cInt>(val + 0.5); } //------------------------------------------------------------------------------ @@ -153,7 +153,7 @@ void PolyTree::Clear() { for (PolyNodes::size_type i = 0; i < AllNodes.size(); ++i) delete AllNodes[i]; - AllNodes.resize(0); + AllNodes.resize(0); Childs.resize(0); } //------------------------------------------------------------------------------ @@ -200,27 +200,27 @@ void PolyNode::AddChild(PolyNode& child) //------------------------------------------------------------------------------ PolyNode* PolyNode::GetNext() const -{ - if (!Childs.empty()) - return Childs[0]; +{ + if (!Childs.empty()) + return Childs[0]; else - return GetNextSiblingUp(); -} + return GetNextSiblingUp(); +} //------------------------------------------------------------------------------ PolyNode* PolyNode::GetNextSiblingUp() const -{ +{ if (!Parent) //protects against PolyTree.GetNextSiblingUp() return 0; else if (Index == Parent->Childs.size() - 1) return Parent->GetNextSiblingUp(); else return Parent->Childs[Index + 1]; -} +} //------------------------------------------------------------------------------ bool PolyNode::IsHole() const -{ +{ bool result = true; PolyNode* node = Parent; while (node) @@ -229,13 +229,13 @@ bool PolyNode::IsHole() const node = node->Parent; } return result; -} +} //------------------------------------------------------------------------------ bool PolyNode::IsOpen() const -{ +{ return m_IsOpen; -} +} //------------------------------------------------------------------------------ #ifndef use_int32 @@ -256,15 +256,22 @@ class Int128 Int128(long64 _lo = 0) { - lo = (ulong64)_lo; - if (_lo < 0) hi = -1; else hi = 0; + lo = (ulong64)_lo; + if (_lo < 0) hi = -1; else hi = 0; } Int128(const Int128 &val): lo(val.lo), hi(val.hi){} Int128(const long64& _hi, const ulong64& _lo): lo(_lo), hi(_hi){} - + + Int128& operator = (const Int128 &val) + { + lo = val.lo; + hi = val.hi; + return *this; + } + Int128& operator = (const long64 &val) { lo = (ulong64)val; @@ -449,7 +456,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path) IntPoint ipNext = (i == cnt ? path[0] : path[i]); if (ipNext.Y == pt.Y) { - if ((ipNext.X == pt.X) || (ip.Y == pt.Y && + if ((ipNext.X == pt.X) || (ip.Y == pt.Y && ((ipNext.X > pt.X) == (ip.X < pt.X)))) return -1; } if ((ip.Y < pt.Y) != (ipNext.Y < pt.Y)) @@ -459,7 +466,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path) if (ipNext.X > pt.X) result = 1 - result; else { - double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - + double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - (double)(ipNext.X - pt.X) * (ip.Y - pt.Y); if (!d) return -1; if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result; @@ -468,7 +475,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path) { if (ipNext.X > pt.X) { - double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - + double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - (double)(ipNext.X - pt.X) * (ip.Y - pt.Y); if (!d) return -1; if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result; @@ -476,7 +483,7 @@ int PointInPolygon(const IntPoint &pt, const Path &path) } } ip = ipNext; - } + } return result; } //------------------------------------------------------------------------------ @@ -490,7 +497,7 @@ int PointInPolygon (const IntPoint &pt, OutPt *op) { if (op->Next->Pt.Y == pt.Y) { - if ((op->Next->Pt.X == pt.X) || (op->Pt.Y == pt.Y && + if ((op->Next->Pt.X == pt.X) || (op->Pt.Y == pt.Y && ((op->Next->Pt.X > pt.X) == (op->Pt.X < pt.X)))) return -1; } if ((op->Pt.Y < pt.Y) != (op->Next->Pt.Y < pt.Y)) @@ -500,7 +507,7 @@ int PointInPolygon (const IntPoint &pt, OutPt *op) if (op->Next->Pt.X > pt.X) result = 1 - result; else { - double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - + double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y); if (!d) return -1; if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result; @@ -509,16 +516,16 @@ int PointInPolygon (const IntPoint &pt, OutPt *op) { if (op->Next->Pt.X > pt.X) { - double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - + double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y); if (!d) return -1; if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result; } } - } + } op = op->Next; if (startOp == op) break; - } + } return result; } //------------------------------------------------------------------------------ @@ -531,10 +538,10 @@ bool Poly2ContainsPoly1(OutPt *OutPt1, OutPt *OutPt2) //nb: PointInPolygon returns 0 if false, +1 if true, -1 if pt on polygon int res = PointInPolygon(op->Pt, OutPt2); if (res >= 0) return res > 0; - op = op->Next; + op = op->Next; } while (op != OutPt1); - return true; + return true; } //---------------------------------------------------------------------- @@ -542,11 +549,11 @@ bool SlopesEqual(const TEdge &e1, const TEdge &e2, bool UseFullInt64Range) { #ifndef use_int32 if (UseFullInt64Range) - return Int128Mul(e1.Top.Y - e1.Bot.Y, e2.Top.X - e2.Bot.X) == + return Int128Mul(e1.Top.Y - e1.Bot.Y, e2.Top.X - e2.Bot.X) == Int128Mul(e1.Top.X - e1.Bot.X, e2.Top.Y - e2.Bot.Y); - else + else #endif - return (e1.Top.Y - e1.Bot.Y) * (e2.Top.X - e2.Bot.X) == + return (e1.Top.Y - e1.Bot.Y) * (e2.Top.X - e2.Bot.X) == (e1.Top.X - e1.Bot.X) * (e2.Top.Y - e2.Bot.Y); } //------------------------------------------------------------------------------ @@ -557,7 +564,7 @@ bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, #ifndef use_int32 if (UseFullInt64Range) return Int128Mul(pt1.Y-pt2.Y, pt2.X-pt3.X) == Int128Mul(pt1.X-pt2.X, pt2.Y-pt3.Y); - else + else #endif return (pt1.Y-pt2.Y)*(pt2.X-pt3.X) == (pt1.X-pt2.X)*(pt2.Y-pt3.Y); } @@ -569,7 +576,7 @@ bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, #ifndef use_int32 if (UseFullInt64Range) return Int128Mul(pt1.Y-pt2.Y, pt3.X-pt4.X) == Int128Mul(pt1.X-pt2.X, pt3.Y-pt4.Y); - else + else #endif return (pt1.Y-pt2.Y)*(pt3.X-pt4.X) == (pt1.X-pt2.X)*(pt3.Y-pt4.Y); } @@ -621,7 +628,7 @@ inline cInt TopX(TEdge &edge, const cInt currentY) void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip) { -#ifdef use_xyz +#ifdef use_xyz ip.Z = 0; #endif @@ -653,8 +660,8 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip) b1 = Edge1.Bot.Y - (Edge1.Bot.X / Edge1.Dx); ip.Y = Round(ip.X / Edge1.Dx + b1); } - } - else + } + else { b1 = Edge1.Bot.X - Edge1.Bot.Y * Edge1.Dx; b2 = Edge2.Bot.X - Edge2.Bot.Y * Edge2.Dx; @@ -662,11 +669,11 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip) ip.Y = Round(q); if (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx)) ip.X = Round(Edge1.Dx * q + b1); - else + else ip.X = Round(Edge2.Dx * q + b2); } - if (ip.Y < Edge1.Top.Y || ip.Y < Edge2.Top.Y) + if (ip.Y < Edge1.Top.Y || ip.Y < Edge2.Top.Y) { if (Edge1.Top.Y > Edge2.Top.Y) ip.Y = Edge1.Top.Y; @@ -676,7 +683,7 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip) ip.X = TopX(Edge1, ip.Y); else ip.X = TopX(Edge2, ip.Y); - } + } //finally, don't allow 'ip' to be BELOW curr.Y (ie bottom of scanbeam) ... if (ip.Y > Edge1.Curr.Y) { @@ -760,7 +767,7 @@ inline void ReverseHorizontal(TEdge &e) //progression of the bounds - ie so their xbots will align with the //adjoining lower edge. [Helpful in the ProcessHorizontal() method.] std::swap(e.Top.X, e.Bot.X); -#ifdef use_xyz +#ifdef use_xyz std::swap(e.Top.Z, e.Bot.Z); #endif } @@ -898,10 +905,10 @@ void RangeTest(const IntPoint& Pt, bool& useFullRange) { if (useFullRange) { - if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange) + if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange) throw clipperException("Coordinate outside allowed range"); } - else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange) + else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange) { useFullRange = true; RangeTest(Pt, useFullRange); @@ -978,9 +985,9 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) //We need to be careful with open paths because this may not be a //true local minima (ie E may be following a skip edge). //Also, consecutive horz. edges may start heading left before going right. - if (NextIsForward) + if (NextIsForward) EStart = E->Prev; - else + else EStart = E->Next; if (IsHorizontal(*EStart)) //ie an adjoining horizontal skip edge { @@ -990,7 +997,7 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) else if (EStart->Bot.X != E->Bot.X) ReverseHorizontal(*E); } - + EStart = E; if (NextIsForward) { @@ -1005,19 +1012,19 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) while (IsHorizontal(*Horz->Prev)) Horz = Horz->Prev; if (Horz->Prev->Top.X > Result->Next->Top.X) Result = Horz->Prev; } - while (E != Result) + while (E != Result) { E->NextInLML = E->Next; if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Prev->Top.X) ReverseHorizontal(*E); E = E->Next; } - if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Prev->Top.X) + if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Prev->Top.X) ReverseHorizontal(*E); Result = Result->Next; //move to the edge just beyond current bound } else { - while (Result->Top.Y == Result->Prev->Bot.Y && Result->Prev->OutIdx != Skip) + while (Result->Top.Y == Result->Prev->Bot.Y && Result->Prev->OutIdx != Skip) Result = Result->Prev; if (IsHorizontal(*Result) && Result->Prev->OutIdx != Skip) { @@ -1030,11 +1037,11 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) while (E != Result) { E->NextInLML = E->Prev; - if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) + if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) ReverseHorizontal(*E); E = E->Prev; } - if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) + if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) ReverseHorizontal(*E); Result = Result->Prev; //move to the edge just beyond current bound } @@ -1096,10 +1103,10 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) eLoopStop = E; continue; } - if (E->Prev == E->Next) + if (E->Prev == E->Next) break; //only two vertices else if (Closed && - SlopesEqual(E->Prev->Curr, E->Curr, E->Next->Curr, m_UseFullRange) && + SlopesEqual(E->Prev->Curr, E->Curr, E->Next->Curr, m_UseFullRange) && (!m_PreserveCollinear || !Pt2IsBetweenPt1AndPt3(E->Prev->Curr, E->Curr, E->Next->Curr))) { @@ -1124,7 +1131,7 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) } if (!Closed) - { + { m_HasOpenPaths = true; eStart->Prev->OutIdx = Skip; } @@ -1143,9 +1150,9 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) //Totally flat paths must be handled differently when adding them //to LocalMinima list to avoid endless loops etc ... - if (IsFlat) + if (IsFlat) { - if (Closed) + if (Closed) { delete [] edges; return false; @@ -1187,7 +1194,7 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) //Compare their slopes to find which starts which bound ... MinimaList::value_type locMin; locMin.Y = E->Bot.Y; - if (E->Dx < E->Prev->Dx) + if (E->Dx < E->Prev->Dx) { locMin.LeftBound = E->Prev; locMin.RightBound = E; @@ -1442,7 +1449,7 @@ void ClipperBase::SwapPositionsInAEL(TEdge *Edge1, TEdge *Edge2) void ClipperBase::UpdateEdgeIntoAEL(TEdge *&e) { - if (!e->NextInLML) + if (!e->NextInLML) throw clipperException("UpdateEdgeIntoAEL: invalid call"); e->NextInLML->OutIdx = e->OutIdx; @@ -1480,15 +1487,15 @@ Clipper::Clipper(int initOptions) : ClipperBase() //constructor m_StrictSimple = ((initOptions & ioStrictlySimple) != 0); m_PreserveCollinear = ((initOptions & ioPreserveCollinear) != 0); m_HasOpenPaths = false; -#ifdef use_xyz +#ifdef use_xyz m_ZFill = 0; #endif } //------------------------------------------------------------------------------ -#ifdef use_xyz +#ifdef use_xyz void Clipper::ZFillFunction(ZFillCallback zFillFunc) -{ +{ m_ZFill = zFillFunc; } //------------------------------------------------------------------------------ @@ -1547,7 +1554,7 @@ void Clipper::FixHoleLinkage(OutRec &outrec) { //skip OutRecs that (a) contain outermost polygons or //(b) already have the correct owner/child linkage ... - if (!outrec.FirstLeft || + if (!outrec.FirstLeft || (outrec.IsHole != outrec.FirstLeft->IsHole && outrec.FirstLeft->Pts)) return; @@ -1567,7 +1574,7 @@ bool Clipper::ExecuteInternal() m_SortedEdges = 0; succeeded = true; - cInt botY, topY; + cInt botY = 0, topY = 0; if (!PopScanbeam(botY)) return false; InsertLocalMinimaIntoAEL(botY); while (PopScanbeam(topY) || LocalMinimaPending()) @@ -1584,7 +1591,7 @@ bool Clipper::ExecuteInternal() InsertLocalMinimaIntoAEL(botY); } } - catch(...) + catch(...) { succeeded = false; } @@ -1638,7 +1645,7 @@ void Clipper::SetWindingCount(TEdge &edge) edge.WindCnt = edge.WindDelta; edge.WindCnt2 = 0; e = m_ActiveEdges; //ie get ready to calc WindCnt2 - } + } else if (edge.WindDelta == 0 && m_ClipType != ctUnion) { edge.WindCnt = 1; @@ -1655,7 +1662,7 @@ void Clipper::SetWindingCount(TEdge &edge) TEdge *e2 = e->PrevInAEL; while (e2) { - if (e2->PolyTyp == e->PolyTyp && e2->WindDelta != 0) + if (e2->PolyTyp == e->PolyTyp && e2->WindDelta != 0) Inside = !Inside; e2 = e2->PrevInAEL; } @@ -1667,7 +1674,7 @@ void Clipper::SetWindingCount(TEdge &edge) } edge.WindCnt2 = e->WindCnt2; e = e->NextInAEL; //ie get ready to calc WindCnt2 - } + } else { //nonZero, Positive or Negative filling ... @@ -1678,11 +1685,11 @@ void Clipper::SetWindingCount(TEdge &edge) if (Abs(e->WindCnt) > 1) { //outside prev poly but still inside another. - //when reversing direction of prev poly use the same WC + //when reversing direction of prev poly use the same WC if (e->WindDelta * edge.WindDelta < 0) edge.WindCnt = e->WindCnt; //otherwise continue to 'decrease' WC ... else edge.WindCnt = e->WindCnt + edge.WindDelta; - } + } else //now outside all polys of same polytype so set own WC ... edge.WindCnt = (edge.WindDelta == 0 ? 1 : edge.WindDelta); @@ -1690,7 +1697,7 @@ void Clipper::SetWindingCount(TEdge &edge) { //prev edge is 'increasing' WindCount (WC) away from zero //so we're inside the previous polygon ... - if (edge.WindDelta == 0) + if (edge.WindDelta == 0) edge.WindCnt = (e->WindCnt < 0 ? e->WindCnt - 1 : e->WindCnt + 1); //if wind direction is reversing prev then use same WC else if (e->WindDelta * edge.WindDelta < 0) edge.WindCnt = e->WindCnt; @@ -1754,14 +1761,14 @@ bool Clipper::IsContributing(const TEdge& edge) const switch(pft) { - case pftEvenOdd: + case pftEvenOdd: //return false if a subj line has been flagged as inside a subj polygon if (edge.WindDelta == 0 && edge.WindCnt != 1) return false; break; case pftNonZero: if (Abs(edge.WindCnt) != 1) return false; break; - case pftPositive: + case pftPositive: if (edge.WindCnt != 1) return false; break; default: //pftNegative @@ -1773,24 +1780,24 @@ bool Clipper::IsContributing(const TEdge& edge) const case ctIntersection: switch(pft2) { - case pftEvenOdd: - case pftNonZero: + case pftEvenOdd: + case pftNonZero: return (edge.WindCnt2 != 0); - case pftPositive: + case pftPositive: return (edge.WindCnt2 > 0); - default: + default: return (edge.WindCnt2 < 0); } break; case ctUnion: switch(pft2) { - case pftEvenOdd: - case pftNonZero: + case pftEvenOdd: + case pftNonZero: return (edge.WindCnt2 == 0); - case pftPositive: + case pftPositive: return (edge.WindCnt2 <= 0); - default: + default: return (edge.WindCnt2 >= 0); } break; @@ -1798,23 +1805,23 @@ bool Clipper::IsContributing(const TEdge& edge) const if (edge.PolyTyp == ptSubject) switch(pft2) { - case pftEvenOdd: - case pftNonZero: + case pftEvenOdd: + case pftNonZero: return (edge.WindCnt2 == 0); - case pftPositive: + case pftPositive: return (edge.WindCnt2 <= 0); - default: + default: return (edge.WindCnt2 >= 0); } else switch(pft2) { - case pftEvenOdd: - case pftNonZero: + case pftEvenOdd: + case pftNonZero: return (edge.WindCnt2 != 0); - case pftPositive: + case pftPositive: return (edge.WindCnt2 > 0); - default: + default: return (edge.WindCnt2 < 0); } break; @@ -1822,15 +1829,15 @@ bool Clipper::IsContributing(const TEdge& edge) const if (edge.WindDelta == 0) //XOr always contributing unless open switch(pft2) { - case pftEvenOdd: - case pftNonZero: + case pftEvenOdd: + case pftNonZero: return (edge.WindCnt2 == 0); - case pftPositive: + case pftPositive: return (edge.WindCnt2 <= 0); - default: + default: return (edge.WindCnt2 >= 0); } - else + else return true; break; default: @@ -1851,7 +1858,7 @@ OutPt* Clipper::AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &Pt) e2->Side = esRight; e = e1; if (e->PrevInAEL == e2) - prevE = e2->PrevInAEL; + prevE = e2->PrevInAEL; else prevE = e->PrevInAEL; } else @@ -1867,7 +1874,7 @@ OutPt* Clipper::AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &Pt) prevE = e->PrevInAEL; } - if (prevE && prevE->OutIdx >= 0 && prevE->Top.Y < Pt.Y && e->Top.Y < Pt.Y) + if (prevE && prevE->OutIdx >= 0 && prevE->Top.Y < Pt.Y && e->Top.Y < Pt.Y) { cInt xPrev = TopX(*prevE, Pt.Y); cInt xE = TopX(*e, Pt.Y); @@ -1891,9 +1898,9 @@ void Clipper::AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &Pt) e1->OutIdx = Unassigned; e2->OutIdx = Unassigned; } - else if (e1->OutIdx < e2->OutIdx) - AppendPolygon(e1, e2); - else + else if (e1->OutIdx < e2->OutIdx) + AppendPolygon(e1, e2); + else AppendPolygon(e2, e1); } //------------------------------------------------------------------------------ @@ -1983,7 +1990,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) { TEdge* lb = lm->LeftBound; TEdge* rb = lm->RightBound; - + OutPt *Op1 = 0; if (!lb) { @@ -1991,8 +1998,8 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) InsertEdgeIntoAEL(rb, 0); SetWindingCount(*rb); if (IsContributing(*rb)) - Op1 = AddOutPt(rb, rb->Bot); - } + Op1 = AddOutPt(rb, rb->Bot); + } else if (!rb) { InsertEdgeIntoAEL(lb, 0); @@ -2009,7 +2016,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) rb->WindCnt = lb->WindCnt; rb->WindCnt2 = lb->WindCnt2; if (IsContributing(*lb)) - Op1 = AddLocalMinPoly(lb, rb, lb->Bot); + Op1 = AddLocalMinPoly(lb, rb, lb->Bot); InsertScanbeam(lb->Top.Y); } @@ -2018,7 +2025,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) if (IsHorizontal(*rb)) { AddEdgeToSEL(rb); - if (rb->NextInLML) + if (rb->NextInLML) InsertScanbeam(rb->NextInLML->Top.Y); } else InsertScanbeam( rb->Top.Y ); @@ -2027,7 +2034,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) if (!lb || !rb) continue; //if any output polygons share an edge, they'll need joining later ... - if (Op1 && IsHorizontal(*rb) && + if (Op1 && IsHorizontal(*rb) && m_GhostJoins.size() > 0 && (rb->WindDelta != 0)) { for (JoinList::size_type i = 0; i < m_GhostJoins.size(); ++i) @@ -2040,7 +2047,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) } } - if (lb->OutIdx >= 0 && lb->PrevInAEL && + if (lb->OutIdx >= 0 && lb->PrevInAEL && lb->PrevInAEL->Curr.X == lb->Bot.X && lb->PrevInAEL->OutIdx >= 0 && SlopesEqual(lb->PrevInAEL->Bot, lb->PrevInAEL->Top, lb->Curr, lb->Top, m_UseFullRange) && @@ -2073,7 +2080,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) } } } - + } } //------------------------------------------------------------------------------ @@ -2099,7 +2106,7 @@ void Clipper::SetZ(IntPoint& pt, TEdge& e1, TEdge& e2) else if (pt == e1.Top) pt.Z = e1.Top.Z; else if (pt == e2.Bot) pt.Z = e2.Bot.Z; else if (pt == e2.Top) pt.Z = e2.Top.Z; - else (*m_ZFill)(e1.Bot, e1.Top, e2.Bot, e2.Top, pt); + else (*m_ZFill)(e1.Bot, e1.Top, e2.Bot, e2.Top, pt); } //------------------------------------------------------------------------------ #endif @@ -2122,7 +2129,7 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) if (e1->WindDelta == 0 && e2->WindDelta == 0) return; //if intersecting a subj line with a subj poly ... - else if (e1->PolyTyp == e2->PolyTyp && + else if (e1->PolyTyp == e2->PolyTyp && e1->WindDelta != e2->WindDelta && m_ClipType == ctUnion) { if (e1->WindDelta == 0) @@ -2145,13 +2152,13 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) else if (e1->PolyTyp != e2->PolyTyp) { //toggle subj open path OutIdx on/off when Abs(clip.WndCnt) == 1 ... - if ((e1->WindDelta == 0) && abs(e2->WindCnt) == 1 && + if ((e1->WindDelta == 0) && abs(e2->WindCnt) == 1 && (m_ClipType != ctUnion || e2->WindCnt2 == 0)) { AddOutPt(e1, Pt); if (e1Contributing) e1->OutIdx = Unassigned; } - else if ((e2->WindDelta == 0) && (abs(e1->WindCnt) == 1) && + else if ((e2->WindDelta == 0) && (abs(e1->WindCnt) == 1) && (m_ClipType != ctUnion || e1->WindCnt2 == 0)) { AddOutPt(e2, Pt); @@ -2225,7 +2232,7 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) if ((e1Wc != 0 && e1Wc != 1) || (e2Wc != 0 && e2Wc != 1) || (e1->PolyTyp != e2->PolyTyp && m_ClipType != ctXor) ) { - AddLocalMaxPoly(e1, e2, Pt); + AddLocalMaxPoly(e1, e2, Pt); } else { @@ -2237,7 +2244,7 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) } else if ( e1Contributing ) { - if (e2Wc == 0 || e2Wc == 1) + if (e2Wc == 0 || e2Wc == 1) { AddOutPt(e1, Pt); SwapSides(*e1, *e2); @@ -2246,13 +2253,13 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) } else if ( e2Contributing ) { - if (e1Wc == 0 || e1Wc == 1) + if (e1Wc == 0 || e1Wc == 1) { AddOutPt(e2, Pt); SwapSides(*e1, *e2); SwapPolyIndexes(*e1, *e2); } - } + } else if ( (e1Wc == 0 || e1Wc == 1) && (e2Wc == 0 || e2Wc == 1)) { //neither edge is currently contributing ... @@ -2308,7 +2315,7 @@ void Clipper::SetHoleState(TEdge *e, OutRec *outrec) if (e2->OutIdx >= 0 && e2->WindDelta != 0) { if (!eTmp) eTmp = e2; - else if (eTmp->OutIdx == e2->OutIdx) eTmp = 0; + else if (eTmp->OutIdx == e2->OutIdx) eTmp = 0; } e2 = e2->PrevInAEL; } @@ -2328,9 +2335,9 @@ void Clipper::SetHoleState(TEdge *e, OutRec *outrec) OutRec* GetLowermostRec(OutRec *outRec1, OutRec *outRec2) { //work out which polygon fragment has the correct hole state ... - if (!outRec1->BottomPt) + if (!outRec1->BottomPt) outRec1->BottomPt = GetBottomPt(outRec1->Pts); - if (!outRec2->BottomPt) + if (!outRec2->BottomPt) outRec2->BottomPt = GetBottomPt(outRec2->Pts); OutPt *OutPt1 = outRec1->BottomPt; OutPt *OutPt2 = outRec2->BottomPt; @@ -2376,7 +2383,7 @@ void Clipper::AppendPolygon(TEdge *e1, TEdge *e2) holeStateRec = outRec2; else if (OutRec1RightOfOutRec2(outRec2, outRec1)) holeStateRec = outRec1; - else + else holeStateRec = GetLowermostRec(outRec1, outRec2); //get the start and ends of both output polygons and @@ -2643,7 +2650,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) GetHorzDirection(*horzEdge, dir, horzLeft, horzRight); TEdge* eLastHorz = horzEdge, *eMaxPair = 0; - while (eLastHorz->NextInLML && IsHorizontal(*eLastHorz->NextInLML)) + while (eLastHorz->NextInLML && IsHorizontal(*eLastHorz->NextInLML)) eLastHorz = eLastHorz->NextInLML; if (!eLastHorz->NextInLML) eMaxPair = GetMaximaPair(eLastHorz); @@ -2673,7 +2680,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) for (;;) //loop through consec. horizontal edges { - + bool IsLastHorz = (horzEdge == eLastHorz); TEdge* e = GetNextInAEL(horzEdge, dir); while(e) @@ -2686,7 +2693,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) { if (dir == dLeftToRight) { - while (maxIt != m_Maxima.end() && *maxIt < e->Curr.X) + while (maxIt != m_Maxima.end() && *maxIt < e->Curr.X) { if (horzEdge->OutIdx >= 0 && !IsOpen) AddOutPt(horzEdge, IntPoint(*maxIt, horzEdge->Bot.Y)); @@ -2709,7 +2716,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) //Also break if we've got to the end of an intermediate horizontal edge ... //nb: Smaller Dx's are to the right of larger Dx's ABOVE the horizontal. - if (e->Curr.X == horzEdge->Top.X && horzEdge->NextInLML && + if (e->Curr.X == horzEdge->Top.X && horzEdge->NextInLML && e->Dx < horzEdge->NextInLML->Dx) break; if (horzEdge->OutIdx >= 0 && !IsOpen) //note: may be done multiple times @@ -2717,7 +2724,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) #ifdef use_xyz if (dir == dLeftToRight) SetZ(e->Curr, *horzEdge, *e); else SetZ(e->Curr, *e, *horzEdge); -#endif +#endif op1 = AddOutPt(horzEdge, e->Curr); TEdge* eNextHorz = m_SortedEdges; while (eNextHorz) @@ -2733,7 +2740,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) } AddGhostJoin(op1, horzEdge->Bot); } - + //OK, so far we're still in range of the horizontal Edge but make sure //we're at the last of consec. horizontals when matching with eMaxPair if(e == eMaxPair && IsLastHorz) @@ -2744,7 +2751,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) DeleteFromAEL(eMaxPair); return; } - + if(dir == dLeftToRight) { IntPoint Pt = IntPoint(e->Curr.X, horzEdge->Curr.Y); @@ -2815,7 +2822,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) } } else - UpdateEdgeIntoAEL(horzEdge); + UpdateEdgeIntoAEL(horzEdge); } else { @@ -2835,7 +2842,7 @@ bool Clipper::ProcessIntersections(const cInt topY) if (IlSize == 1 || FixupIntersectionOrder()) ProcessIntersectList(); else return false; } - catch(...) + catch(...) { m_SortedEdges = 0; DisposeIntersectNodes(); @@ -2940,7 +2947,7 @@ bool Clipper::FixupIntersectionOrder() CopyAELToSEL(); std::sort(m_IntersectList.begin(), m_IntersectList.end(), IntersectListSort); size_t cnt = m_IntersectList.size(); - for (size_t i = 0; i < cnt; ++i) + for (size_t i = 0; i < cnt; ++i) { if (!EdgesAdjacent(*m_IntersectList[i])) { @@ -2988,7 +2995,7 @@ void Clipper::DoMaxima(TEdge *e) #ifdef use_lines else if (e->WindDelta == 0) { - if (e->OutIdx >= 0) + if (e->OutIdx >= 0) { AddOutPt(e, e->Top); e->OutIdx = Unassigned; @@ -3001,7 +3008,7 @@ void Clipper::DoMaxima(TEdge *e) eMaxPair->OutIdx = Unassigned; } DeleteFromAEL(eMaxPair); - } + } #endif else throw clipperException("DoMaxima error"); } @@ -3039,7 +3046,7 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) if (e->OutIdx >= 0) AddOutPt(e, e->Bot); AddEdgeToSEL(e); - } + } else { e->Curr.X = TopX( *e, topY ); @@ -3052,7 +3059,7 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) //When StrictlySimple and 'e' is being touched by another edge, then //make sure both edges have a vertex here ... if (m_StrictSimple) - { + { TEdge* ePrev = e->PrevInAEL; if ((e->OutIdx >= 0) && (e->WindDelta != 0) && ePrev && (ePrev->OutIdx >= 0) && (ePrev->Curr.X == e->Curr.X) && (ePrev->WindDelta != 0)) @@ -3083,7 +3090,7 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) if(IsIntermediate(e, topY)) { OutPt* op = 0; - if( e->OutIdx >= 0 ) + if( e->OutIdx >= 0 ) op = AddOutPt(e, e->Top); UpdateEdgeIntoAEL(e); @@ -3250,12 +3257,12 @@ void Clipper::BuildResult2(PolyTree& polytree) { OutRec* outRec = m_PolyOuts[i]; if (!outRec->PolyNd) continue; - if (outRec->IsOpen) + if (outRec->IsOpen) { outRec->PolyNd->m_IsOpen = true; polytree.AddChild(*outRec->PolyNd); } - else if (outRec->FirstLeft && outRec->FirstLeft->PolyNd) + else if (outRec->FirstLeft && outRec->FirstLeft->PolyNd) outRec->FirstLeft->PolyNd->AddChild(*outRec->PolyNd); else polytree.AddChild(*outRec->PolyNd); @@ -3278,24 +3285,24 @@ void SwapIntersectNodes(IntersectNode &int1, IntersectNode &int2) inline bool E2InsertsBeforeE1(TEdge &e1, TEdge &e2) { - if (e2.Curr.X == e1.Curr.X) + if (e2.Curr.X == e1.Curr.X) { if (e2.Top.Y > e1.Top.Y) - return e2.Top.X < TopX(e1, e2.Top.Y); + return e2.Top.X < TopX(e1, e2.Top.Y); else return e1.Top.X > TopX(e2, e1.Top.Y); - } + } else return e2.Curr.X < e1.Curr.X; } //------------------------------------------------------------------------------ -bool GetOverlap(const cInt a1, const cInt a2, const cInt b1, const cInt b2, +bool GetOverlap(const cInt a1, const cInt a2, const cInt b1, const cInt b2, cInt& Left, cInt& Right) { if (a1 < a2) { if (b1 < b2) {Left = std::max(a1,b1); Right = std::min(a2,b2);} else {Left = std::max(a1,b2); Right = std::min(a2,b1);} - } + } else { if (b1 < b2) {Left = std::max(a2,b1); Right = std::min(a1,b2);} @@ -3306,7 +3313,7 @@ bool GetOverlap(const cInt a1, const cInt a2, const cInt b1, const cInt b2, //------------------------------------------------------------------------------ inline void UpdateOutPtIdxs(OutRec& outrec) -{ +{ OutPt* op = outrec.Pts; do { @@ -3331,11 +3338,11 @@ void Clipper::InsertEdgeIntoAEL(TEdge *edge, TEdge* startEdge) edge->NextInAEL = m_ActiveEdges; m_ActiveEdges->PrevInAEL = edge; m_ActiveEdges = edge; - } + } else { if(!startEdge) startEdge = m_ActiveEdges; - while(startEdge->NextInAEL && + while(startEdge->NextInAEL && !E2InsertsBeforeE1(*startEdge->NextInAEL , *edge)) startEdge = startEdge->NextInAEL; edge->NextInAEL = startEdge->NextInAEL; @@ -3357,7 +3364,7 @@ OutPt* DupOutPt(OutPt* outPt, bool InsertAfter) result->Prev = outPt; outPt->Next->Prev = result; outPt->Next = result; - } + } else { result->Prev = outPt->Prev; @@ -3381,24 +3388,24 @@ bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, //So, to facilitate this while inserting Op1b and Op2b ... //when DiscardLeft, make sure we're AT or RIGHT of Pt before adding Op1b, //otherwise make sure we're AT or LEFT of Pt. (Likewise with Op2b.) - if (Dir1 == dLeftToRight) + if (Dir1 == dLeftToRight) { - while (op1->Next->Pt.X <= Pt.X && - op1->Next->Pt.X >= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) + while (op1->Next->Pt.X <= Pt.X && + op1->Next->Pt.X >= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) op1 = op1->Next; if (DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next; op1b = DupOutPt(op1, !DiscardLeft); - if (op1b->Pt != Pt) + if (op1b->Pt != Pt) { op1 = op1b; op1->Pt = Pt; op1b = DupOutPt(op1, !DiscardLeft); } - } + } else { - while (op1->Next->Pt.X >= Pt.X && - op1->Next->Pt.X <= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) + while (op1->Next->Pt.X >= Pt.X && + op1->Next->Pt.X <= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) op1 = op1->Next; if (!DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next; op1b = DupOutPt(op1, DiscardLeft); @@ -3412,7 +3419,7 @@ bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, if (Dir2 == dLeftToRight) { - while (op2->Next->Pt.X <= Pt.X && + while (op2->Next->Pt.X <= Pt.X && op2->Next->Pt.X >= op2->Pt.X && op2->Next->Pt.Y == Pt.Y) op2 = op2->Next; if (DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next; @@ -3425,8 +3432,8 @@ bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, }; } else { - while (op2->Next->Pt.X >= Pt.X && - op2->Next->Pt.X <= op2->Pt.X && op2->Next->Pt.Y == Pt.Y) + while (op2->Next->Pt.X >= Pt.X && + op2->Next->Pt.X <= op2->Pt.X && op2->Next->Pt.Y == Pt.Y) op2 = op2->Next; if (!DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next; op2b = DupOutPt(op2, DiscardLeft); @@ -3476,11 +3483,11 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) //Strictly Simple join ... if (outRec1 != outRec2) return false; op1b = j->OutPt1->Next; - while (op1b != op1 && (op1b->Pt == j->OffPt)) + while (op1b != op1 && (op1b->Pt == j->OffPt)) op1b = op1b->Next; bool reverse1 = (op1b->Pt.Y > j->OffPt.Y); op2b = j->OutPt2->Next; - while (op2b != op2 && (op2b->Pt == j->OffPt)) + while (op2b != op2 && (op2b->Pt == j->OffPt)) op2b = op2b->Next; bool reverse2 = (op2b->Pt.Y > j->OffPt.Y); if (reverse1 == reverse2) return false; @@ -3507,7 +3514,7 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) j->OutPt2 = op1b; return true; } - } + } else if (isHorizontal) { //treat horizontal joins differently to non-horizontal joins since with @@ -3537,18 +3544,18 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) //on the discard Side as either may still be needed for other joins ... IntPoint Pt; bool DiscardLeftSide; - if (op1->Pt.X >= Left && op1->Pt.X <= Right) + if (op1->Pt.X >= Left && op1->Pt.X <= Right) { Pt = op1->Pt; DiscardLeftSide = (op1->Pt.X > op1b->Pt.X); - } - else if (op2->Pt.X >= Left&& op2->Pt.X <= Right) + } + else if (op2->Pt.X >= Left&& op2->Pt.X <= Right) { Pt = op2->Pt; DiscardLeftSide = (op2->Pt.X > op2b->Pt.X); - } + } else if (op1b->Pt.X >= Left && op1b->Pt.X <= Right) { Pt = op1b->Pt; DiscardLeftSide = op1b->Pt.X > op1->Pt.X; - } + } else { Pt = op2b->Pt; DiscardLeftSide = (op2b->Pt.X > op2->Pt.X); @@ -3624,7 +3631,7 @@ static OutRec* ParseFirstLeft(OutRec* FirstLeft) //------------------------------------------------------------------------------ void Clipper::FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec) -{ +{ //tests if NewOutRec contains the polygon before reassigning FirstLeft for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) { @@ -3721,7 +3728,7 @@ void Clipper::JoinCommonEdges() if ((outRec2->IsHole ^ m_ReverseOutput) == (Area(*outRec2) > 0)) ReversePolyPtLinks(outRec2->Pts); - + } else if (Poly2ContainsPoly1(outRec1->Pts, outRec2->Pts)) { //outRec2 contains outRec1 ... @@ -3734,7 +3741,7 @@ void Clipper::JoinCommonEdges() if ((outRec1->IsHole ^ m_ReverseOutput) == (Area(*outRec1) > 0)) ReversePolyPtLinks(outRec1->Pts); - } + } else { //the 2 polygons are completely separate ... @@ -3744,7 +3751,7 @@ void Clipper::JoinCommonEdges() //fixup FirstLeft pointers that may need reassigning to OutRec2 if (m_UsingPolyTree) FixupFirstLefts1(outRec1, outRec2); } - + } else { //joined 2 polygons together ... @@ -3754,7 +3761,7 @@ void Clipper::JoinCommonEdges() outRec2->Idx = outRec1->Idx; outRec1->IsHole = holeStateRec->IsHole; - if (holeStateRec == outRec2) + if (holeStateRec == outRec2) outRec1->FirstLeft = outRec2->FirstLeft; outRec2->FirstLeft = outRec1; @@ -3769,7 +3776,7 @@ void Clipper::JoinCommonEdges() DoublePoint GetUnitNormal(const IntPoint &pt1, const IntPoint &pt2) { - if(pt2.X == pt1.X && pt2.Y == pt1.Y) + if(pt2.X == pt1.X && pt2.Y == pt1.Y) return DoublePoint(0, 0); double Dx = (double)(pt2.X - pt1.X); @@ -3863,7 +3870,7 @@ void ClipperOffset::FixOrientations() { //fixup orientations of all closed paths if the orientation of the //closed path with the lowermost vertex is wrong ... - if (m_lowest.X >= 0 && + if (m_lowest.X >= 0 && !Orientation(m_polyNodes.Childs[(int)m_lowest.X]->Contour)) { for (int i = 0; i < m_polyNodes.ChildCount(); ++i) @@ -3890,7 +3897,7 @@ void ClipperOffset::Execute(Paths& solution, double delta) solution.clear(); FixOrientations(); DoOffset(delta); - + //now clean up 'corners' ... Clipper clpr; clpr.AddPaths(m_destPolys, ptSubject, true); @@ -3962,7 +3969,7 @@ void ClipperOffset::DoOffset(double delta) m_delta = delta; //if Zero offset, just copy any CLOSED polygons to m_p and return ... - if (NEAR_ZERO(delta)) + if (NEAR_ZERO(delta)) { m_destPolys.reserve(m_polyNodes.ChildCount()); for (int i = 0; i < m_polyNodes.ChildCount(); i++) @@ -3980,12 +3987,12 @@ void ClipperOffset::DoOffset(double delta) double y; if (ArcTolerance <= 0.0) y = def_arc_tolerance; - else if (ArcTolerance > std::fabs(delta) * def_arc_tolerance) + else if (ArcTolerance > std::fabs(delta) * def_arc_tolerance) y = std::fabs(delta) * def_arc_tolerance; else y = ArcTolerance; //see offset_triginometry2.svg in the documentation folder ... double steps = pi / std::acos(1 - y / std::fabs(delta)); - if (steps > std::fabs(delta) * pi) + if (steps > std::fabs(delta) * pi) steps = std::fabs(delta) * pi; //ie excessive precision check m_sin = std::sin(two_pi / steps); m_cos = std::cos(two_pi / steps); @@ -4133,17 +4140,17 @@ void ClipperOffset::OffsetPoint(int j, int& k, JoinType jointype) { //cross product ... m_sinA = (m_normals[k].X * m_normals[j].Y - m_normals[j].X * m_normals[k].Y); - if (std::fabs(m_sinA * m_delta) < 1.0) + if (std::fabs(m_sinA * m_delta) < 1.0) { //dot product ... - double cosA = (m_normals[k].X * m_normals[j].X + m_normals[j].Y * m_normals[k].Y ); + double cosA = (m_normals[k].X * m_normals[j].X + m_normals[j].Y * m_normals[k].Y ); if (cosA > 0) // angle => 0 degrees { m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].X + m_normals[k].X * m_delta), Round(m_srcPoly[j].Y + m_normals[k].Y * m_delta))); - return; + return; } - //else angle => 180 degrees + //else angle => 180 degrees } else if (m_sinA > 1.0) m_sinA = 1.0; else if (m_sinA < -1.0) m_sinA = -1.0; @@ -4222,7 +4229,7 @@ void ClipperOffset::DoRound(int j, int k) void Clipper::DoSimplePolygons() { PolyOutList::size_type i = 0; - while (i < m_PolyOuts.size()) + while (i < m_PolyOuts.size()) { OutRec* outrec = m_PolyOuts[i++]; OutPt* op = outrec->Pts; @@ -4230,9 +4237,9 @@ void Clipper::DoSimplePolygons() do //for each Pt in Polygon until duplicate found do ... { OutPt* op2 = op->Next; - while (op2 != outrec->Pts) + while (op2 != outrec->Pts) { - if ((op->Pt == op2->Pt) && op2->Next != op && op2->Prev != op) + if ((op->Pt == op2->Pt) && op2->Next != op && op2->Prev != op) { //split the polygon into two ... OutPt* op3 = op->Prev; @@ -4343,7 +4350,7 @@ double DistanceFromLineSqrd( } //--------------------------------------------------------------------------- -bool SlopesNearCollinear(const IntPoint& pt1, +bool SlopesNearCollinear(const IntPoint& pt1, const IntPoint& pt2, const IntPoint& pt3, double distSqrd) { //this function is more accurate when the point that's geometrically @@ -4392,10 +4399,10 @@ void CleanPolygon(const Path& in_poly, Path& out_poly, double distance) { //distance = proximity in units/pixels below which vertices //will be stripped. Default ~= sqrt(2). - + size_t size = in_poly.size(); - - if (size == 0) + + if (size == 0) { out_poly.clear(); return; @@ -4412,13 +4419,13 @@ void CleanPolygon(const Path& in_poly, Path& out_poly, double distance) double distSqrd = distance * distance; OutPt* op = &outPts[0]; - while (op->Idx == 0 && op->Next != op->Prev) + while (op->Idx == 0 && op->Next != op->Prev) { if (PointsAreClose(op->Pt, op->Prev->Pt, distSqrd)) { op = ExcludeOp(op); size--; - } + } else if (PointsAreClose(op->Prev->Pt, op->Next->Pt, distSqrd)) { ExcludeOp(op->Next); @@ -4468,7 +4475,7 @@ void CleanPolygons(Paths& polys, double distance) } //------------------------------------------------------------------------------ -void Minkowski(const Path& poly, const Path& path, +void Minkowski(const Path& poly, const Path& path, Paths& solution, bool isSum, bool isClosed) { int delta = (isClosed ? 1 : 0); @@ -4575,7 +4582,7 @@ void AddPolyNodeToPaths(const PolyNode& polynode, NodeType nodetype, Paths& path void PolyTreeToPaths(const PolyTree& polytree, Paths& paths) { - paths.resize(0); + paths.resize(0); paths.reserve(polytree.Total()); AddPolyNodeToPaths(polytree, ntAny, paths); } @@ -4583,7 +4590,7 @@ void PolyTreeToPaths(const PolyTree& polytree, Paths& paths) void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths) { - paths.resize(0); + paths.resize(0); paths.reserve(polytree.Total()); AddPolyNodeToPaths(polytree, ntClosed, paths); } @@ -4591,7 +4598,7 @@ void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths) void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths) { - paths.resize(0); + paths.resize(0); paths.reserve(polytree.Total()); //Open paths are top level only, so ... for (int i = 0; i < polytree.ChildCount(); ++i) |