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))); }
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); }
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); }
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); }
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); }
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()); }
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); }
private bool RectangleHasCollisions(Rectangle rectangle) { return(Rectangles.Any(r => r.IntersectsWith(rectangle))); }