Ejemplo n.º 1
0
        public static ImmutableList<TrianglePosition> GetNearest(TrianglePosition current, int triangleSize)
        {
            var hasLeft = current.Column > 0;
            var hasRight = current.Row + current.Column < triangleSize;
            var hasBottom = current.Row > 0;

            var builder = ImmutableList<TrianglePosition>.Empty.ToBuilder();

            if (hasLeft)
            {
                builder.Add(new TrianglePosition(current.Row, current.Column - 1, triangleSize));
                builder.Add(new TrianglePosition(current.Row - 1, current.Column - 1, triangleSize));
            }

            if (hasRight)
            {
                builder.Add(new TrianglePosition(current.Row, current.Column + 1, triangleSize));
                builder.Add(new TrianglePosition(current.Row + 1, current.Column, triangleSize));
            }

            if (hasBottom)
            {
                builder.Add(new TrianglePosition(current.Row - 1, current.Column + 1, triangleSize));
                builder.Add(new TrianglePosition(current.Row - 1, current.Column, triangleSize));
            }

            return builder.ToImmutable();
        }
Ejemplo n.º 2
0
            public CellData(int index, TrianglePosition position, [NotNull] ImmutableList<int> adjacentCells)
            {
                Validate.ArgumentIsNotNull(adjacentCells, nameof(adjacentCells));

                Index = index;
                Position = position;
                AdjacentCells = adjacentCells;
            }
Ejemplo n.º 3
0
        public void CheckBallCenterX([Values(1, 3, 5)]int triangleSize)
        {
            // Given
            var cellsCount = PositionHelper.GetCellsCount(triangleSize);

            var generator = new GridGenerator(cellsCount, new PortableSize(1, 10));
            var column = triangleSize / 2;
            var trianglePosition = new TrianglePosition(0, column, triangleSize);

            // When
            var centerOfMiddle = generator.GetCenterOfCell(trianglePosition);

            // Then
            centerOfMiddle.X.ShouldBe(0.5);
        }
Ejemplo n.º 4
0
        public PortablePoint GetCenterOfCell(TrianglePosition position)
        {
            var x = (position.Row + 2 * position.Column + 1) * r;
            var y = (2 + 3 * position.Row) * t / 2;

            Validate.GreaterThan(x, 0);
            Validate.GreaterThan(y, 0);
            Validate.LessOrEqualThan(y, Size.Height);
            Validate.LessOrEqualThan(x, Size.Width);

            return new PortablePoint(x, Size.Height - y);
        }
Ejemplo n.º 5
0
 public void StartDrag(TrianglePosition initialBall)
 {
 }