Skip to content

Commit bcdb11e

Browse files
committed
Run TidyCode on all new classes
1 parent 5a6aae6 commit bcdb11e

12 files changed

+145
-140
lines changed

Terminal.Gui/Drawing/AssumeSupportDetector.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Implementation of <see cref="ISixelSupportDetector"/> that assumes best
5-
/// case scenario (full support including transparency with 10x20 resolution).
4+
/// Implementation of <see cref="ISixelSupportDetector"/> that assumes best
5+
/// case scenario (full support including transparency with 10x20 resolution).
66
/// </summary>
77
public class AssumeSupportDetector : ISixelSupportDetector
88
{
9-
/// <inheritdoc />
9+
/// <inheritdoc/>
1010
public SixelSupportResult Detect ()
1111
{
12-
return new SixelSupportResult
12+
return new()
1313
{
1414
IsSupported = true,
1515
MaxPaletteColors = 256,
16-
Resolution = new Size (10, 20),
16+
Resolution = new (10, 20),
1717
SupportsTransparency = true
1818
};
1919
}

Terminal.Gui/Drawing/ISixelSupportDetector.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Interface for detecting sixel support. Either through
5-
/// ansi requests to terminal or config file etc.
4+
/// Interface for detecting sixel support. Either through
5+
/// ansi requests to terminal or config file etc.
66
/// </summary>
77
public interface ISixelSupportDetector
88
{
99
/// <summary>
10-
/// Gets the supported sixel state e.g. by sending Ansi escape sequences
11-
/// or from a config file etc.
10+
/// Gets the supported sixel state e.g. by sending Ansi escape sequences
11+
/// or from a config file etc.
1212
/// </summary>
1313
/// <returns>Description of sixel support.</returns>
1414
public SixelSupportResult Detect ();

Terminal.Gui/Drawing/Quant/ColorQuantizer.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@
33
namespace Terminal.Gui;
44

55
/// <summary>
6-
/// Translates colors in an image into a Palette of up to <see cref="MaxColors"/> colors (typically 256).
6+
/// Translates colors in an image into a Palette of up to <see cref="MaxColors"/> colors (typically 256).
77
/// </summary>
88
public class ColorQuantizer
99
{
1010
/// <summary>
11-
/// Gets the current colors in the palette based on the last call to
12-
/// <see cref="BuildPalette"/>.
11+
/// Gets the current colors in the palette based on the last call to
12+
/// <see cref="BuildPalette"/>.
1313
/// </summary>
1414
public IReadOnlyCollection<Color> Palette { get; private set; } = new List<Color> ();
1515

1616
/// <summary>
17-
/// Gets or sets the maximum number of colors to put into the <see cref="Palette"/>.
18-
/// Defaults to 256 (the maximum for sixel images).
17+
/// Gets or sets the maximum number of colors to put into the <see cref="Palette"/>.
18+
/// Defaults to 256 (the maximum for sixel images).
1919
/// </summary>
2020
public int MaxColors { get; set; } = 256;
2121

2222
/// <summary>
23-
/// Gets or sets the algorithm used to map novel colors into existing
24-
/// palette colors (closest match). Defaults to <see cref="EuclideanColorDistance"/>
23+
/// Gets or sets the algorithm used to map novel colors into existing
24+
/// palette colors (closest match). Defaults to <see cref="EuclideanColorDistance"/>
2525
/// </summary>
2626
public IColorDistance DistanceAlgorithm { get; set; } = new EuclideanColorDistance ();
2727

2828
/// <summary>
29-
/// Gets or sets the algorithm used to build the <see cref="Palette"/>.
29+
/// Gets or sets the algorithm used to build the <see cref="Palette"/>.
3030
/// </summary>
31-
public IPaletteBuilder PaletteBuildingAlgorithm { get; set; } = new PopularityPaletteWithThreshold (new EuclideanColorDistance (),8) ;
31+
public IPaletteBuilder PaletteBuildingAlgorithm { get; set; } = new PopularityPaletteWithThreshold (new EuclideanColorDistance (), 8);
3232

3333
private readonly ConcurrentDictionary<Color, int> _nearestColorCache = new ();
3434

3535
/// <summary>
36-
/// Builds a <see cref="Palette"/> of colors that most represent the colors used in <paramref name="pixels"/> image.
37-
/// This is based on the currently configured <see cref="PaletteBuildingAlgorithm"/>.
36+
/// Builds a <see cref="Palette"/> of colors that most represent the colors used in <paramref name="pixels"/> image.
37+
/// This is based on the currently configured <see cref="PaletteBuildingAlgorithm"/>.
3838
/// </summary>
3939
/// <param name="pixels"></param>
4040
public void BuildPalette (Color [,] pixels)
4141
{
42-
List<Color> allColors = new List<Color> ();
42+
List<Color> allColors = new ();
4343
int width = pixels.GetLength (0);
4444
int height = pixels.GetLength (1);
4545

46-
for (int x = 0; x < width; x++)
46+
for (var x = 0; x < width; x++)
4747
{
48-
for (int y = 0; y < height; y++)
48+
for (var y = 0; y < height; y++)
4949
{
5050
allColors.Add (pixels [x, y]);
5151
}
@@ -57,14 +57,14 @@ public void BuildPalette (Color [,] pixels)
5757

5858
public int GetNearestColor (Color toTranslate)
5959
{
60-
if (_nearestColorCache.TryGetValue (toTranslate, out var cachedAnswer))
60+
if (_nearestColorCache.TryGetValue (toTranslate, out int cachedAnswer))
6161
{
6262
return cachedAnswer;
6363
}
6464

6565
// Simple nearest color matching based on DistanceAlgorithm
66-
double minDistance = double.MaxValue;
67-
int nearestIndex = 0;
66+
var minDistance = double.MaxValue;
67+
var nearestIndex = 0;
6868

6969
for (var index = 0; index < Palette.Count; index++)
7070
{
@@ -79,6 +79,7 @@ public int GetNearestColor (Color toTranslate)
7979
}
8080

8181
_nearestColorCache.TryAdd (toTranslate, nearestIndex);
82+
8283
return nearestIndex;
8384
}
84-
}
85+
}
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// <para>
5-
/// Calculates the distance between two colors using Euclidean distance in 3D RGB space.
6-
/// This measures the straight-line distance between the two points representing the colors.
7-
///</para>
8-
/// <para>
9-
/// Euclidean distance in RGB space is calculated as:
10-
/// </para>
11-
/// <code>
12-
/// √((R2 - R1)² + (G2 - G1)² + (B2 - B1)²)
13-
/// </code>
14-
/// <remarks>Values vary from 0 to ~441.67 linearly</remarks>
15-
///
16-
/// <remarks>This distance metric is commonly used for comparing colors in RGB space, though
17-
/// it doesn't account for perceptual differences in color.</remarks>
4+
/// <para>
5+
/// Calculates the distance between two colors using Euclidean distance in 3D RGB space.
6+
/// This measures the straight-line distance between the two points representing the colors.
7+
/// </para>
8+
/// <para>
9+
/// Euclidean distance in RGB space is calculated as:
10+
/// </para>
11+
/// <code>
12+
/// √((R2 - R1)² + (G2 - G1)² + (B2 - B1)²)
13+
/// </code>
14+
/// <remarks>Values vary from 0 to ~441.67 linearly</remarks>
15+
/// <remarks>
16+
/// This distance metric is commonly used for comparing colors in RGB space, though
17+
/// it doesn't account for perceptual differences in color.
18+
/// </remarks>
1819
/// </summary>
1920
public class EuclideanColorDistance : IColorDistance
2021
{
@@ -24,6 +25,7 @@ public double CalculateDistance (Color c1, Color c2)
2425
int rDiff = c1.R - c2.R;
2526
int gDiff = c1.G - c2.G;
2627
int bDiff = c1.B - c2.B;
28+
2729
return Math.Sqrt (rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
2830
}
2931
}

Terminal.Gui/Drawing/Quant/IColorDistance.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Interface for algorithms that compute the relative distance between pairs of colors.
5-
/// This is used for color matching to a limited palette, such as in Sixel rendering.
4+
/// Interface for algorithms that compute the relative distance between pairs of colors.
5+
/// This is used for color matching to a limited palette, such as in Sixel rendering.
66
/// </summary>
77
public interface IColorDistance
88
{
99
/// <summary>
10-
/// Computes a similarity metric between two <see cref="Color"/> instances.
11-
/// A larger value indicates more dissimilar colors, while a smaller value indicates more similar colors.
12-
/// The metric is internally consistent for the given algorithm.
10+
/// Computes a similarity metric between two <see cref="Color"/> instances.
11+
/// A larger value indicates more dissimilar colors, while a smaller value indicates more similar colors.
12+
/// The metric is internally consistent for the given algorithm.
1313
/// </summary>
1414
/// <param name="c1">The first color.</param>
1515
/// <param name="c2">The second color.</param>

Terminal.Gui/Drawing/Quant/IPaletteBuilder.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Builds a palette of a given size for a given set of input colors.
4+
/// Builds a palette of a given size for a given set of input colors.
55
/// </summary>
66
public interface IPaletteBuilder
77
{
88
/// <summary>
9-
/// Reduce the number of <paramref name="colors"/> to <paramref name="maxColors"/> (or less)
10-
/// using an appropriate selection algorithm.
9+
/// Reduce the number of <paramref name="colors"/> to <paramref name="maxColors"/> (or less)
10+
/// using an appropriate selection algorithm.
1111
/// </summary>
12-
/// <param name="colors">Color of every pixel in the image. Contains duplication in order
13-
/// to support algorithms that weigh how common a color is.</param>
12+
/// <param name="colors">
13+
/// Color of every pixel in the image. Contains duplication in order
14+
/// to support algorithms that weigh how common a color is.
15+
/// </param>
1416
/// <param name="maxColors">The maximum number of colours that should be represented.</param>
1517
/// <returns></returns>
1618
List<Color> BuildPalette (List<Color> colors, int maxColors);

Terminal.Gui/Drawing/Quant/PopularityPaletteWithThreshold.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
using Color = Terminal.Gui.Color;
33

44
/// <summary>
5-
/// Simple fast palette building algorithm which uses the frequency that a color is seen
6-
/// to determine whether it will appear in the final palette. Includes a threshold where
7-
/// by colors will be considered 'the same'. This reduces the chance of under represented
8-
/// colors being missed completely.
5+
/// Simple fast palette building algorithm which uses the frequency that a color is seen
6+
/// to determine whether it will appear in the final palette. Includes a threshold where
7+
/// by colors will be considered 'the same'. This reduces the chance of under represented
8+
/// colors being missed completely.
99
/// </summary>
1010
public class PopularityPaletteWithThreshold : IPaletteBuilder
1111
{
1212
private readonly IColorDistance _colorDistance;
1313
private readonly double _mergeThreshold;
1414

1515
/// <summary>
16-
/// Creates a new instance with the given color grouping parameters.
16+
/// Creates a new instance with the given color grouping parameters.
1717
/// </summary>
1818
/// <param name="colorDistance">Determines which different colors can be considered the same.</param>
1919
/// <param name="mergeThreshold">Threshold for merging two colors together.</param>
@@ -31,7 +31,7 @@ public List<Color> BuildPalette (List<Color> colors, int maxColors)
3131
}
3232

3333
// Step 1: Build the histogram of colors (count occurrences)
34-
Dictionary<Color, int> colorHistogram = new Dictionary<Color, int> ();
34+
Dictionary<Color, int> colorHistogram = new ();
3535

3636
foreach (Color color in colors)
3737
{
@@ -64,14 +64,14 @@ public List<Color> BuildPalette (List<Color> colors, int maxColors)
6464
}
6565

6666
/// <summary>
67-
/// Merge colors in the histogram if they are within the threshold distance
67+
/// Merge colors in the histogram if they are within the threshold distance
6868
/// </summary>
6969
/// <param name="colorHistogram"></param>
7070
/// <param name="maxColors"></param>
7171
/// <returns></returns>
7272
private Dictionary<Color, int> MergeSimilarColors (Dictionary<Color, int> colorHistogram, int maxColors)
7373
{
74-
Dictionary<Color, int> mergedHistogram = new Dictionary<Color, int> ();
74+
Dictionary<Color, int> mergedHistogram = new ();
7575

7676
foreach (KeyValuePair<Color, int> entry in colorHistogram)
7777
{

0 commit comments

Comments
 (0)