<commit_before>﻿#region Using

using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.InteropServices;

#endregion

namespace Emotion.Primitives
{
    /// <summary>
    /// A color.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Color
    {
        #region Constructors

        /// <summary>
        /// Creates a new instance of <see cref="Color" /> struct.
        /// </summary>
        /// <param name="color">A <see cref="Color" /> for RGB values of new <see cref="Color" /> instance.</param>
        /// <param name="a">Alpha component value.</param>
        public Color(Color color, byte a)
        {
            R = color.R;
            G = color.G;
            B = color.B;
            A = a;
        }

        /// <summary>
        /// Creates a new instance of <see cref="Color" /> struct.
        /// </summary>
        /// <param name="r">Red component value.</param>
        /// <param name="g">Green component value.</param>
        /// <param name="b">Blue component value</param>
        /// <param name="a">Alpha component value.</param>
        public Color(byte r, byte g, byte b, byte a = 255)
        {
            R = r;
            G = g;
            B = b;
            A = a;
        }

        /// <inheritdoc />
        /// <summary>
        /// Creates a new instance of <see cref="T:Emotion.Primitives.Color" /> struct.
        /// </summary>
        /// <param name="r">Red component value.</param>
        /// <param name="g">Green component value.</param>
        /// <param name="b">Blue component value</param>
        /// <param name="a">Alpha component value.</param>
        public Color(int r, int g, int b, int a = 255) : this((byte) r, (byte) g, (byte) b, (byte) a)
        {
        }

        /// <summary>
        /// Create a new instance of <see cref="Color" /> struct from an HTML hex string.
        /// </summary>
        /// <param name="htmlFormat">An HTML hex string containing the color.</param>
        public Color(string htmlFormat)
        {
            htmlFormat = htmlFormat.Replace("#", "");
            R = byte.Parse(htmlFormat.Substring(0, 2), NumberStyles.HexNumber);
            G = byte.Parse(htmlFormat.Substring(2, 2), NumberStyles.HexNumber);
            B = byte.Parse(htmlFormat.Substring(4, 2), NumberStyles.HexNumber);
            A = 255;
        }

        #endregion

        /// <summary>
        /// Gets or sets the red component.
        /// </summary>
        public byte R;

        /// <summary>
        /// Gets or sets the green component.
        /// </summary>
        public byte G;

        /// <summary>
        /// Gets or sets the blue component.
        /// </summary>
        public byte B;

        /// <summary>
        /// Gets or sets the alpha component.
        /// </summary>
        public byte A;

        /// <summary>
        /// Gets the hash code of this <see cref="Color" />.
        /// </summary>
        /// <returns>Hash code of this <see cref="Color" />.</returns>
        public override int GetHashCode()
        {
            return R ^ G ^ B ^ A;
        }

        /// <summary>
        /// Compares whether current instance is equal to specified object.
        /// </summary>
        /// <param name="obj">The <see cref="Color" /> to compare.</param>
        /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
        public override bool Equals(object obj)
        {
            return obj is Color color && Equals(color);
        }

        /// <summary>
        /// Compares whether current instance is equal to specified object.
        /// </summary>
        /// <param name="color">The <see cref="Color" /> to compare.</param>
        /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
        public bool Equals(Color color)
        {
            return color.R == R && color.G == G && color.B == B && color.A == A;
        }

        #region Functions

        ///// <summary>
        ///// Performs linear interpolation of <see cref="Color" />.
        ///// </summary>
        ///// <param name="value1">Source <see cref="Color" />.</param>
        ///// <param name="value2">Destination <see cref="Color" />.</param>
        ///// <param name="amount">Interpolation factor.</param>
        ///// <returns>Interpolated <see cref="Color" />.</returns>
        //public static Color Lerp(Color value1, Color value2, float amount)
        //{
        //    amount = MathExtension.Clamp(amount, 0, 1);
        //    return new Color(
        //        (byte) MathExtension.Lerp(value1.R, value2.R, amount),
        //        (byte) MathExtension.Lerp(value1.G, value2.G, amount),
        //        (byte) MathExtension.Lerp(value1.B, value2.B, amount),
        //        (byte) MathExtension.Lerp(value1.A, value2.A, amount));
        //}

        /// <summary>
        /// Multiply <see cref="Color" /> by value.
        /// </summary>
        /// <param name="value">Source <see cref="Color" />.</param>
        /// <param name="scale">Multiplicator.</param>
        /// <returns>Multiplication result.</returns>
        public static Color Multiply(Color value, float scale)
        {
            return new Color((byte) (value.R * scale), (byte) (value.G * scale), (byte) (value.B * scale), (byte) (value.A * scale));
        }


        /// <summary>
        /// Translate a non-premultipled alpha <see cref="Color" /> to a <see cref="Color" /> that contains premultiplied alpha.
        /// </summary>
        /// <param name="r">Red component value.</param>
        /// <param name="g">Green component value.</param>
        /// <param name="b">Blue component value.</param>
        /// <param name="a">Alpha component value.</param>
        /// <returns>A <see cref="Color" /> which contains premultiplied alpha data.</returns>
        public static Color FromNonPremultiplied(int r, int g, int b, int a)
        {
            return new Color((byte) (r * a / 255), (byte) (g * a / 255), (byte) (b * a / 255), (byte) a);
        }

        #endregion
<commit_msg>Restored Color Lerp and added a uint constructor<commit_after>﻿#region Using

using Emotion.Utility;
using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.InteropServices;

#endregion

namespace Emotion.Primitives
{
    /// <summary>
    /// A color.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct Color
    {
        #region Constructors

        /// <summary>
        /// Creates a new instance of <see cref="Color" /> struct.
        /// </summary>
        /// <param name="color">A <see cref="Color" /> for RGB values of new <see cref="Color" /> instance.</param>
        /// <param name="a">Alpha component value.</param>
        public Color(Color color, byte a)
        {
            R = color.R;
            G = color.G;
            B = color.B;
            A = a;
        }

        /// <summary>
        /// Creates a new instance of <see cref="Color" /> struct.
        /// </summary>
        /// <param name="r">Red component value.</param>
        /// <param name="g">Green component value.</param>
        /// <param name="b">Blue component value</param>
        /// <param name="a">Alpha component value.</param>
        public Color(byte r, byte g, byte b, byte a = 255)
        {
            R = r;
            G = g;
            B = b;
            A = a;
        }

        /// <inheritdoc />
        /// <summary>
        /// Creates a new instance of <see cref="T:Emotion.Primitives.Color" /> struct.
        /// </summary>
        /// <param name="r">Red component value.</param>
        /// <param name="g">Green component value.</param>
        /// <param name="b">Blue component value</param>
        /// <param name="a">Alpha component value.</param>
        public Color(int r, int g, int b, int a = 255) : this((byte) r, (byte) g, (byte) b, (byte) a)
        {
        }

        /// <summary>
        /// Create a new instance of <see cref="Color" /> struct from an HTML hex string.
        /// </summary>
        /// <param name="htmlFormat">An HTML hex string containing the color.</param>
        public Color(string htmlFormat)
        {
            htmlFormat = htmlFormat.Replace("#", "");
            R = byte.Parse(htmlFormat.Substring(0, 2), NumberStyles.HexNumber);
            G = byte.Parse(htmlFormat.Substring(2, 2), NumberStyles.HexNumber);
            B = byte.Parse(htmlFormat.Substring(4, 2), NumberStyles.HexNumber);
            A = 255;
        }

        /// <summary>
        /// Creates a new color, from a packed RGBA uint.
        /// </summary>
        /// <param name="packed">The packed uint.</param>
        public Color(uint packed)
        {
            R = (byte) (packed >> 0);
            G = (byte) (packed >> 8);
            B = (byte) (packed >> 16);
            A = (byte) (packed >> 24);
        }

        #endregion

        /// <summary>
        /// Gets or sets the red component.
        /// </summary>
        public byte R;

        /// <summary>
        /// Gets or sets the green component.
        /// </summary>
        public byte G;

        /// <summary>
        /// Gets or sets the blue component.
        /// </summary>
        public byte B;

        /// <summary>
        /// Gets or sets the alpha component.
        /// </summary>
        public byte A;

        /// <summary>
        /// Gets the hash code of this <see cref="Color" />.
        /// </summary>
        /// <returns>Hash code of this <see cref="Color" />.</returns>
        public override int GetHashCode()
        {
            return R ^ G ^ B ^ A;
        }

        /// <summary>
        /// Compares whether current instance is equal to specified object.
        /// </summary>
        /// <param name="obj">The <see cref="Color" /> to compare.</param>
        /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
        public override bool Equals(object obj)
        {
            return obj is Color color && Equals(color);
        }

        /// <summary>
        /// Compares whether current instance is equal to specified object.
        /// </summary>
        /// <param name="color">The <see cref="Color" /> to compare.</param>
        /// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
        public bool Equals(Color color)
        {
            return color.R == R && color.G == G && color.B == B && color.A == A;
        }

        #region Functions

        /// <summary>
        /// Performs linear interpolation of <see cref="Color" />.
        /// </summary>
        /// <param name="value1">Source <see cref="Color" />.</param>
        /// <param name="value2">Destination <see cref="Color" />.</param>
        /// <param name="amount">Interpolation factor.</param>
        /// <returns>Interpolated <see cref="Color" />.</returns>
        public static Color Lerp(Color value1, Color value2, float amount)
        {
            amount = Maths.Clamp(amount, 0, 1);
            return new Color(
                (byte)Maths.Lerp(value1.R, value2.R, amount),
                (byte)Maths.Lerp(value1.G, value2.G, amount),
                (byte)Maths.Lerp(value1.B, value2.B, amount),
                (byte)Maths.Lerp(value1.A, value2.A, amount));
        }

        /// <summary>
        /// Multiply <see cref="Color" /> by value.
        /// </summary>
        /// <param name="value">Source <see cref="Color" />.</param>
        /// <param name="scale">Multiplicator.</param>
        /// <returns>Multiplication result.</returns>
        public static Color Multiply(Color value, float scale)
        {
            return new Color((byte) (value.R * scale), (byte) (value.G * scale), (byte) (value.B * scale), (byte) (value.A * scale));
        }


        /// <summary>
        /// Translate a non-premultipled alpha <see cref="Color" /> to a <see cref="Color" /> that contains premultiplied alpha.
        /// </summary>
        /// <param name="r">Red component value.</param>
        /// <param name="g">Green component value.</param>
        /// <param name="b">Blue component value.</param>
        /// <param name="a">Alpha component value.</param>
        /// <returns>A <see cref="Color" /> which contains premultiplied alpha data.</returns>
        public static Color FromNonPremultiplied(int r, int g, int b, int a)
        {
            return new Color((byte) (r * a / 255), (byte) (g * a / 255), (byte) (b * a / 255), (byte) a);
        }

        #endregion

{'fraction_non_alphanumeric': 0.16350411132194814, 'fraction_numerical': 0.006483238456672992, 'mean_word_length': 1.6867034834324555, 'pattern_counts': {'":': 0, '<': 235, '<?xml version=': 0, '>': 243, 'https://': 0, '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': '6314670', 'n_tokens_mistral': 3640, 'n_tokens_neox': 3537, 'n_words': 1043}