Repository: alacritty/alacritty
File: alacritty/src/renderer/text/builtin_font.rs (Rust)

Code before:
    let buffer = BitmapBuffer::Rgb(canvas.into_raw());
    RasterizedGlyph {
        character,
        top,
        left: 0,
        height: height as i32,
        width: width as i32,
        buffer,
        advance: (width as i32, height as i32),
    }
}

fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> RasterizedGlyph {
    let height = (metrics.line_height as i32 + offset.y as i32) as usize;
    let width = (metrics.average_advance as i32 + offset.x as i32) as usize;
    let extra_thickness = calculate_stroke_size(width) as i32 - 1;

    let mut canvas = Canvas::new(width, height);

    let slope = 1;
    let f_y0 = 1;
    let g_y0 = height as i32 - f_y0 - 1;

    // Start with offset `1` and draw until the intersection of the f(x) = x + 1 and
    // g(x) = H - x - 1 lines. The intersection happens when f(x) = g(x), which is at
    // x = H/2 - 1.
    let intersection = (height as i32 + 1) / 2 - 1;

    let f_x = LineEquation::new(slope, f_y0, 0, intersection);
    let g_x = LineEquation::new(-slope, g_y0, 0, intersection);

    // Inner functions to make arrows thicker.
    let mut f_x_inner =
        LineEquation::new(slope, f_y0 + extra_thickness, 0, intersection - extra_thickness);
    let mut g_x_inner =
        LineEquation::new(-slope, g_y0 - extra_thickness, 0, intersection - extra_thickness);

    // NOTE f_x and g_x have the same amount of iterations.
    for (p1, p2) in iter::zip(f_x, g_x) {
        if character == POWERLINE_TRIANGLE || character == POWERLINE_TRIANGLE_FLIPPED {
            canvas.draw_rect(0., p1.1, p1.0 + 1., 1., COLOR_FILL);
            canvas.draw_rect(0., p2.1, p2.0 + 1., 1., COLOR_FILL);
        } else if character == POWERLINE_ARROW || character == POWERLINE_ARROW_FLIPPED {
            let p3 = f_x_inner.next().unwrap_or(p2);
            let p4 = g_x_inner.next().unwrap_or(p1);

            // Once we reach the canvas end fill the area between f(x) and g(x) to make a proper
            // cut.
            if p1.0 as usize + 1 == width {
                canvas.draw_rect(p1.0, p1.1, 1., p2.1 - p1.1 + 1., COLOR_FILL);
                break;

Review comment (suggestion):
I mean the intersection is always at height / 2, isn't it? This comment seems pointlessly complex for that.

Our height offset of 1 at the top and bottom is irrelevant since it applies to both the top and the bottom, thus not changing the center point.

Unless you're talking about the X position of the intersection, which I'd assume you're not here since the value ignores `slope`.

Code after:
    let buffer = BitmapBuffer::Rgb(canvas.into_raw());
    RasterizedGlyph {
        character,
        top,
        left: 0,
        height: height as i32,
        width: width as i32,
        buffer,
        advance: (width as i32, height as i32),
    }
}

fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> RasterizedGlyph {
    let height = (metrics.line_height as i32 + offset.y as i32) as usize;
    let width = (metrics.average_advance as i32 + offset.x as i32) as usize;
    let extra_thickness = calculate_stroke_size(width) as i32 - 1;

    let mut canvas = Canvas::new(width, height);

    let slope = 1;
    let top_y = 1;
    let bottom_y = height as i32 - top_y - 1;

    // Start with offset `1` and draw until the intersection of the f(x) = slope * x + 1 and
    // g(x) = H - slope * x - 1 lines. The intersection happens when f(x) = g(x), which is at
    // x = (H - 2) / (2 * slope).
    let x_intersection = (height as i32 + 1) / 2 - 1;

    let top_line = (0..x_intersection).map(|x| line_equation(slope, x, top_y));
    let bottom_line = (0..x_intersection).map(|x| line_equation(-slope, x, bottom_y));

    // Inner lines to make arrows thicker.
    let mut top_inner_line = (0..x_intersection - extra_thickness)
        .map(|x| line_equation(slope, x, top_y + extra_thickness));
    let mut bottom_inner_line = (0..x_intersection - extra_thickness)
        .map(|x| line_equation(-slope, x, bottom_y - extra_thickness));

    // NOTE: top_line and bottom_line have the same amount of iterations.
    for (p1, p2) in top_line.zip(bottom_line) {
        if character == POWERLINE_TRIANGLE_LTR || character == POWERLINE_TRIANGLE_RTL {
            canvas.draw_rect(0., p1.1, p1.0 + 1., 1., COLOR_FILL);
            canvas.draw_rect(0., p2.1, p2.0 + 1., 1., COLOR_FILL);
        } else if character == POWERLINE_ARROW_LTR || character == POWERLINE_ARROW_RTL {
            let p3 = top_inner_line.next().unwrap_or(p2);
            let p4 = bottom_inner_line.next().unwrap_or(p1);

            // If we can't fit the entire arrow in the cell, we cut off the tip of the arrow by
            // drawing a rectangle between the two lines.
            if p1.0 as usize + 1 == width {
                canvas.draw_rect(p1.0, p1.1, 1., p2.1 - p1.1 + 1., COLOR_FILL);
                break;