Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Бабин Георгий #168

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

tripples25
Copy link

@tripples25 tripples25 commented Feb 4, 2024

Внесённые изменения

  • Классы приложения переведены на использование паттерна Result.
  • Обработаны основные исключительные ситуации.
  • Добавлены дополнительные тесты.
  • Файл README.MD обновлён в соответствии с текущим состоянием проекта.

@the-homeless-god

Comment on lines 1 to 11
# Примеры раскладки с разными параметрами
## Rectangles = 500; deltaAngle = 5°; distance = 2
![example1](https://github.com/tripples25/tdd/blob/8b58d8f0592e3592d28af7ce6bfe3c817a716d16/TagsCloudVisualization/layoutImages/new%20500%20rects%20angle%205%20distance%202.Png?raw=true)
## Rectangles = 100; deltaAngle = 5°; distance = 2
![example1](https://github.com/tripples25/tdd/blob/8b58d8f0592e3592d28af7ce6bfe3c817a716d16/TagsCloudVisualization/layoutImages/new%20angle%205%20distance%202.Png?raw=true)
## Rectangles = 100; deltaAngle = 10°; distance = 2
![example2](https://github.com/tripples25/tdd/blob/8b58d8f0592e3592d28af7ce6bfe3c817a716d16/TagsCloudVisualization/layoutImages/new%20angle%2010%20distance%202.Png?raw=true)
## Rectangles = 100; deltaAngle = 5°; distance = 0.5
![example3](https://github.com/tripples25/tdd/blob/8b58d8f0592e3592d28af7ce6bfe3c817a716d16/TagsCloudVisualization/layoutImages/new%20angle%205%20distance%200.5.Png?raw=true)
## Rectangles = 100; deltaAngle = 1°; distance = 0.5
![example4](https://github.com/tripples25/tdd/blob/8b58d8f0592e3592d28af7ce6bfe3c817a716d16/TagsCloudVisualization/layoutImages/new%20angle%201%20distance%200.5.Png?raw=true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо за README, рекомендую отформатировать только его и перенести из заголовков второго уровня информацию про параметры, можно использовать таблички

if (dialog == DialogResult.OK)
imageHolder.RecreateImage(imageSettings);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В конце файлов нужны пустые строки, можно настроить EditorConfig

public void Perform()
{
var dialog = SettingsForm.For(imageSettings).ShowDialog();
if (dialog == DialogResult.OK)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Старайся использовать { } и избегать однострочных выражений

}

public MenuCategory Category => MenuCategory.Settings;
public string Name => "Источник...";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы утащил все тексты в Resources Dictionary

Comment on lines 31 to 32
// container.RegisterType<TxtTextReader>().Keyed<TextReader>(FileExtension.Txt);
// container.RegisterType<DocTextReader>().Keyed<TextReader>(FileExtension.Doc).Keyed<TextReader>(FileExtension.Docx);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Избегаем закомменченого кода

Comment on lines 3 to 8
public class None
{
private None()
{
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не понимаю логику

Также классы лучше разнести под namespace в разных файлах

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result я брал из примера, что предоставили нам в Контуре. None в данном случае используется для представления возвращаемого значения void-методов. Какой-то дополнительной логики этот класс более не несёт.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в названии файлов не следует использовать пробелы, также .png вместо .Png


Приложение для создания облак тегов на основе текста.

![example1](https://github.com/tripples25/fp/blob/1a4585180188efc9c6a35736650295a4e470f916/TagsCloudResult/layoutImages/sample.png?raw=true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В квадратных скобках переименовать название, у самого файла сделать адекватный путь и название без camelCase к примеру

Comment on lines 29 to 30
Refresh();
Application.DoEvents();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему так решил делать?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думал запускать цикл при отрисовке тегов, чтобы отрисовывать в real-time. В целом, он теперь не нужен, да и не рекомендуем к использованию, если верить документации и форумам, поэтому убрал.

return items;
}

private static ToolStripMenuItem CreateTopLevelMenuItem(MenuCategory category, IList<IUiAction> items)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не фабричный метод, а статические методы?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну, я не рассчитывал на создание других клиентов или других типов/видов кнопок, поэтому пренебрёг пластичностью и просто создал удобные для себя статические расширения.
Создал фабрику, правда, в качестве результата там пока ToolStripItem. Это позволит создавать другие типы кнопок, унаследованные от ToolStripItem, но не подменять их другими классами не связанными с ним.


container.RegisterAssemblyTypes(typeof(IUiAction).Assembly).AsImplementedInterfaces();

container.RegisterType<PictureBoxImageHolder>().As<PictureBoxImageHolder, IImageHolder>().SingleInstance();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Было бы круто добавить здесь комментариев

Comment on lines 30 to 59
private Point MovePointAlongXAxis(Point point, Size rectangleSize)
{
var offsetToCenter = new Size(-rectangleSize.Width / 2, -rectangleSize.Height / 2);
var offsetX = Math.Sign(Center.X + offsetToCenter.Width - point.X);
while (Center.X + offsetToCenter.Width - point.X != 0 && offsetX != 0)
{
var newPoint = point.WithOffset(new Size(offsetX, 0));
if (!IsPlaceSuitableForRectangle(new Rectangle(newPoint, rectangleSize)))
break;

point = newPoint;
}

return point;
}

private Point MovePointAlongYAxis(Point point, Size rectangleSize)
{
var offsetToCenter = new Size(-rectangleSize.Width / 2, -rectangleSize.Height / 2);
var offsetY = Math.Sign(Center.Y + offsetToCenter.Height - point.Y);
while (Center.Y + offsetToCenter.Height - point.Y != 0 && offsetY != 0)
{
var newPoint = point.WithOffset(new Size(0, offsetY));
if (!IsPlaceSuitableForRectangle(new Rectangle(newPoint, rectangleSize)))
break;

point = newPoint;
}

return point;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Дублирование кода, магические цифры, не хватает SRP

Comment on lines 62 to 63
if (!tagDraw.IsSuccess)
return tagDraw;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему так?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потому что по задумке метод должен вернуть Result с ошибкой на первом теге, который не сумел отрисоваться. Переписал на LINQ, дополнительно выделив методы, убрал часть вложенности.


private Color GetTagColor(Tag tag)
{
return tag.Coeff > 0.75 ? tagsSettings.PrimaryColor : tag.Coeff > 0.35 ? tagsSettings.SecondaryColor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Избавиться от однострочности, нечитаемо, возможно даже стоит добавить комментов

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переписал, использовав константы и оператор switch.

Comment on lines 10 to 12
public DocTextReader(SourceSettings settings) : base(settings)
{
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем пустой?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потому что наследуется от абстрактного класса, в котором прописан конструктор. До этого абстрактный класс ещё содержал дополнительную общую логику, но теперь она уже отсутствует. Переписал на использование интерфейса.

Comment on lines 7 to 9
public TxtTextReader(SourceSettings settings) : base(settings)
{
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тот же вопрос почему появляются пустые конструкторы?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Красивое 🚀

Copy link

@the-homeless-god the-homeless-god left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 само приложение не потестил, вопросов нет


Приложение для создания облак тегов на основе текста.

![tagcloudsample](layoutImages/sample.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

исправить tagcloudsample на tag_cloud_sample
исправить layoutImages/ на layout/images/

Comment on lines +29 to +30
var res = dialog.ShowDialog();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var res = dialog.ShowDialog();
var res = dialog.ShowDialog();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants