Repository: microsoft/terminal
File: src/renderer/gdi/state.cpp (C++)

Code before:
    auto doubleUnderlinePosBottom = underlineOffset + underlineWidth - thinLineWidth;
    // 3. Since we don't align the center of our two lines, but rather the top borders
    //    we need to subtract half a line width from our center point.
    auto doubleUnderlinePosTop = std::roundf((baseline + doubleUnderlinePosBottom - thinLineWidth) / 2.0f);
    // 4.
    doubleUnderlinePosTop = std::max(doubleUnderlinePosTop, baseline + thinLineWidth);
    // 5. The gap is only the distance _between_ the lines, but we need the distance from the
    //    top border of the top and bottom lines, which includes an additional line width.
    const auto doubleUnderlineGap = std::max(1.0f, std::roundf(1.2f / 72.0f * _iCurrentDpi));
    doubleUnderlinePosBottom = std::max(doubleUnderlinePosBottom, doubleUnderlinePosTop + doubleUnderlineGap + thinLineWidth);
    // Our cells can't overlap each other so we additionally clamp the bottom line to be inside the cell boundaries.
    doubleUnderlinePosBottom = std::min(doubleUnderlinePosBottom, cellHeight - thinLineWidth);

    // The wave line is drawn using a cubic Bézier curve (PolyBezier), because that happens to be cheap with GDI.
    // We use a Bézier curve where, if the start (a) and end (c) points are at (0,0) and (1,0), the control points are
    // at (0.5,0.5) (b) and (0.5,-0.5) (d) respectively. Like this but a/b/c/d are square and the lines are round:
    //
    //       b
    //
    //     ^
    //    / \                here's some text so the compiler ignores the trailing \ character
    //   a   \   c
    //        \ /
    //         v
    //
    //       c
    //
    // If you punch x=0.25 into the cubic bezier formula you get y=0.140625. This constant is
    // important to us because it (plus the line width) tells us the amplitude of the wave.
    //
    // We can use the inverse of the constant to figure out how many px one period of the wave has to be to end up being 1px tall.
    // In our case we want the amplitude of the wave to have a peak-to-peak amplitude that matches our double-underline.
    const auto doubleUnderlineHalfDistance = 0.5f * (doubleUnderlinePosBottom - doubleUnderlinePosTop);
    const auto doubleUnderlineCenter = doubleUnderlinePosTop + doubleUnderlineHalfDistance;
    const auto curlyLineIdealAmplitude = std::max(1.0f, doubleUnderlineHalfDistance);
    // Since GDI can't deal with fractional pixels, we first calculate the control point offsets (0.5 and -0.5) by multiplying by 0.5 and
    // then undo that by multiplying by 2.0 for the period. This ensures that our control points can be at curlyLinePeriod/2, an integer.
    const auto curlyLineControlPointOffset = roundf(curlyLineIdealAmplitude * (1.0f / 0.140625f) * 0.5f);
    const auto curlyLinePeriod = curlyLineControlPointOffset * 2.0f;
    // We can reverse the above to get back the actual amplitude of our Bézier curve. The line
    // will be drawn with a width of thinLineWidth in the center of the curve (= 0.5x padding).
    const auto curlyLineAmplitude = 0.140625f * curlyLinePeriod + 0.5f * thinLineWidth;
    // To make the wavy line with its double-underline amplitude look consistent with the double-underline we position it at its center.
    const auto curlyLineOffset = std::min(roundf(doubleUnderlineCenter), floorf(cellHeight - curlyLineAmplitude));

    _lineMetrics.gridlineWidth = lroundf(idealGridlineWidth);
    _lineMetrics.thinLineWidth = lroundf(thinLineWidth);
    _lineMetrics.underlineOffset = lroundf(underlineOffset);
    _lineMetrics.underlineWidth = lroundf(underlineWidth);
    _lineMetrics.doubleUnderlinePosTop = lroundf(doubleUnderlinePosTop);
    _lineMetrics.doubleUnderlinePosBottom = lroundf(doubleUnderlinePosBottom);

