<commit_before>﻿// Color conversion portions of this source file are adapted from the WinUI project. 
// (https://github.com/microsoft/microsoft-ui-xaml) 
// 
// Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation.

using System;
using Avalonia.Utilities;

namespace Avalonia.Media
{
    /// <summary>
    /// Defines a color using the hue/saturation/value (HSV) model.
    /// </summary>
#if !BUILDTASK
    public
#endif
    readonly struct HsvColor : IEquatable<HsvColor>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HsvColor"/> struct.
        /// </summary>
        /// <param name="hue">The Hue channel value in the range from 0..360.</param>
        /// <param name="saturation">The Saturation channel value in the range from 0..1.</param>
        /// <param name="value">The Value channel value in the range from 0..1.</param>
        public HsvColor(
            double hue,
            double saturation,
            double value)
        {
            A = 1.0;
            H = MathUtilities.Clamp((double.IsNaN(hue) ? 0 : hue), 0, 360);
            S = MathUtilities.Clamp((double.IsNaN(saturation) ? 0 : saturation), 0, 1);
            V = MathUtilities.Clamp((double.IsNaN(value) ? 0 : value), 0, 1);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HsvColor"/> struct.
        /// </summary>
        /// <param name="hue">The Hue channel value in the range from 0..360.</param>
        /// <param name="saturation">The Saturation channel value in the range from 0..1.</param>
        /// <param name="value">The Value channel value in the range from 0..1.</param>
        /// <param name="alpha">The Alpha (transparency) channel value in the range from 0..1.</param>
        public HsvColor(
            double hue,
            double saturation,
            double value,
            double alpha)
        {
            A = MathUtilities.Clamp((double.IsNaN(alpha) ? 1 : alpha), 0, 1); // Default to no transparency
            H = MathUtilities.Clamp((double.IsNaN(hue) ? 0 : hue), 0, 360);
            S = MathUtilities.Clamp((double.IsNaN(saturation) ? 0 : saturation), 0, 1);
            V = MathUtilities.Clamp((double.IsNaN(value) ? 0 : value), 0, 1);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HsvColor"/> struct.
        /// </summary>
        /// <param name="color">The RGB color to convert to HSV.</param>
        public HsvColor(Color color)
        {
            var hsv = HsvColor.FromRgb(color);

            A = hsv.A;
            H = hsv.H;
            S = hsv.S;
            V = hsv.V;
        }

        /// <summary>
        /// Gets the Alpha (transparency) channel value in the range from 0..1.
        /// </summary>
        public double A { get; }

        /// <summary>
        /// Gets the Hue channel value in the range from 0..360.
        /// </summary>
        public double H { get; }<commit_msg>Make alpha the first parameter in the constructor matching Color<commit_after>﻿// Color conversion portions of this source file are adapted from the WinUI project. 
// (https://github.com/microsoft/microsoft-ui-xaml) 
// 
// Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation.

using System;
using Avalonia.Utilities;

namespace Avalonia.Media
{
    /// <summary>
    /// Defines a color using the hue/saturation/value (HSV) model.
    /// </summary>
#if !BUILDTASK
    public
#endif
    readonly struct HsvColor : IEquatable<HsvColor>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HsvColor"/> struct.
        /// </summary>
        /// <param name="hue">The Hue channel value in the range from 0..360.</param>
        /// <param name="saturation">The Saturation channel value in the range from 0..1.</param>
        /// <param name="value">The Value channel value in the range from 0..1.</param>
        public HsvColor(
            double hue,
            double saturation,
            double value)
        {
            A = 1.0;
            H = MathUtilities.Clamp((double.IsNaN(hue) ? 0 : hue), 0, 360);
            S = MathUtilities.Clamp((double.IsNaN(saturation) ? 0 : saturation), 0, 1);
            V = MathUtilities.Clamp((double.IsNaN(value) ? 0 : value), 0, 1);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HsvColor"/> struct.
        /// </summary>
        /// <param name="alpha">The Alpha (transparency) channel value in the range from 0..1.</param>
        /// <param name="hue">The Hue channel value in the range from 0..360.</param>
        /// <param name="saturation">The Saturation channel value in the range from 0..1.</param>
        /// <param name="value">The Value channel value in the range from 0..1.</param>
        public HsvColor(
            double alpha,
            double hue,
            double saturation,
            double value)
        {
            A = MathUtilities.Clamp((double.IsNaN(alpha) ? 1 : alpha), 0, 1); // Default to no transparency
            H = MathUtilities.Clamp((double.IsNaN(hue) ? 0 : hue), 0, 360);
            S = MathUtilities.Clamp((double.IsNaN(saturation) ? 0 : saturation), 0, 1);
            V = MathUtilities.Clamp((double.IsNaN(value) ? 0 : value), 0, 1);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HsvColor"/> struct.
        /// </summary>
        /// <param name="color">The RGB color to convert to HSV.</param>
        public HsvColor(Color color)
        {
            var hsv = HsvColor.FromRgb(color);

            A = hsv.A;
            H = hsv.H;
            S = hsv.S;
            V = hsv.V;
        }

        /// <summary>
        /// Gets the Alpha (transparency) channel value in the range from 0..1.
        /// </summary>
        public double A { get; }

        /// <summary>
        /// Gets the Hue channel value in the range from 0..360.
        /// </summary>
        public double H { get; }
{'fraction_non_alphanumeric': 0.13575557390586293, 'fraction_numerical': 0.016845582163501238, 'mean_word_length': 1.8352059925093633, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '510912', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1729, 'n_words': 563}