Exemplo n.º 1
0
        private Rectangle GetMaze()
        {
            if (!Rectangles.Any())
            {
                return(Rectangle.Empty);
            }

            var top    = Rectangles.Min(rectangle => rectangle.Top);
            var bottom = Rectangles.Max(rectangle => rectangle.Bottom);
            var left   = Rectangles.Min(rectangle => rectangle.Left);
            var right  = Rectangles.Max(rectangle => rectangle.Right);

            return(new Rectangle(left, top, Math.Abs(right - left), Math.Abs(bottom - top)));
        }
Exemplo n.º 2
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            Rectangle nextRectangle;

            do
            {
                nextRectangle = new Rectangle(Spiral.GetNextPoint(), rectangleSize);
            }while (Rectangles.Any(r => r.IntersectsWith(nextRectangle)));

            if (NeedingShiftToCenter)
            {
                nextRectangle = GetShiftedToCenterRectangle(nextRectangle);
            }
            Rectangles.Add(nextRectangle);
            return(nextRectangle);
        }
Exemplo n.º 3
0
        public Vector2Int GetFirstWorkableCubePosition()
        {
            for (int y = 0; y < YBound + 1; y++)
            {
                for (int x = 0; x < XBound + 1; x++)
                {
                    var cube = Cubes[x, y];
                    var pos  = new Vector2Int(x, y);
                    if (cube.IsFull && !Rectangles.Any(r => r.Contains(pos)))
                    {
                        return(pos);
                    }
                }
            }

            return(-Vector2Int.One);
        }
Exemplo n.º 4
0
 private bool ContainsAllFullAndNotInRect(RectangleInt rectangle)
 {
     if (rectangle.TopLeft < Vector2Int.Zero || rectangle.BottomRight > Bounds)
     {
         return(false);
     }
     for (int x = rectangle.X; x < rectangle.X + rectangle.Width; x++)
     {
         for (int y = rectangle.Y; y < rectangle.Y + rectangle.Height; y++)
         {
             if (!Cubes[x, y].IsFull || Rectangles.Any(r => r.Contains(new Vector2Int(x, y))))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemplo n.º 5
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            Rectangle nextRectangle;

            do
            {
                var center    = Spiral.GetNextPoint();
                var leftAngle = new Point(center.X - rectangleSize.Width / 2, center.Y - rectangleSize.Height / 2);
                nextRectangle = new Rectangle(leftAngle, rectangleSize);
            } while (Rectangles.Any(r => r.IntersectsWith(nextRectangle)));

            if (NeedingShiftToCenter)
            {
                nextRectangle = GetShiftedToCenterRectangle(nextRectangle);
            }
            Rectangles.Add(nextRectangle);
            return(nextRectangle);
        }
Exemplo n.º 6
0
        public new Rectangle PutNextRectangle(Size rectangleSize)
        {
            foreach (var point in Spiral.GetPoints(center))
            {
                var rectangle =
                    new Rectangle(new Point(point.X - rectangleSize.Width / 2, point.Y - rectangleSize.Height / 2),
                                  rectangleSize);
                if (Rectangles.Any(r => r.Contains(point)))
                {
                    continue;
                }
                if (HasOverlappingRectangles(rectangle, Rectangles))
                {
                    continue;
                }

                Rectangles.Add(rectangle);
                return(rectangle);
            }

            // до суда потенциально не дойдет, т.к. спираль выдает бесконечно точки
            return(new Rectangle());
        }
Exemplo n.º 7
0
        private Rectangle GetShiftedToCenterRectangle(Rectangle initialRectangle)
        {
            var minDistanceToCenter = double.MaxValue;
            var shiftedRectangle    = initialRectangle;
            var queue = new Queue <Rectangle>();

            queue.Enqueue(shiftedRectangle);

            while (queue.Any())
            {
                var currentRectangle = queue.Dequeue();
                var distanceToCenter = currentRectangle.Location.DistanceTo(Center);
                if (Rectangles.Any(r => r.IntersectsWith(currentRectangle)) ||
                    distanceToCenter >= minDistanceToCenter)
                {
                    continue;
                }
                minDistanceToCenter = distanceToCenter;
                shiftedRectangle    = currentRectangle;
                GetNeighboursFor(currentRectangle).ForEach(r => queue.Enqueue(r));
            }

            return(shiftedRectangle);
        }
Exemplo n.º 8
0
 private bool RectangleHasCollisions(Rectangle rectangle)
 {
     return(Rectangles.Any(r => r.IntersectsWith(rectangle)));
 }