コード例 #1
0
        public void Rotate(Shape shape, RotationDirection direction)
        {
            foreach (var box in shape.Boxes)
            {
                var radius = mathHelperService.CalculateRadius(box.X, box.Y, shape.CenterX, shape.CenterY);

                if (radius == 0)
                {
                    // The box is at the center of the shape, no rotation
                    continue;
                }

                var adjacentAngle = mathHelperService.CalculateAdjacentAngleInRadians(Math.Abs(box.X - shape.CenterX), radius);

                var angle = mathHelperService.CalculateAngleOfRotation(box, shape, direction, adjacentAngle);

                box.X = Convert.ToInt32(shape.CenterX + radius * Math.Cos(angle));
                box.Y = Convert.ToInt32(shape.CenterY + radius * Math.Sin(angle));
            }
        }
コード例 #2
0
 public void CalculateRadius_WhenPointsAreAllZero_ReturnsZero()
 {
     Assert.That(sut.CalculateRadius(0, 0, 0, 0), Is.EqualTo(0));
 }