public Result <Rectangle> PutNextRectangle(Size rectangleSize) { if (pointGenerator == null) { return(Result.Fail <Rectangle>("Point generator cannot be null")); } if (rectangleSize.Height <= 0 || rectangleSize.Width <= 0) { return(Result.Fail <Rectangle>("Rectangle size must be more than zero")); } Point point; try { point = pointGenerator.GetNextPoint(); while (!CheckRectanglePosition(point, rectangleSize)) { point = pointGenerator.GetNextPoint(); } } catch (Exception e) { return(Result.Fail <Rectangle>(e.Message)); } var rectangle = GetLocatedRectangle(point, rectangleSize); cloudRectangles.Add(rectangle); pointGenerator.StartOver(); return(rectangle); }
private Rectangle PutRectangleOnSpiral(Size rectangleSize) { var point = generator.GetNextPoint(); return(new Rectangle(new Point(point.X - rectangleSize.Width / 2, point.Y - rectangleSize.Height / 2), rectangleSize)); }
public void StartOverPointGenerator_ShouldResetGeneration() { var expectedPoints = new Point[3]; for (int i = 0; i < 3; i++) { expectedPoints[i] = sut.GetNextPoint(); } sut.StartOver(); var actualPoints = new Point[3]; for (int i = 0; i < 3; i++) { actualPoints[i] = sut.GetNextPoint(); } actualPoints.Should().Equal(expectedPoints); }
public Rectangle PutNextRectangle(Size rectangleSize) { if (rectangleSize.Height <= 0 || rectangleSize.Width <= 0) { throw new ArgumentException("Rectangle size must be more than zero"); } var point = pointGenerator.GetNextPoint(); while (!CheckRectanglePosition(point, rectangleSize)) { point = pointGenerator.GetNextPoint(); } var rectangle = GetLocatedRectangle(point, rectangleSize); cloudRectangles.Add(rectangle); pointGenerator.StartOver(); return(rectangle); }
public Rectangle PutNextRectangle(Size rectangleSize) { var shift = new Size( center.X - rectangleSize.Width / 2, center.Y - rectangleSize.Height / 2 ); while (true) { var location = Point.Truncate(sequence.GetNextPoint()) + shift; var rectangle = new Rectangle(location, rectangleSize); if (IntersectsWithOthers(rectangle)) { continue; } rectangles.Add(rectangle); return(rectangle); } }
public Result <Rectangle> PutNextRectangle(Size rectangleSize) { if (rectangleSize.Width < 0 || rectangleSize.Height < 0) { return(Result.Fail <Rectangle>($"The size {rectangleSize} of the rectangle must not be negative")); } var shift = new Size(center.X - rectangleSize.Width / 2, center.Y - rectangleSize.Height / 2); while (true) { var location = Point.Truncate(sequence.GetNextPoint()) + shift; var rectangle = new Rectangle(location, rectangleSize); if (IntersectsWithOthers(rectangle)) { continue; } rectangles.Add(rectangle); return(rectangle); } }
public void PutNextRectangle_PointsGenerationStartsOver_WhenPutOneRectangle() { sut.PutNextRectangle(new Size(300, 300)); pointGenerator.GetNextPoint().Should().Be(pointGenerator.Center); }