public void CalculateAngleOfRotation_WhenBoxIsOverCenterPointAndClockwise_ReturnsFirstQuadrantData() { // Arrange var box = new Box { X = 0, Y = 0 }; var shape = new Shape { CenterX = 0, CenterY = 0 }; // Act var result = sut.CalculateAngleOfRotation(box, shape, RotationDirection.CLOCKWISE, 0); // Assert Assert.That(result, Is.InRange(threePiOverTwo - 0.0000001, threePiOverTwo + 0.0000001)); }
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)); } }