Repository: microsoft/terminal
File: src/cascadia/TerminalCore/ColorFix.cpp (C++)

Code before:

    // R sub T
    const double rSubT = -2 * sqrt(pow(cBarPrime, 7) / (pow(cBarPrime, 7) + pow(25.0, 7))) * sin(rad060 * exp(-pow((hBarPrime - rad275) / rad025, 2)));

    // Put it all together!
    const double lightness = deltaLPrime / (kSubL * sSubL);
    const double chroma = deltaCPrime / (kSubC * sSubC);
    const double hue = deltaHPrime / (kSubH * sSubH);

    return sqrt(pow(lightness, 2) + pow(chroma, 2) + pow(hue, 2) + rSubT * chroma * hue);
}

// Method Description:
// - Populates our L, A, B values, based on our r, g, b values
// - Converts a color in rgb format to a color in lab format
// - Reference: http://www.easyrgb.com/index.php?X=MATH&H=01#text1
void ColorFix::_ToLab()
{
    double var_R = r / 255.0;
    double var_G = g / 255.0;
    double var_B = b / 255.0;

    if (var_R > 0.04045)
        var_R = pow(((var_R + 0.055) / 1.055), 2.4);
    else
        var_R = var_R / 12.92;
    if (var_G > 0.04045)
        var_G = pow(((var_G + 0.055) / 1.055), 2.4);
    else
        var_G = var_G / 12.92;
    if (var_B > 0.04045)
        var_B = pow(((var_B + 0.055) / 1.055), 2.4);
    else
        var_B = var_B / 12.92;

    var_R = var_R * 100.;
    var_G = var_G * 100.;
    var_B = var_B * 100.;

    //Observer. = 2 degrees, Illuminant = D65
    double X = var_R * 0.4124 + var_G * 0.3576 + var_B * 0.1805;
    double Y = var_R * 0.2126 + var_G * 0.7152 + var_B * 0.0722;
    double Z = var_R * 0.0193 + var_G * 0.1192 + var_B * 0.9505;

    double var_X = X / 95.047; //ref_X =  95.047   (Observer= 2 degrees, Illuminant= D65)
    double var_Y = Y / 100.000; //ref_Y = 100.000
    double var_Z = Z / 108.883; //ref_Z = 108.883

    if (var_X > 0.008856)
        var_X = pow(var_X, (1. / 3.));
    else

Review comment (suggestion):
```suggestion
    var_R = var_R > 0.04045 ? pow(((var_R + 0.055) / 1.055), 2.4) : var_R / 12.92;
```
You could use the ternary operator across basically all the `if-else` branches in this file.

Code after:

    // T
    const double t = 1 - 0.17 * cos(hBarPrime - rad030) + 0.24 * cos(2 * hBarPrime) + 0.32 * cos(3 * hBarPrime + rad006) - 0.20 * cos(4 * hBarPrime - rad063);

    // S sub H
    const double sSubH = 1 + 0.015 * cBarPrime * t;

    // R sub T
    const double rSubT = -2 * sqrt(pow(cBarPrime, 7) / (pow(cBarPrime, 7) + pow(25.0, 7))) * sin(rad060 * exp(-pow((hBarPrime - rad275) / rad025, 2)));

    // Put it all together!
    const double lightness = deltaLPrime / (kSubL * sSubL);
    const double chroma = deltaCPrime / (kSubC * sSubC);
    const double hue = deltaHPrime / (kSubH * sSubH);

    return sqrt(pow(lightness, 2) + pow(chroma, 2) + pow(hue, 2) + rSubT * chroma * hue);
}

// Method Description:
// - Populates our L, A, B values, based on our r, g, b values
// - Converts a color in rgb format to a color in lab format
// - Reference: http://www.easyrgb.com/index.php?X=MATH&H=01#text1
void ColorFix::_ToLab()
{
    double var_R = r / 255.0;
    double var_G = g / 255.0;
    double var_B = b / 255.0;

    var_R = var_R > 0.04045 ? pow(((var_R + 0.055) / 1.055), 2.4) : var_R / 12.92;
    var_G = var_G > 0.04045 ? pow(((var_G + 0.055) / 1.055), 2.4) : var_G / 12.92;
    var_B = var_B > 0.04045 ? pow(((var_B + 0.055) / 1.055), 2.4) : var_B / 12.92;

    var_R = var_R * 100.;
    var_G = var_G * 100.;
    var_B = var_B * 100.;

    //Observer. = 2 degrees, Illuminant = D65
    const double X = var_R * 0.4124 + var_G * 0.3576 + var_B * 0.1805;
    const double Y = var_R * 0.2126 + var_G * 0.7152 + var_B * 0.0722;
    const double Z = var_R * 0.0193 + var_G * 0.1192 + var_B * 0.9505;

    double var_X = X / 95.047; //ref_X =  95.047   (Observer= 2 degrees, Illuminant= D65)
    double var_Y = Y / 100.000; //ref_Y = 100.000
    double var_Z = Z / 108.883; //ref_Z = 108.883

    var_X = var_X > 0.008856 ? pow(var_X, (1. / 3.)) : (7.787 * var_X) + (16. / 116.);
    var_Y = var_Y > 0.008856 ? pow(var_Y, (1. / 3.)) : (7.787 * var_Y) + (16. / 116.);
    var_Z = var_Z > 0.008856 ? pow(var_Z, (1. / 3.)) : (7.787 * var_Z) + (16. / 116.);

    L = (116. * var_Y) - 16.;
    A = 500. * (var_X - var_Y);