private static bool Param1RightOfParam2(OutRec outRec1, OutRec outRec2) { Contract.Requires(outRec1 != null); do { outRec1 = outRec1.FirstLeft; if (outRec1 == outRec2) return true; } while (outRec1 != null); return false; }
private static void UpdateOutPtIdxs(OutRec outRec) { Contract.Requires(outRec != null); Contract.Requires(outRec.Pts != null); var op = outRec.Pts; do { op = op.Prev; } while (op != outRec.Pts); }
private static void FixupOutPolygon(OutRec outRec) { Contract.Requires(outRec != null); Contract.Requires(outRec.Pts != null); //FixupOutPolygon() - removes duplicate points and simplifies consecutive //parallel edges by removing the middle vertex. OutPt lastOk = null; outRec.BottomPt = null; var pp = outRec.Pts; for (;;) { if (pp.Prev == pp || pp.Prev == pp.Next) { DisposeOutPts(pp); outRec.Pts = null; return; } //test for duplicate points and for same slope (cross-product) ... if (pp.Pt.Equals(pp.Next.Pt) || InternalHelpers.SlopesEqual(pp.Prev.Pt, pp.Pt, pp.Next.Pt)) { lastOk = null; pp.Prev.Next = pp.Next; pp.Next.Prev = pp.Prev; pp = pp.Prev; } else if (pp == lastOk) break; else { if (lastOk == null) lastOk = pp; pp = pp.Next; } } outRec.Pts = pp; }
private static OutRec GetLowermostRec(OutRec outRec1, OutRec outRec2) { Contract.Requires(outRec2 != null); Contract.Requires(outRec1 != null); //work out which polygon fragment has the correct hole state ... if (outRec1.BottomPt == null) outRec1.BottomPt = outRec1.Pts.GetBottomPt(); if (outRec2.BottomPt == null) outRec2.BottomPt = outRec2.Pts.GetBottomPt(); var bPt1 = outRec1.BottomPt; var bPt2 = outRec2.BottomPt; if (bPt1.Pt.Y > bPt2.Pt.Y) return outRec1; else if (bPt1.Pt.Y < bPt2.Pt.Y) return outRec2; else if (bPt1.Pt.X < bPt2.Pt.X) return outRec1; else if (bPt1.Pt.X > bPt2.Pt.X) return outRec2; else if (bPt1.Next == bPt1) return outRec2; else if (bPt2.Next == bPt2) return outRec1; else if (InternalHelpers.FirstIsBottomPt(bPt1, bPt2)) return outRec1; else return outRec2; }
private static void FixHoleLinkage(OutRec outRec) { Contract.Requires(outRec != null); //skip if an outermost polygon or //already already points to the correct FirstLeft ... if (outRec.FirstLeft == null || (outRec.IsHole != outRec.FirstLeft.IsHole && outRec.FirstLeft.Pts != null)) return; var orfl = outRec.FirstLeft; while (orfl != null && ((orfl.IsHole == outRec.IsHole) || orfl.Pts == null)) orfl = orfl.FirstLeft; outRec.FirstLeft = orfl; }
private void SetHoleState(TEdge e, OutRec outRec) { Contract.Requires(e != null); var isHole = false; var e2 = e.PrevInAEL; while (e2 != null) { if (e2.OutIdx >= 0) { isHole = !isHole; if (outRec.FirstLeft == null) outRec.FirstLeft = _polyOuts[e2.OutIdx]; } e2 = e2.PrevInAEL; } if (isHole) outRec.IsHole = true; }
private void FixupFirstLefts2(OutRec oldOutRec, OutRec newOutRec) { foreach (var outRec in _polyOuts.Where(outRec => outRec.FirstLeft == oldOutRec)) outRec.FirstLeft = newOutRec; }
private void FixupFirstLefts1(OutRec oldOutRec, OutRec newOutRec) { foreach (var outRec in _polyOuts.Where(outRec => outRec.Pts != null && outRec.FirstLeft == oldOutRec && Poly2ContainsPoly1(outRec.Pts, newOutRec.Pts))) outRec.FirstLeft = newOutRec; }
private OutRec CreateOutRec() { var result = new OutRec { Idx = -1, IsHole = false, FirstLeft = null, Pts = null, BottomPt = null, PolyNode = null }; _polyOuts.Add(result); result.Idx = _polyOuts.Count - 1; return result; }