@DrunkDog

Сможете разбить последний большой метод на вспомогательные?

Помогите разбить последний большой метод на вспомогательные, буду весьма благодарен
using System;
using System.Drawing;
using System.Drawing.Drawing2D;


namespace RefactorMe
{
    class Printer
    {
        static float x, y;
        static Graphics graphics;

        public static void Initialize ( Graphics newGraphics )
        {
            graphics = newGraphics;
            graphics.SmoothingMode = SmoothingMode.None;
            graphics.Clear(Color.Black);
        }

        public static void SetPosition(float x0, float y0)
        {
            x = x0;
            y = y0;
        }

        public static void MakeIt(Pen pen, double length, double angle)
        {
        var x1 = (float)(x + length * Math.Cos(angle));
        var y1 = (float)(y + length * Math.Sin(angle));

        graphics.DrawLine(pen, x, y, x1, y1);

        x = x1;
        y = y1;
        }

        public static void Change(double length, double angle)
        {
           x = (float)(x + length * Math.Cos(angle)); 
           y = (float)(y + length * Math.Sin(angle));
        }
    }

    public class ImpossibleSquare
    {
        public static void Draw(int width, int height, double angleRotation, Graphics graphics)
        {
            Printer.Initialize(graphics);

            var size = Math.Min(width, height);

            var diagonalLength = Math.Sqrt(2) * (size * 0.375f + size * 0.04f) / 2;
            var x0 = (float)(diagonalLength * Math.Cos(Math.PI / 4 + Math.PI)) + width / 2f;
            var y0 = (float)(diagonalLength * Math.Sin(Math.PI / 4 + Math.PI)) + height / 2f;

            Printer.SetPosition(x0, y0);

            Printer.MakeIt(Pens.Yellow, size * 0.375f, 0);
            Printer.MakeIt(Pens.Yellow, size * 0.04f * Math.Sqrt(2), Math.PI / 4);
            Printer.MakeIt(Pens.Yellow, size * 0.375f, Math.PI);
            Printer.MakeIt(Pens.Yellow, size * 0.375f - size * 0.04f, Math.PI / 2);
            
            Printer.Change(size * 0.04f, -Math.PI);
            Printer.Change(size * 0.04f * Math.Sqrt(2), 3 * Math.PI / 4);
              

            
            Printer.MakeIt(Pens.Yellow, size * 0.375f, -Math.PI / 2);
            Printer.MakeIt(Pens.Yellow, size * 0.04f * Math.Sqrt(2), -Math.PI / 2 + Math.PI / 4);
            Printer.MakeIt(Pens.Yellow, size * 0.375f, -Math.PI / 2 + Math.PI);
            Printer.MakeIt(Pens.Yellow, size * 0.375f - size * 0.04f, -Math.PI / 2 + Math.PI / 2);

            Printer.Change(size * 0.04f, -Math.PI / 2 - Math.PI);
            Printer.Change(size * 0.04f * Math.Sqrt(2), -Math.PI / 2 + 3 * Math.PI / 4);

            
            Printer.MakeIt(Pens.Yellow, size * 0.375f, Math.PI);
            Printer.MakeIt(Pens.Yellow, size * 0.04f * Math.Sqrt(2), Math.PI + Math.PI / 4);
            Printer.MakeIt(Pens.Yellow, size * 0.375f, Math.PI + Math.PI);
            Printer.MakeIt(Pens.Yellow, size * 0.375f - size * 0.04f, Math.PI + Math.PI / 2);

            Printer.Change(size * 0.04f, Math.PI - Math.PI);
            Printer.Change(size * 0.04f * Math.Sqrt(2), Math.PI + 3 * Math.PI / 4);

            
            Printer.MakeIt(Pens.Yellow, size * 0.375f, Math.PI / 2);
            Printer.MakeIt(Pens.Yellow, size * 0.04f * Math.Sqrt(2), Math.PI / 2 + Math.PI / 4);
            Printer.MakeIt(Pens.Yellow, size * 0.375f, Math.PI / 2 + Math.PI);
            Printer.MakeIt(Pens.Yellow, size * 0.375f - size * 0.04f, Math.PI / 2 + Math.PI / 2);

            Printer.Change(size * 0.04f, Math.PI / 2 - Math.PI);
            Printer.Change(size * 0.04f * Math.Sqrt(2), Math.PI / 2 + 3 * Math.PI / 4);
        }
    }
}
  • Вопрос задан
  • 212 просмотров
Пригласить эксперта
Ответы на вопрос 1
vabka
@vabka Куратор тега C#
Токсичный шарпист
А как мы должны догадаться, что оно должно делать? Выделяете в самостоятельные блоки, избавляетесь от дублирования, так и делаете новые методы.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы