<commit_before>//
// Color.h
//
#ifndef __COLOR_H_
#define __COLOR_H_

#include "math.h"

typedef int COLOR_INT;

struct Color
{
    static const COLOR_INT BLACK       = 0xFF000000;
    static const COLOR_INT DKGRAY      = 0xFF444444;
    static const COLOR_INT GRAY        = 0xFF888888;
    static const COLOR_INT LTGRAY      = 0xFFCCCCCC;
    static const COLOR_INT WHITE       = 0xFFFFFFFF;
    static const COLOR_INT RED         = 0xFFFF0000;
    static const COLOR_INT GREEN       = 0xFF00FF00;
    static const COLOR_INT BLUE        = 0xFF0000FF;
    static const COLOR_INT YELLOW      = 0xFFFFFF00;
    static const COLOR_INT CYAN        = 0xFF00FFFF;
    static const COLOR_INT MAGENTA     = 0xFFFF00FF;
    static const COLOR_INT TRANSPARENT = 0;

    static int alpha(COLOR_INT color)
    {
        return (color >> 24) & 0xFF;
    }
    static int red(COLOR_INT color)
    {
        return (color >> 16) & 0xFF;
    }
    static int green(COLOR_INT color)
    {
        return (color >> 8) & 0xFF;
    }
    static int blue(COLOR_INT color)
    {
        return (color >> 0) & 0xFF;
    }


    static COLOR_INT rgb(int red, int green, int blue)
    {
        return argb(0xFF, red, green, blue);
    }
    static COLOR_INT argb(int alpha, int red, int green, int blue)
    {
        return (clip(alpha) << 24) | (clip(red) << 16) | (clip(green) << 8) | clip(blue);
    }

    static COLOR_INT rgb(float red, float green, float blue)
    {
        return argb(1.0f, red, green, blue);
    }
    static COLOR_INT argb(float alpha, float red, float green, float blue)
    {
        return argb(asByte(alpha), asByte(red), asByte(green), asByte(blue));
    }

    static COLOR_INT temperature(float kelvin)
    {
        return rgb(blackBodyRed(kelvin), blackBodyGreen(kelvin), blackBodyBlue(kelvin));
    }

protected:

    static int clip(int b)
    {
        return min(255, max(0, b));
    }
    static int asByte(float f)
    {
        // [0-1) should clearly be [0-255)
        // Additionally, we assign the pesky 1.0f ALSO to 255
        return clip(int(f * 256.0f));
    }

    //----------------------------------------------------------------------------------------------
    // Color Wheel
    //----------------------------------------------------------------------------------------------

public:

    static inline COLOR_INT wheelTri(float f)
    {
        return wheel<triUp, triDown>(f);
    }

    static inline COLOR_INT wheelSin(float f)
    {
        return wheel<sinUp, sinDown>(f);
    }

protected:

    typedef float (*PFN)(float);

    // For a given (fractional) angle around the color wheel, returns
    // the color associated therewith. Red is at 0 (and 1); green is
    // at 1/3, and blue is at 2/3.
    template <PFN pfnUp, PFN pfnDown>
    static COLOR_INT wheel(float f)
    {
        const float oneThird = 1.f / 3.f;
        const float twoThirds = 2.f / 3.f;
        const float threeHalves = 1.5f;

        // Red appears less intense; we can compensate
        const float redScale = 1.0f;
        const float greenScale = 1.0f;
        const float blueScale = 1.0f;

        f -= floorf(f); // remove integer part

        if (f <= oneThird)
        {
            return Color::rgb(
                scalePfn<pfnDown>((f + oneThird) * threeHalves, redScale),
                scalePfn<pfnUp>(f * threeHalves, greenScale),
                0);
        }
        else if (f <= twoThirds)
        {
            return Color::rgb(
                0,
                scalePfn<pfnDown>(f * threeHalves, greenScale),
                scalePfn<pfnUp>((f-oneThird) * threeHalves, blueScale));
        }
        else
        {
            return Color::rgb(
                scalePfn<pfnUp>((f - twoThirds) * threeHalves, redScale),
                0,
                scalePfn<pfnDown>((f-oneThird) * threeHalves, blueScale));
        }
    }

