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 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);
        }