示例#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.Center;
			ConnectionPoint endPoint = ConnectionPoint.Center;
			
			GetClosestConnectionPoints(out startPoint, out endPoint);

			PointF posF = GetConnectionPointPosition(from, startPoint);
			PointF posT = GetConnectionPointPosition(to, endPoint);
			
			Direction dir1 = default (Direction);
			Direction dir2 = default (Direction);
			Direction dir3 = default (Direction);
			
			float l1 = 0;
			float l2 = 0;
			float l3 = 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: dir3 = Direction.Down; break;
					case ConnectionPoint.East: dir3 = Direction.Left; break;
					case ConnectionPoint.South: dir3 = Direction.Up; break;
					case ConnectionPoint.West: dir3 = Direction.Right; break;
			}
			
			if ((dir1 == Direction.Down && dir3 == Direction.Up) ||
			    (dir3 == Direction.Down && dir1 == Direction.Up))
			{
				l1 = l3 = 20;
				float h = Math.Abs(posF.Y - posT.Y);
				if (posT.Y > posF.Y)
					l3 += 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 && dir3 == Direction.Right) ||
			         (dir3 == Direction.Left && dir1 == Direction.Right))
			{
				l1 = l3 = 20;
				float w = Math.Abs(posF.X - posT.X);
				if (posT.X > posF.X)
					l3 += 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 && dir3 == Direction.Down) ||
			         (dir1 == Direction.Up && dir3 == Direction.Up))
			{
				l1 = l3 = 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 && dir3 == Direction.Left) ||
			         (dir1 == Direction.Right && dir3 == Direction.Right))
			{
				l1 = l3 = 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) && 
			         (dir3 == Direction.Up || dir3 == Direction.Down))
			{
				l1 = Math.Abs(posF.X - posT.X);
				l3 = Math.Abs(posF.Y - posT.Y);
			}
			else if ((dir3 == Direction.Left || dir3 == Direction.Right) && 
			         (dir1 == Direction.Up || dir1 == Direction.Down))
			{
				l3 = Math.Abs(posF.X - posT.X);
				l1 = Math.Abs(posF.Y - posT.Y);
			}
			
			RouteSegment seg2 = null;
			
			RouteSegment seg1 = new RouteSegment(l1, dir1);
			if (l2 > 0)
				seg2 = new RouteSegment(l2, dir2);
			RouteSegment seg3 = new RouteSegment(l3, dir3);
			
			segments.AddFirst(seg1);
			if (seg2 != null)
				segments.AddLast(seg2);
			segments.AddLast(seg3);
		}
示例#4
0
		private void FixRouteSegment (RouteSegment seg)
		{
			
		}
示例#5
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;
		}
示例#6
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;
		}
示例#7
0
        public void Recalc(IEnumerable <IRectangle> rectangles)
        {
            segments.Clear();

            ConnectionPoint startPoint = ConnectionPoint.Center;
            ConnectionPoint endPoint   = ConnectionPoint.Center;

            GetClosestConnectionPoints(out startPoint, out endPoint);

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

            Direction dir1 = default(Direction);
            Direction dir2 = default(Direction);
            Direction dir3 = default(Direction);

            float l1 = 0;
            float l2 = 0;
            float l3 = 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: dir3 = Direction.Down; break;

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

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

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

            if ((dir1 == Direction.Down && dir3 == Direction.Up) ||
                (dir3 == Direction.Down && dir1 == Direction.Up))
            {
                l1 = l3 = 20;
                float h = Math.Abs(posF.Y - posT.Y);
                if (posT.Y > posF.Y)
                {
                    l3 += 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 && dir3 == Direction.Right) ||
                     (dir3 == Direction.Left && dir1 == Direction.Right))
            {
                l1 = l3 = 20;
                float w = Math.Abs(posF.X - posT.X);
                if (posT.X > posF.X)
                {
                    l3 += 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 && dir3 == Direction.Down) ||
                     (dir1 == Direction.Up && dir3 == Direction.Up))
            {
                l1   = l3 = 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 && dir3 == Direction.Left) ||
                     (dir1 == Direction.Right && dir3 == Direction.Right))
            {
                l1   = l3 = 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) &&
                     (dir3 == Direction.Up || dir3 == Direction.Down))
            {
                l1 = Math.Abs(posF.X - posT.X);
                l3 = Math.Abs(posF.Y - posT.Y);
            }
            else if ((dir3 == Direction.Left || dir3 == Direction.Right) &&
                     (dir1 == Direction.Up || dir1 == Direction.Down))
            {
                l3 = Math.Abs(posF.X - posT.X);
                l1 = Math.Abs(posF.Y - posT.Y);
            }

            RouteSegment seg2 = null;

            RouteSegment seg1 = new RouteSegment(l1, dir1);

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

            segments.AddFirst(seg1);
            if (seg2 != null)
            {
                segments.AddLast(seg2);
            }
            segments.AddLast(seg3);
        }
示例#8
0
 private void FixRouteSegment(RouteSegment seg)
 {
 }