безуспешный рефакторинг c#
Задание с ulearn.https://ulearn.me/course/basicprogramming/Praktika_Refaktoring__51aa14fb-1176-474f-a7ca-aafb86ff1967 Не понимаю, где ошибка, вот что выводит:
Неверный результат:
Как минимум один из тестов не пройден!
Название теста: DrawExpectedImage
Сообщение:
Expected: less than 100.0d
But was: 2556.0d
Стек вызовов:
at RefactorMe.DrawingProgram_Tests.AssertImageEquals(Bitmap expected, Bitmap actual)
at RefactorMe.DrawingProgram_Tests.DrawExpectedImage()
Код:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using static System.Math;
namespace RefactorMe
{
class Painter
{
public static double GetSqrt(double number)
{
return Math.Sqrt(number);
}
public static double GetCos(double number)
{
return Math.Cos(number);
}
public static double GetSin(double number)
{
return Math.Sin(number);
}
static float x, y;
static Graphics graphic;
public static void Initialize(Graphics newGraphic)
{
graphic = newGraphic;
graphic.SmoothingMode = SmoothingMode.None;
graphic.Clear(Color.Black);
}
public static void SetPosition(float x0, float y0)
{
x = x0;
y = y0;
}
public double ShiftX(double length, double angle)
{
return x + length * GetCos(angle);
}
public double ShiftY(double length, double angle)
{
return y + length * GetSin(angle);
}
public void DrawPassedStep(Pen pen, double length, double angle)
{
var x1 = (float)ShiftX(length, angle);
var y1 = (float)ShiftY(length, angle);
graphic.DrawLine(pen, x, y, x1, y1);
x = x1;
y = y1;
}
}
public class ImpossibleSquare
{
const float const1 = 0.375f;
const float const2 = 0.04f;
const double PI = Math.PI;
Painter painter = new Painter();
public static void Draw(int width, int height, double rotationAngle, Graphics graphic)
{
Painter.Initialize(graphic);
var size = Math.Min(width, height);
var color = Pens.Yellow;
Painter painter = new Painter();
void DrawSquareSide(double param)
{
painter.DrawPassedStep(color, size * const1, param);
painter.DrawPassedStep(color, size * const2 * Painter.GetSqrt(2), param + PI / 4);
painter.DrawPassedStep(color, size * const1, param + PI);
painter.DrawPassedStep(color, size * const1 - size * const2, param + PI / 2);
painter.ShiftX(size * const2, param - PI);
painter.ShiftY(size * const2, param - PI);
painter.ShiftX(size * const2 * Painter.GetSqrt(2), param + 3 * PI / 4);
painter.ShiftY(size * const2 * Painter.GetSqrt(2), param + 3 * PI / 4);
}
var diagLength = Painter.GetSqrt(2) * (size * const1 + size * const2) / 2;
var x0 = (float)(diagLength * Painter.GetCos(PI / 4 + PI) + width / 2f);
var y0 = (float)(diagLength * Painter.GetSin(PI / 4 + PI) + height / 2f);
Painter.SetPosition(x0, y0);
DrawSquareSide(0);
DrawSquareSide(-PI / 2);
DrawSquareSide(PI);
DrawSquareSide(PI / 2);
}
}
}
Причем предыдущий код работал исправно:
using System.Drawing;
using System.Drawing.Drawing2D;
namespace RefactorMe
{
class Painter
{
const double PI = Math.PI;
public static double GetSqrt(double number)
{
return Math.Sqrt(number);
}
public static double GetCos(double number)
{
return Math.Cos(number);
}
public static double GetSin(double number)
{
return Math.Sin(number);
}
static float x, y;
static Graphics graphic;
public static void Initialize(Graphics newGraphic)
{
graphic = newGraphic;
graphic.SmoothingMode = SmoothingMode.None;
graphic.Clear(Color.Black);
}
public static void Set_position(float x0, float y0)
{
x = x0;
y = y0;
}
public static void MakeIt(Pen pen, double length, double angle)
{
//Делает шаг длиной dlina в направлении ugol и рисует пройденную траекторию
var x1 = (float)(x + length * GetCos(angle));
var y1 = (float)(y + length * GetSin(angle));
graphic.DrawLine(pen, x, y, x1, y1);
x = x1;
y = y1;
}
public static void Change(double length, double angle)
{
x = (float)(x + length * GetCos(angle));
y = (float)(y + length * GetSin(angle));
}
}
public class ImpossibleSquare
{
const double PI = Math.PI;
public static double GetSqrt(double number)
{
return Math.Sqrt(number);
}
public static double GetCos(double number)
{
return Math.Cos(number);
}
public static double GetSin(double number)
{
return Math.Sin(number);
}
public static void Draw(int width, int height, double angleOfRotation, Graphics graphic)
{
// ugolPovorota пока не используется, но будет использоваться в будущем
Painter.Initialize(graphic);
var size = Math.Min(width, height);
void drawIt(double param1)
{
Painter.MakeIt(Pens.Yellow, size * 0.375f, param1);
Painter.MakeIt(Pens.Yellow, size * 0.04f * GetSqrt(2), param1 + PI / 4);
Painter.MakeIt(Pens.Yellow, size * 0.375f, param1 + PI);
Painter.MakeIt(Pens.Yellow, size * 0.375f - size * 0.04f, param1 + PI / 2);
Painter.Change(size * 0.04f, param1 - PI);
Painter.Change(size * 0.04f * GetSqrt(2), param1 + 3 * PI / 4);
}
var diagonal_length = GetSqrt(2) * (size * 0.375f + size * 0.04f) / 2;
var x0 = (float)(diagonal_length * GetCos(PI / 4 + PI)) + width / 2f;
var y0 = (float)(diagonal_length * GetSin(PI / 4 + PI)) + height / 2f;
Painter.Set_position(x0, y0);
//Рисуем 1-ую сторону
drawIt(0);
//Рисуем 2-ую сторону
drawIt(-PI / 2);
//Рисуем 3-ю сторону
drawIt(PI);
//Рисуем 4-ую сторону
drawIt(PI / 2);
}
}
}
Так в чем же все-таки ошибка? спасите помогите