    inline static float triUp(float f)
    {
        return f + f;
    }
    inline static float triDown(float f)
    {
        float result = (1 - f);
        return result + result;
    }

    inline static float sinUp(float f)
    {
        float result = sinf(f * PiF);
        return result * result;
    }
    inline static float sinDown(float f)
    {
        return sinUp(f);
    }

    template <PFN pfn>
    inline static byte scalePfn(float f, float scale)
    {
        return asByte(scale * pfn(f));
    }

    //----------------------------------------------------------------------------------------------
    // Black body radiation
    //----------------------------------------------------------------------------------------------

    static float blackBodyRed(float kelvin)
    {
        const float r0 = 6500;
        if (kelvin <= r0)
        {
            return 1;
        }
        else
        {
            kelvin -= r0;
            const float a = 1.0018;
            const float b = -0.000191353;
            const float c = 2.27577e-8;
            const float d = 0;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
    }

    static float blackBodyGreen(float kelvin)
    {
        const float g0 = 1000;
        const float g2 = 6600;
        if (kelvin <= g2)
        {
            kelvin -= g0;
            const float a = 0.0374249;
            const float b = 0.00022693;
            const float c = -7.10085e-9;
            const float d = -7.87308e-13;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
        else
        {
            kelvin -= g2;
            const float a = 0.945357;
            const float b = -0.000121171;
            const float c = 2.21965e-8;
            const float d = -2.03433e-12;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
    }

    static float blackBodyBlue(float kelvin)
    {
        const float b1 = 1900;
        const float b2 = 6600;
        if (kelvin <= b1)
        {
            return 0;
        }
        else if (kelvin <= b2)
        {
            kelvin -= b1;
            const float a = -0.0058959;
            const float b = 0.0000885465;
            const float c = 5.48613e-8;
            const float d = -5.96726e-12;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
        else
        {
            return 1;
        }
    }

};

#endif
<commit_msg>tidy color<commit_after>//
// Color.h
//
#ifndef __COLOR_H_
#define __COLOR_H_

#include "math.h"

typedef int COLOR_INT;

struct Color
{
    //----------------------------------------------------------------------------------------------
    // Public function
    //----------------------------------------------------------------------------------------------

    static const COLOR_INT BLACK       = 0xFF000000;
    static const COLOR_INT DKGRAY      = 0xFF444444;
    static const COLOR_INT GRAY        = 0xFF888888;
    static const COLOR_INT LTGRAY      = 0xFFCCCCCC;
    static const COLOR_INT WHITE       = 0xFFFFFFFF;
    static const COLOR_INT RED         = 0xFFFF0000;
    static const COLOR_INT GREEN       = 0xFF00FF00;
    static const COLOR_INT BLUE        = 0xFF0000FF;
    static const COLOR_INT YELLOW      = 0xFFFFFF00;
    static const COLOR_INT CYAN        = 0xFF00FFFF;
    static const COLOR_INT MAGENTA     = 0xFFFF00FF;
    static const COLOR_INT TRANSPARENT = 0;

    static inline int alpha(COLOR_INT color)
    {
        return (color >> 24) & 0xFF;
    }
    static inline int red(COLOR_INT color)
    {
        return (color >> 16) & 0xFF;
    }
    static inline int green(COLOR_INT color)
    {
        return (color >> 8) & 0xFF;
    }
    static inline int blue(COLOR_INT color)
    {
        return (color >> 0) & 0xFF;
    }


    static inline COLOR_INT rgb(int red, int green, int blue)
    {
        return argb(0xFF, red, green, blue);
    }
    static COLOR_INT argb(int alpha, int red, int green, int blue)
    {
        return (clip(alpha) << 24) | (clip(red) << 16) | (clip(green) << 8) | clip(blue);
    }


    static inline COLOR_INT rgb(float red, float green, float blue)
    {
        return argb(1.0f, red, green, blue);
    }
    static COLOR_INT argb(float alpha, float red, float green, float blue)
    {
        return argb(asByte(alpha), asByte(red), asByte(green), asByte(blue));
    }


    static COLOR_INT temperature(float kelvin)
    {
        return rgb(blackBodyRed(kelvin), blackBodyGreen(kelvin), blackBodyBlue(kelvin));
    }


    static inline COLOR_INT wheelTri(float f)
    {
        return wheel<triUp, triDown>(f);
    }

    static inline COLOR_INT wheelSin(float f)
    {
        return wheel<sinUp, sinDown>(f);
    }

    //----------------------------------------------------------------------------------------------
    // Internal
    //----------------------------------------------------------------------------------------------

protected:

    typedef float (*PFN)(float);

    static int clip(int b)
    {
        return min(255, max(0, b));
    }
    static int asByte(float f)
    {
        // [0-1) should clearly be [0-255)
        // Additionally, we assign the pesky 1.0f ALSO to 255
        return clip(int(f * 256.0f));
    }

    template <PFN pfn>
    inline static byte scalePfn(float f, float scale)
    {
        return asByte(scale * pfn(f));
    }

    //----------------------------------------------------------------------------------------------
    // Color Wheel
    //----------------------------------------------------------------------------------------------

    // For a given (fractional) angle around the color wheel, returns
    // the color associated therewith. Red is at 0 (and 1); green is
    // at 1/3, and blue is at 2/3.
    template <PFN pfnUp, PFN pfnDown>
    static COLOR_INT wheel(float f)
    {
        const float oneThird = 1.f / 3.f;
        const float twoThirds = 2.f / 3.f;
        const float threeHalves = 1.5f;

        // Red appears less intense; we can compensate
        const float redScale = 1.0f;
        const float greenScale = 1.0f;
        const float blueScale = 1.0f;

        f -= floorf(f); // remove integer part

        if (f <= oneThird)
        {
            return Color::rgb(
                scalePfn<pfnDown>((f + oneThird) * threeHalves, redScale),
                scalePfn<pfnUp>(f * threeHalves, greenScale),
                0);
        }
        else if (f <= twoThirds)
        {
            return Color::rgb(
                0,
                scalePfn<pfnDown>(f * threeHalves, greenScale),
                scalePfn<pfnUp>((f-oneThird) * threeHalves, blueScale));
        }
        else
        {
            return Color::rgb(
                scalePfn<pfnUp>((f - twoThirds) * threeHalves, redScale),
                0,
                scalePfn<pfnDown>((f-oneThird) * threeHalves, blueScale));
        }
    }

    inline static float triUp(float f)
    {
        return f + f;
    }
    inline static float triDown(float f)
    {
        float result = (1 - f);
        return result + result;
    }

    inline static float sinUp(float f)
    {
        float result = sinf(f * PiF);
        return result * result;
    }
    inline static float sinDown(float f)
    {
        return sinUp(f);
    }

    //----------------------------------------------------------------------------------------------
    // Black body radiation
    //----------------------------------------------------------------------------------------------

    static float blackBodyRed(float kelvin)
    {
        const float r0 = 6500;
        if (kelvin <= r0)
        {
            return 1;
        }
        else
        {
            kelvin -= r0;
            const float a = 1.0018;
            const float b = -0.000191353;
            const float c = 2.27577e-8;
            const float d = 0;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
    }

    static float blackBodyGreen(float kelvin)
    {
        const float g0 = 1000;
        const float g2 = 6600;
        if (kelvin <= g2)
        {
            kelvin -= g0;
            const float a = 0.0374249;
            const float b = 0.00022693;
            const float c = -7.10085e-9;
            const float d = -7.87308e-13;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
        else
        {
            kelvin -= g2;
            const float a = 0.945357;
            const float b = -0.000121171;
            const float c = 2.21965e-8;
            const float d = -2.03433e-12;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
    }

    static float blackBodyBlue(float kelvin)
    {
        const float b1 = 1900;
        const float b2 = 6600;
        if (kelvin <= b1)
        {
            return 0;
        }
        else if (kelvin <= b2)
        {
            kelvin -= b1;
            const float a = -0.0058959;
            const float b = 0.0000885465;
            const float c = 5.48613e-8;
            const float d = -5.96726e-12;
            return ((((d * kelvin) + c) * kelvin) + b) * kelvin + a;
        }
        else
        {
            return 1;
        }
    }

};

#endif

{'fraction_non_alphanumeric': 0.18156975861545468, 'fraction_numerical': 0.04007894337331107, 'mean_word_length': 1.2707687004481214, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '3693648', 'n_tokens_mistral': 4387, 'n_tokens_neox': 3959, 'n_words': 1112}