private static Point?EscapeProcessII(CoverSet coverSet, Orientation orientation, ref List <Point> LeA, ref List <ConnectorSegment> LhA, ref List <ConnectorSegment> LvA, ref List <ConnectorSegment> LhB, ref List <ConnectorSegment> LvB, Point Z, Point R, Size margin, out bool intersectionFlag, out ConnectorSegment intersectionSegmentA, out ConnectorSegment intersectionSegmentB)
        {
            intersectionFlag     = false;
            intersectionSegmentA = null;
            intersectionSegmentB = null;
            ConnectorSegment escapeLine = ConnectorSegment.SegmentFromLeftToRightCover(coverSet, R);
            ConnectorSegment segment2   = ConnectorSegment.SegmentFromBottomToTopCover(coverSet, R);

            for (int i = 0; i < LvB.Count; i++)
            {
                ConnectorSegment segment  = LvB[i];
                Point?           nullable = escapeLine.Intersect(segment);
                if (nullable.HasValue)
                {
                    intersectionFlag     = true;
                    intersectionSegmentA = escapeLine;
                    intersectionSegmentB = segment;
                    LeA.Add(R);
                    return(nullable);
                }
            }
            for (int j = 0; j < LhB.Count; j++)
            {
                ConnectorSegment segment4  = LhB[j];
                Point?           nullable2 = segment2.Intersect(segment4);
                if (nullable2.HasValue)
                {
                    intersectionFlag     = true;
                    intersectionSegmentA = segment2;
                    intersectionSegmentB = segment4;
                    LeA.Add(R);
                    return(nullable2);
                }
            }
            Point?nullable3 = null;

            if (orientation == Orientation.Horizontal)
            {
                nullable3 = EscapeProcessI(coverSet, R, segment2, Orientation.Horizontal, margin);
                if (nullable3.HasValue)
                {
                    LvA.Add(segment2);
                    LeA.Add(R);
                    return(nullable3);
                }
                nullable3 = EscapeProcessI(coverSet, R, escapeLine, Orientation.Vertical, margin);
                if (nullable3.HasValue)
                {
                    LhA.Add(escapeLine);
                    LeA.Add(R);
                    return(nullable3);
                }
            }
            else
            {
                nullable3 = EscapeProcessI(coverSet, R, escapeLine, Orientation.Vertical, margin);
                if (nullable3.HasValue)
                {
                    LhA.Add(escapeLine);
                    LeA.Add(R);
                    return(nullable3);
                }
                nullable3 = EscapeProcessI(coverSet, R, segment2, Orientation.Horizontal, margin);
                if (nullable3.HasValue)
                {
                    LvA.Add(segment2);
                    LeA.Add(R);
                    return(nullable3);
                }
            }
            return(null);
        }
        private static void SecondRefinementAlgorithm(CoverSet coverSet, ref List <Point> refinedPath, Size margin)
        {
            int          num;
            List <Point> list = new List <Point>();

            for (num = 0; num < (refinedPath.Count - 1); num++)
            {
                Point            a       = refinedPath[num];
                Point            b       = refinedPath[num + 1];
                ConnectorSegment segment = ConnectorSegment.ConstructBoundSegment(coverSet, a, b);
                int num2 = num + 2;
                while (num2 < (refinedPath.Count - 1))
                {
                    Point            point3   = refinedPath[num2];
                    Point            point4   = refinedPath[num2 + 1];
                    ConnectorSegment segment2 = ConnectorSegment.ConstructBoundSegment(coverSet, point3, point4);
                    Point?           nullable = segment.Intersect(segment2);
                    if (nullable.HasValue)
                    {
                        list.Clear();
                        for (int i = 0; i <= num; i++)
                        {
                            list.Add(refinedPath[i]);
                        }
                        list.Add(nullable.Value);
                        for (int j = num2 + 1; j < refinedPath.Count; j++)
                        {
                            list.Add(refinedPath[j]);
                        }
                        List <Point> list2 = refinedPath;
                        refinedPath = list;
                        list        = list2;
                        list.Clear();
                        num2 = num + 2;
                    }
                    else
                    {
                        num2++;
                    }
                }
            }
            num = 0;
            while (num < (refinedPath.Count - 1))
            {
                Point            point5   = refinedPath[num];
                Point            point6   = refinedPath[num + 1];
                bool             flag     = false;
                ConnectorSegment segment3 = ConnectorSegment.ConstructBoundSegment(coverSet, point5, point6);
                if (segment3 != null)
                {
                    Point point7       = new Point(point6.X - point5.X, point6.Y - point5.Y);
                    int   introduced30 = Math.Abs((int)(point7.X / margin.Width));
                    int   num5         = Math.Max(introduced30, Math.Abs((int)(point7.Y / margin.Height)));
                    point7.X = Math.Sign(point7.X);
                    point7.Y = Math.Sign(point7.Y);
                    for (int k = 1; k <= num5; k++)
                    {
                        Point point8 = new Point(point5.X + ((k * margin.Width) * point7.X), point5.Y + ((k * margin.Height) * point7.Y));
                        if (point8 == point6)
                        {
                            break;
                        }
                        ConnectorSegment segment4 = ConnectorSegment.ConstructBoundSegment(coverSet, point8, (segment3.Orientation == Orientation.Horizontal) ? Orientation.Vertical : Orientation.Horizontal);
                        for (int m = num + 2; (m < (refinedPath.Count - 1)) && !flag; m++)
                        {
                            Point            point9    = refinedPath[m];
                            Point            point10   = refinedPath[m + 1];
                            ConnectorSegment segment5  = new ConnectorSegment(point9, point10);
                            Point?           nullable2 = segment4.Intersect(segment5);
                            if (nullable2.HasValue && segment5.IsPointOnSegment(nullable2.Value))
                            {
                                flag = true;
                                list.Clear();
                                for (int n = 0; n <= num; n++)
                                {
                                    list.Add(refinedPath[n]);
                                }
                                list.Add(point8);
                                list.Add(nullable2.Value);
                                for (int num9 = m + 1; num9 < refinedPath.Count; num9++)
                                {
                                    list.Add(refinedPath[num9]);
                                }
                                List <Point> list3 = refinedPath;
                                refinedPath = list;
                                list3.Clear();
                                break;
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    num++;
                }
            }
        }
        private static Point?EscapeAlgorithm(CoverSet coverSet, Point Z, Point targetPoint, ref List <Point> LeA, ref List <ConnectorSegment> LhA, ref List <ConnectorSegment> LvA, ref List <ConnectorSegment> LhB, ref List <ConnectorSegment> LvB, ref Orientation orientationA, out ConnectorSegment intersectionSegmentA, out ConnectorSegment intersectionSegmentB, Size margin, ref bool noEscapeA)
        {
            bool  flag2;
            bool  flag3;
            bool  flag4;
            bool  flag5;
            Point?nullable = null;

            intersectionSegmentA = null;
            intersectionSegmentB = null;
            ConnectorSegment cover    = coverSet.GetCover(Z, DesignerEdges.Left);
            ConnectorSegment segment2 = coverSet.GetCover(Z, DesignerEdges.Right);
            ConnectorSegment segment3 = coverSet.GetCover(Z, DesignerEdges.Bottom);
            ConnectorSegment segment4 = coverSet.GetCover(Z, DesignerEdges.Top);
            ConnectorSegment item     = ConnectorSegment.SegmentFromLeftToRightCover(coverSet, Z);

            LhA.Add(item);
            ConnectorSegment segment6 = ConnectorSegment.SegmentFromBottomToTopCover(coverSet, Z);

            LvA.Add(segment6);
            for (int i = 0; i < LvB.Count; i++)
            {
                ConnectorSegment segment = LvB[i];
                nullable = item.Intersect(segment);
                if (nullable.HasValue)
                {
                    intersectionSegmentA = item;
                    intersectionSegmentB = segment;
                    return(nullable);
                }
            }
            for (int j = 0; j < LhB.Count; j++)
            {
                ConnectorSegment segment8 = LhB[j];
                nullable = segment6.Intersect(segment8);
                if (nullable.HasValue)
                {
                    intersectionSegmentA = segment6;
                    intersectionSegmentB = segment8;
                    return(nullable);
                }
            }
            Point?nullable2 = EscapeProcessI(coverSet, Z, segment6, Orientation.Horizontal, margin);

            if (nullable2.HasValue)
            {
                orientationA = Orientation.Vertical;
                LeA.Add(nullable2.Value);
                return(null);
            }
            nullable2 = EscapeProcessI(coverSet, Z, item, Orientation.Vertical, margin);
            if (nullable2.HasValue)
            {
                orientationA = Orientation.Horizontal;
                LeA.Add(nullable2.Value);
                return(null);
            }
            bool  intersectionFlag = false;
            Point empty            = Point.Empty;
            Point r      = Point.Empty;
            Point point3 = Point.Empty;
            Point point4 = Point.Empty;

            if (segment4 != null)
            {
                empty = new Point(Z.X, segment4.A.Y);
            }
            if (segment2 != null)
            {
                r = new Point(segment2.A.X, Z.Y);
            }
            if (segment3 != null)
            {
                point3 = new Point(Z.X, segment3.A.Y);
            }
            if (cover != null)
            {
                point4 = new Point(cover.A.X, Z.Y);
            }
            do
            {
                flag2 = flag3 = flag4 = flag5 = false;
                if (segment4 != null)
                {
                    empty.Y -= margin.Height;
                    if (empty.Y > Z.Y)
                    {
                        flag2 = true;
                        Point?nullable3 = EscapeProcessII(coverSet, Orientation.Vertical, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, empty, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB);
                        if (nullable3.HasValue)
                        {
                            LvA.Add(segment6);
                            if (intersectionFlag)
                            {
                                return(nullable3);
                            }
                            orientationA = Orientation.Horizontal;
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, empty));
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(empty, nullable3.Value));
                            LeA.Add(nullable3.Value);
                            return(null);
                        }
                    }
                }
                if (segment2 != null)
                {
                    r.X -= margin.Width;
                    if (r.X > Z.X)
                    {
                        flag3 = true;
                        Point?nullable4 = EscapeProcessII(coverSet, Orientation.Horizontal, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, r, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB);
                        if (nullable4.HasValue)
                        {
                            LhA.Add(item);
                            if (intersectionFlag)
                            {
                                return(nullable4);
                            }
                            orientationA = Orientation.Vertical;
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, r));
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(r, nullable4.Value));
                            LeA.Add(nullable4.Value);
                            return(null);
                        }
                    }
                }
                if (segment3 != null)
                {
                    point3.Y += margin.Height;
                    if (point3.Y < Z.Y)
                    {
                        flag4 = true;
                        Point?nullable5 = EscapeProcessII(coverSet, Orientation.Vertical, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, point3, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB);
                        if (nullable5.HasValue)
                        {
                            LvA.Add(segment6);
                            if (intersectionFlag)
                            {
                                return(nullable5);
                            }
                            orientationA = Orientation.Horizontal;
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, point3));
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(point3, nullable5.Value));
                            LeA.Add(nullable5.Value);
                            return(null);
                        }
                    }
                }
                if (cover != null)
                {
                    point4.X += margin.Width;
                    if (point4.X < Z.X)
                    {
                        flag5 = true;
                        Point?nullable6 = EscapeProcessII(coverSet, Orientation.Horizontal, ref LeA, ref LhA, ref LvA, ref LhB, ref LvB, Z, point4, margin, out intersectionFlag, out intersectionSegmentA, out intersectionSegmentB);
                        if (nullable6.HasValue)
                        {
                            LhA.Add(item);
                            if (intersectionFlag)
                            {
                                return(nullable6);
                            }
                            orientationA = Orientation.Vertical;
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(Z, point4));
                            coverSet.AddUsedEscapeLine(new ConnectorSegment(point4, nullable6.Value));
                            LeA.Add(nullable6.Value);
                            return(null);
                        }
                    }
                }
            }while ((flag2 || flag3) || (flag4 || flag5));
            noEscapeA = true;
            return(null);
        }