Review comment (suggestion):
i assume this should be 
```suggestion
    //   a   \   d
```

because line R413 has `c` on it

Code after:

    // 1.
    const auto thinLineWidth = std::max(1.0f, roundf(idealUnderlineWidth / 2.0f));
    // 2.
    auto doubleUnderlinePosBottom = underlineCenter + underlineWidth - thinLineWidth;
    // 3. Since we don't align the center of our two lines, but rather the top borders
    //    we need to subtract half a line width from our center point.
    auto doubleUnderlinePosTop = roundf((baseline + doubleUnderlinePosBottom - thinLineWidth) / 2.0f);
    // 4.
    doubleUnderlinePosTop = std::max(doubleUnderlinePosTop, baseline + thinLineWidth);
    // 5. The gap is only the distance _between_ the lines, but we need the distance from the
    //    top border of the top and bottom lines, which includes an additional line width.
    const auto doubleUnderlineGap = std::max(1.0f, roundf(1.2f / 72.0f * _iCurrentDpi));
    doubleUnderlinePosBottom = std::max(doubleUnderlinePosBottom, doubleUnderlinePosTop + doubleUnderlineGap + thinLineWidth);
    // Our cells can't overlap each other so we additionally clamp the bottom line to be inside the cell boundaries.
    doubleUnderlinePosBottom = std::min(doubleUnderlinePosBottom, cellHeight - thinLineWidth);

    // The wave line is drawn using a cubic Bézier curve (PolyBezier), because that happens to be cheap with GDI.
    // We use a Bézier curve where, if the start (a) and end (c) points are at (0,0) and (1,0), the control points are
    // at (0.5,0.5) (b) and (0.5,-0.5) (d) respectively. Like this but a/b/c/d are square and the lines are round:
    //
    //       b
    //
    //     ^
    //    / \                here's some text so the compiler ignores the trailing \ character
    //   a   \   c
    //        \ /
    //         v
    //
    //       d
    //
    // If you punch x=0.25 into the cubic bezier formula you get y=0.140625. This constant is
    // important to us because it (plus the line width) tells us the amplitude of the wave.
    //
    // We can use the inverse of the constant to figure out how many px one period of the wave has to be to end up being 1px tall.
    // In our case we want the amplitude of the wave to have a peak-to-peak amplitude that matches our double-underline.
    const auto doubleUnderlineHalfDistance = 0.5f * (doubleUnderlinePosBottom - doubleUnderlinePosTop);
    const auto doubleUnderlineCenter = doubleUnderlinePosTop + doubleUnderlineHalfDistance;
    const auto curlyLineIdealAmplitude = std::max(1.0f, doubleUnderlineHalfDistance);
    // Since GDI can't deal with fractional pixels, we first calculate the control point offsets (0.5 and -0.5) by multiplying by 0.5 and
    // then undo that by multiplying by 2.0 for the period. This ensures that our control points can be at curlyLinePeriod/2, an integer.
    const auto curlyLineControlPointOffset = roundf(curlyLineIdealAmplitude * (1.0f / 0.140625f) * 0.5f);
    const auto curlyLinePeriod = curlyLineControlPointOffset * 2.0f;
    // We can reverse the above to get back the actual amplitude of our Bézier curve. The line
    // will be drawn with a width of thinLineWidth in the center of the curve (= 0.5x padding).
    const auto curlyLineAmplitude = 0.140625f * curlyLinePeriod + 0.5f * thinLineWidth;
    // To make the wavy line with its double-underline amplitude look consistent with the double-underline we position it at its center.
    const auto curlyLineOffset = std::min(roundf(doubleUnderlineCenter), floorf(cellHeight - curlyLineAmplitude));

    _lineMetrics.gridlineWidth = lroundf(idealGridlineWidth);
    _lineMetrics.thinLineWidth = lroundf(thinLineWidth);