コード例 #1
0
        private static Point?EscapeProcessI(CoverSet coverSet, Point Z, ConnectorSegment escapeLine, Orientation orientation, Size margin)
        {
            List <DistanceFromPoint> extremitiesList = new List <DistanceFromPoint>(4);
            ConnectorSegment         cover           = coverSet.GetCover(Z, (orientation == Orientation.Horizontal) ? DesignerEdges.Left : DesignerEdges.Bottom);

            if (cover != null)
            {
                AddBoundPoint(ref extremitiesList, cover.A, cover, Z);
                AddBoundPoint(ref extremitiesList, cover.B, cover, Z);
            }
            ConnectorSegment segment = coverSet.GetCover(Z, (orientation == Orientation.Horizontal) ? DesignerEdges.Right : DesignerEdges.Top);

            if (segment != null)
            {
                AddBoundPoint(ref extremitiesList, segment.A, segment, Z);
                AddBoundPoint(ref extremitiesList, segment.B, segment, Z);
            }
            if (extremitiesList.Count != 0)
            {
                DistanceSorter.Sort(ref extremitiesList);
                for (int i = 0; i < extremitiesList.Count; i++)
                {
                    DesignerEdges edges;
                    Point         point3;
                    Point         p      = extremitiesList[i].P;
                    int           x      = Math.Sign((int)(p.X - Z.X));
                    Point         point2 = new Point(x, Math.Sign((int)(p.Y - Z.Y)));
                    if (((orientation == Orientation.Vertical) ? point2.X : point2.Y) == 0)
                    {
                        p = extremitiesList[i].ConnectorSegment.ExtendPointOutwards(p);
                        int introduced13 = Math.Sign((int)(p.X - Z.X));
                        point2 = new Point(introduced13, Math.Sign((int)(p.Y - Z.Y)));
                        p      = extremitiesList[i].P;
                    }
                    if (orientation == Orientation.Vertical)
                    {
                        edges = (point2.Y < 0) ? DesignerEdges.Bottom : DesignerEdges.Top;
                    }
                    else
                    {
                        edges = (point2.X < 0) ? DesignerEdges.Left : DesignerEdges.Right;
                    }
                    if (orientation == Orientation.Vertical)
                    {
                        point3 = new Point(p.X + (point2.X * margin.Width), Z.Y);
                    }
                    else
                    {
                        point3 = new Point(Z.X, p.Y + (point2.Y * margin.Height));
                    }
                    ConnectorSegment segment4 = new ConnectorSegment(Z, point3);
                    if (((!coverSet.EscapeLineHasBeenUsed(segment4, point3) && escapeLine.IsPointOnSegment(point3)) && ((escapeLine.A != point3) && (escapeLine.B != point3))) && coverSet.IsEscapePoint(Z, point3, edges))
                    {
                        coverSet.AddUsedEscapeLine(segment4);
                        return(new Point?(point3));
                    }
                }
            }
            return(null);
        }
コード例 #2
0
        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);
        }