public Result <Rectangle> PutNextRectangle(Size rectangleSize) { if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) { return(Fail <Rectangle>("size has non positive parts")); } var nextPosition = spiralGenerator.Next(); if (!nextPosition.IsSuccess) { return(Fail <Rectangle>(nextPosition.Error)); } var rectangle = new Rectangle(nextPosition.Value, rectangleSize); while (DoesIntersectWithPreviousRectangles(rectangle)) { nextPosition = spiralGenerator.Next(); if (!nextPosition.IsSuccess) { return(Fail <Rectangle>(nextPosition.Error)); } rectangle = new Rectangle(nextPosition.Value, rectangleSize); } rectangle = AdjustPosition(rectangle); rectangles.Add(rectangle); return(rectangle.AsResult()); }
public Rectangle PutNextRectangle(Size rectangleSize) { if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) { throw new ArgumentException("size has non positive parts"); } var nextPosition = spiralGenerator.Next(); var rectangle = new Rectangle(nextPosition, rectangleSize); while (DoesIntersectWithPreviousRectangles(rectangle)) { nextPosition = spiralGenerator.Next(); rectangle = new Rectangle(nextPosition, rectangleSize); } rectangle = AdjustPosition(rectangle); rectangles.Add(rectangle); return(rectangle); }
public static IEnumerable <Point> Take(this AbstractSpiralGenerator generator, int amount) => Enumerable.Range(0, amount) .Select(_ => generator.Next());