Пример #1
0
        private ICollection <IRectangle> FindAllSegmentObstacles(RouteSegment seg, PointF origin, IList <IRectangle> rectangles)
        {
            List <IRectangle> obstacles = new List <IRectangle>();

            foreach (IRectangle rect in rectangles)
            {
                if (seg.IntersectsWith(origin, rect))
                {
                    obstacles.Add(rect);
                }
            }
            return(obstacles);
        }
Пример #2
0
        private IRectangle FindClosestObstacle(RouteSegment seg, PointF origin, IList <IRectangle> rectangles)
        {
            IRectangle closestRect = null;
            float      minDist     = float.MaxValue;

            foreach (IRectangle rect in FindAllSegmentObstacles(seg, origin, rectangles))
            {
                if (closestRect != null)
                {
                    float dist = seg.IntersectionDistance(origin, rect);
                    if (minDist > dist)
                    {
                        minDist     = dist;
                        closestRect = rect;
                    }
                }
                else
                {
                    closestRect = rect;
                }
            }
            return(closestRect);
        }
Пример #3
0
        public void Recalc(IEnumerable <IRectangle> rectangles)
        {
            segments.Clear();

            ConnectionPoint startPoint;           //= ConnectionPoint.East;
            ConnectionPoint endPoint;             //= ConnectionPoint.Center;

            GetClosestConnectionPoints(out startPoint, out endPoint);

            PointF posF = GetConnectionPointPosition(from);            //, startPoint
            PointF posT = GetConnectionPointPosition(to, endPoint);

            Direction dir1 = Direction.Right;             //default (Direction);
            Direction dir2 = default(Direction);
            Direction dir3 = default(Direction);
            Direction dir4 = default(Direction);

            float l1 = 0;
            float l2 = 0;
            float l3 = 0;
            float l4 = 0;


            //switch (startPoint)
            //{
            //    case ConnectionPoint.North: dir1 = Direction.Up; break;
            //    case ConnectionPoint.East: dir1 = Direction.Right; break;
            //    case ConnectionPoint.South: dir1 = Direction.Down; break;
            //    case ConnectionPoint.West: dir1 = Direction.Left; break;
            //}

            switch (endPoint)
            {
            case ConnectionPoint.North: dir4 = Direction.Down; break;

            case ConnectionPoint.East: dir4 = Direction.Left; break;

            case ConnectionPoint.South: dir4 = Direction.Up; break;

            case ConnectionPoint.West: dir4 = Direction.Right; break;
            }

            // построение соединительной линии из коротких 4-х сегментов
            if ((dir1 == Direction.Down && dir4 == Direction.Up) ||
                (dir4 == Direction.Down && dir1 == Direction.Up))
            {
                l1 = l4 = 20;
                float h = Math.Abs(posF.Y - posT.Y);
                if (posT.Y > posF.Y)
                {
                    l4 += h;
                }
                else
                {
                    l1 += h;
                }
                l2   = Math.Abs(posF.X - posT.X);
                dir2 = (posT.X > posF.X) ? Direction.Right : Direction.Left;
            }
            else if (       /*(dir1 == Direction.Left && dir4 == Direction.Right) ||*/
                (dir4 == Direction.Left && dir1 == Direction.Right))
            {               // трех сегментная линия
                l1 = l4 = 30f;
                float diffLen = (posF.X - posT.X);
                if (diffLen < 0)                   // при отрицательном значении нужно увеличить длину l1 на это положительное значение
                {
                    l1 += Math.Abs(diffLen);
                }
                else
                {
                    l4 += Math.Abs(diffLen);
                }
                //if (posT.X > posF.X)
                //	l4 += w;
                //else
                //	l1 += w;
                l2   = Math.Abs(posF.Y - posT.Y);
                dir2 = (posT.Y > posF.Y) ? Direction.Down : Direction.Up;                 // направление второго сегмента вверх/вниз
            }
            else if ((dir1 == Direction.Down && dir4 == Direction.Down) ||
                     (dir1 == Direction.Up && dir4 == Direction.Up))
            {
                l1   = l4 = Math.Abs(posF.Y - posT.Y) / 2;
                l2   = Math.Abs(posF.X - posT.X);
                dir2 = (posT.X > posF.X) ? Direction.Right : Direction.Left;
            }
            else if ((dir1 == Direction.Left && dir4 == Direction.Left) ||
                     (dir1 == Direction.Right && dir4 == Direction.Right))
            {
                l1   = l4 = Math.Abs(posF.X - posT.X) / 2;
                l2   = Math.Abs(posF.Y - posT.Y);
                dir2 = (posT.Y > posF.Y) ? Direction.Down : Direction.Up;
            }
            else if ((dir1 == Direction.Left || dir1 == Direction.Right) &&
                     (dir4 == Direction.Up || dir4 == Direction.Down))
            {
                if (posF.X >= posT.X)                   // четерых сегментная линия
                {
                    l1 = 20;

                    float fromY = from.Y;
                    dir2 = (posT.Y > posF.Y) ? Direction.Down : Direction.Up;
                    if (dir2 == Direction.Down)
                    {
                        fromY += from.Height;
                    }

                    float l2Len;
                    if (dir2 == Direction.Up && (posT.Y >= from.Y && posT.Y <= (from.Y + from.Height)))
                    {
                        l2Len = (posF.Y - posT.Y) / 2;
                        l4    = l2Len;
                    }
                    else
                    {
                        l4    = Math.Abs(fromY - posT.Y) / 2;
                        l2Len = Math.Abs(posF.Y - fromY) + l4;
                    }
                    l2 = l2Len;

                    l3   = Math.Abs(posF.X - posT.X) + l1;
                    dir3 = Direction.Left;
                }
                else
                {
                    l1 = Math.Abs(posF.X - posT.X);
                    l4 = Math.Abs(posF.Y - posT.Y);
                }
            }

            /*else if ((dir4 == Direction.Left || dir4 == Direction.Right) &&
             *       (dir1 == Direction.Up || dir1 == Direction.Down))
             * { // прямая двух сегментная линия по диагонали (неиспользуется)
             *      l4 = Math.Abs(posF.X - posT.X);
             *      l1 = Math.Abs(posF.Y - posT.Y);
             * }*/

            RouteSegment seg2 = null;
            RouteSegment seg3 = null;

            RouteSegment seg1 = new RouteSegment(l1, dir1);

            if (l2 > 0)
            {
                seg2 = new RouteSegment(l2, dir2);
            }
            if (l3 > 0)
            {
                seg3 = new RouteSegment(l3, dir3);
            }
            RouteSegment seg4 = new RouteSegment(l4, dir4);

            segments.AddFirst(seg1);
            if (seg2 != null)
            {
                segments.AddLast(seg2);
            }
            if (seg3 != null)
            {
                segments.AddLast(seg3);
            }
            segments.AddLast(seg4);
        }
Пример #4
0
 private void FixRouteSegment(RouteSegment seg)
 {
 }