コード例 #1
0
ファイル: CircularCloudLayouter.cs プロジェクト: desolver/fp
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: ArchimedesSpiralTests.cs プロジェクト: desolver/di
        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);
        }
コード例 #4
0
ファイル: CircularCloudLayouter.cs プロジェクト: desolver/di
        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);
        }
コード例 #5
0
ファイル: CircularCloudLayouter.cs プロジェクト: KhDV-96/tdd
        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);
            }
        }
コード例 #6
0
ファイル: CircularCloudLayouter.cs プロジェクト: KhDV-96/fp
        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);
            }
        }
コード例 #7
0
        public void PutNextRectangle_PointsGenerationStartsOver_WhenPutOneRectangle()
        {
            sut.PutNextRectangle(new Size(300, 300));

            pointGenerator.GetNextPoint().Should().Be(pointGenerator.Center);
        }