Skip to content

Commit

Permalink
Merge pull request #255 from WildernessLabs/from_hsba_fix
Browse files Browse the repository at this point in the history
FromHsba fix + xml comments
  • Loading branch information
ctacke committed Aug 6, 2024
2 parents 062b242 + 7315805 commit 6c39a14
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions Source/Meadow.Contracts/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct Color
private float brightness;

/// <summary>
/// Hue of current color (0-360.0)
/// Hue of current color (0-360)
/// </summary>
public float Hue
{
Expand All @@ -82,7 +82,7 @@ public float Hue
}

/// <summary>
/// Saturation of color (0-1.0)
/// Saturation of color (0-1)
/// </summary>
public float Saturation
{
Expand All @@ -97,7 +97,7 @@ public float Saturation
}

/// <summary>
/// Brightness of color (0-1.0)
/// Brightness of color (0-1)
/// </summary>
public float Brightness
{
Expand All @@ -114,10 +114,10 @@ public float Brightness
/// <summary>
/// Create a color struct
/// </summary>
/// <param name="red">red component of color</param>
/// <param name="green">green component of color</param>
/// <param name="blue">blue component of color</param>
/// <param name="alpha">transparency of color</param>
/// <param name="red">red component of color (0-255)</param>
/// <param name="green">green component of color (0-255)</param>
/// <param name="blue">blue component of color (0-255)</param>
/// <param name="alpha">transparency of color (0-255)</param>
public Color(byte red, byte green, byte blue, byte alpha = 255)
{
R = red;
Expand All @@ -131,9 +131,9 @@ public Color(byte red, byte green, byte blue, byte alpha = 255)
/// <summary>
/// Create a color struct - convenience ctor for floats - prefer byte version
/// </summary>
/// <param name="red">red component of color</param>
/// <param name="green">green component of color</param>
/// <param name="blue">blue component of color</param>
/// <param name="red">red component of color (0-1)</param>
/// <param name="green">green component of color (0-1)</param>
/// <param name="blue">blue component of color (0-1)</param>
public Color(float red, float green, float blue) :
this((byte)(red * 255), (byte)(green * 255), (byte)(blue * 255), 255)
{
Expand All @@ -142,10 +142,10 @@ public Color(float red, float green, float blue) :
/// <summary>
/// Create a color struct
/// </summary>
/// <param name="hue">hue of color</param>
/// <param name="saturation">saturation of color</param>
/// <param name="brightness">brightness of color</param>
/// <param name="alpha">alpha (transparency) of color</param>
/// <param name="hue">hue of color (0-1)</param>
/// <param name="saturation">saturation of color (0-1)</param>
/// <param name="brightness">brightness of color (0-1)</param>
/// <param name="alpha">alpha (transparency) of color (0-255)</param>
public Color(float hue, float saturation, float brightness, byte alpha = 255)
{
HslToRgb(hue * 360, saturation, brightness, out float red, out float green, out float blue);
Expand All @@ -163,7 +163,7 @@ public Color(float hue, float saturation, float brightness, byte alpha = 255)
/// <summary>
/// Create a new color struct from current color with new brightness
/// </summary>
/// <param name="brightness">brightness of new color (0-1.0)</param>
/// <param name="brightness">brightness of new color (0-1)</param>
/// <returns>new color object</returns>
public Color WithBrightness(float brightness)
{
Expand All @@ -173,7 +173,7 @@ public Color WithBrightness(float brightness)
/// <summary>
/// Create a new color struct from current color with new hue
/// </summary>
/// <param name="hue">hue of new color (0-360.0)</param>
/// <param name="hue">hue of new color (0-360)</param>
/// <returns>new color object</returns>
public Color WithHue(float hue)
{
Expand All @@ -183,7 +183,7 @@ public Color WithHue(float hue)
/// <summary>
/// Create a new color structs from current color with new saturation
/// </summary>
/// <param name="saturation">saturation of new color (0-1.0)</param>
/// <param name="saturation">saturation of new color (0-1)</param>
/// <returns>new color object</returns>
public Color WithSaturation(float saturation)
{
Expand Down Expand Up @@ -449,14 +449,14 @@ public static Color FromRgb(float r, float g, float b)
/// <returns>new color object</returns>
public static Color FromHsba(float h, float s, float b, float a = 1.0f)
{
return new Color(h, s, b, (byte)(a * 255));
return new Color(h / 360f, s, b, (byte)(a * 255));
}

/// <summary>
/// Takes Hue, Saturation and Value and returns a Color object
/// </summary>
/// <param name="alpha"></param>
/// <param name="hue"></param>
/// <param name="alpha">alpha of color (0-1)</param>
/// <param name="hue">hue of color (0-360)</param>
/// <param name="saturation"></param>
/// <param name="value"></param>
/// <returns>A Color object</returns>
Expand All @@ -470,7 +470,7 @@ public static Color FromAhsv(float alpha, float hue, float saturation, float val
/// <summary>
/// HSL to RGB
/// </summary>
/// <param name="hue">Hue in degrees (0-359°)</param>
/// <param name="hue">Hue in degrees (0-360)</param>
/// <param name="saturation">Saturation</param>
/// <param name="lightness">Brightness value</param>
/// <param name="r">The red component (0-1)</param>
Expand Down Expand Up @@ -557,9 +557,9 @@ public static void HslToRgb(float hue, float saturation, float lightness, out fl
/// <summary>
/// HSV to RGB
/// </summary>
/// <param name="hue">Hue in degrees (0-359°)</param>
/// <param name="saturation">Saturation</param>
/// <param name="brightValue">Brightness value</param>
/// <param name="hue">Hue in degrees (0-360)</param>
/// <param name="saturation">Saturation (0-1)</param>
/// <param name="brightValue">Brightness (0-1)</param>
/// <param name="r">The red component (0-1)</param>
/// <param name="g">The green component (0-1)</param>
/// <param name="b">The blue component (0-1)</param>
Expand Down

0 comments on commit 6c39a14

Please sign in to comment.