Skip to content

Commit

Permalink
Fix code style issues in ColorManipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
JLdgu committed May 19, 2024
1 parent e163c82 commit 8c3c247
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Hsb ToHsb(this Color color)
g /= 255;
b /= 255;

double[] rgb = new[] { r, g, b };
double[] rgb = [r, g, b];
double max = rgb.Max();
double min = rgb.Min();
double v = max;
Expand Down
10 changes: 5 additions & 5 deletions src/MaterialDesignColors.Wpf/ColorManipulation/HslExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal static class HslExtensions
{
public static Color ToColor(this Hsl hsl)
{
double hsv_rbg(double v1, double v2, double vH)
static double hsv_rbg(double v1, double v2, double vH)
{
if (vH < 0) vH += 1;
if (vH > 1) vH -= 1;
Expand All @@ -16,9 +16,9 @@ public static Color ToColor(this Hsl hsl)
return (v1);
}

var h = hsl.H * (1.0 / 360);
var s = hsl.S * (1.0 / 100);
var l = hsl.L * (1.0 / 100);
double h = hsl.H * (1.0 / 360);
double s = hsl.S * (1.0 / 100);
double l = hsl.L * (1.0 / 100);

double r, g, b;
if (s == 0)
Expand All @@ -33,7 +33,7 @@ public static Color ToColor(this Hsl hsl)
if (l < 0.5) var_2 = l * (1 + s);
else var_2 = (l + s) - (s * l);

var var_1 = 2 * l - var_2;
double var_1 = 2 * l - var_2;

r = 255 * hsv_rbg(var_1, var_2, h + (1.0 / 3));
g = 255 * hsv_rbg(var_1, var_2, h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static Lab ToLab(this Color c)

public static Lab ToLab(this Xyz xyz)
{
double xyz_lab(double v)
static double xyz_lab(double v)
{
if (v > LabConstants.e)
return Math.Pow(v, 1 / 3.0);
Expand Down
28 changes: 14 additions & 14 deletions src/MaterialDesignColors.Wpf/ColorManipulation/XyzExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ byte clip(double d)
if (d > 255) return 255;
return (byte)Math.Round(d);
}
var r = xyz_rgb(3.2404542 * xyz.X - 1.5371385 * xyz.Y - 0.4985314 * xyz.Z);
var g = xyz_rgb(-0.9692660 * xyz.X + 1.8760108 * xyz.Y + 0.0415560 * xyz.Z);
var b = xyz_rgb(0.0556434 * xyz.X - 0.2040259 * xyz.Y + 1.0572252 * xyz.Z);
double r = xyz_rgb(3.2404542 * xyz.X - 1.5371385 * xyz.Y - 0.4985314 * xyz.Z);
double g = xyz_rgb(-0.9692660 * xyz.X + 1.8760108 * xyz.Y + 0.0415560 * xyz.Z);
double b = xyz_rgb(0.0556434 * xyz.X - 0.2040259 * xyz.Y + 1.0572252 * xyz.Z);

return Color.FromRgb(clip(r), clip(g), clip(b));
}
public static Xyz ToXyz(this Color c)
{
double rgb_xyz(double v)
static double rgb_xyz(double v)
{
v /= 255;
if (v > 0.04045)
Expand All @@ -37,29 +37,29 @@ public static Xyz ToXyz(this Color c)
return v / 12.92;
}

var r = rgb_xyz(c.R);
var g = rgb_xyz(c.G);
var b = rgb_xyz(c.B);
double r = rgb_xyz(c.R);
double g = rgb_xyz(c.G);
double b = rgb_xyz(c.B);

var x = 0.4124564 * r + 0.3575761 * g + 0.1804375 * b;
var y = 0.2126729 * r + 0.7151522 * g + 0.0721750 * b;
var z = 0.0193339 * r + 0.1191920 * g + 0.9503041 * b;
double x = 0.4124564 * r + 0.3575761 * g + 0.1804375 * b;
double y = 0.2126729 * r + 0.7151522 * g + 0.0721750 * b;
double z = 0.0193339 * r + 0.1191920 * g + 0.9503041 * b;
return new Xyz(x, y, z);
}

public static Xyz ToXyz(this Lab lab)
{
double lab_xyz(double d)
static double lab_xyz(double d)
{
if (d > LabConstants.eCubedRoot)
return d * d * d;
else
return (116 * d - 16) / LabConstants.k;
}

var y = (lab.L + 16.0) / 116.0;
var x = double.IsNaN(lab.A) ? y : y + lab.A / 500.0;
var z = double.IsNaN(lab.B) ? y : y - lab.B / 200.0;
double y = (lab.L + 16.0) / 116.0;
double x = double.IsNaN(lab.A) ? y : y + lab.A / 500.0;
double z = double.IsNaN(lab.B) ? y : y - lab.B / 200.0;

y = LabConstants.WhitePointY * lab_xyz(y);
x = LabConstants.WhitePointX * lab_xyz(x);
Expand Down

0 comments on commit 8c3c247

Please sign in to comment.