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

Code before:
        let w = stroke_size as f32;

        let mut x_offset = 0.0;
        let mut y_offset = 0.0;
        let d_bias: f32;
        if self.height > self.width {
            y_offset = self.height as f32 * 0.5 - r + w * 0.5;
            if (self.width % 2 != self.height % 2) && (self.height % 2 == stroke_size % 2) {
                y_offset += 1.0;
            }
            d_bias = if self.width % 2 == stroke_size % 2 { 0.0 } else { 0.5 };
        } else {
            x_offset = self.width as f32 * 0.5 - r + w * 0.5;
            if (self.width % 2 != self.height % 2) && (self.width % 2 == stroke_size % 2) {
                x_offset += 1.0;
            }
            d_bias = if self.height % 2 == stroke_size % 2 { 0.0 } else { 0.5 };
        }

        let radius_i = (self.width.min(self.height) + stroke_size + 1) / 2;
        for y in 0..radius_i {
            for x in 0..radius_i {
                let y = y as f32;
                let x = x as f32;
                let d = (x * x + y * y).sqrt() + d_bias;
                let v = if d < r - w - 1.0 {
                    0.0
                } else if d < r - w {
                    1.0 + d - (r - w)
                } else if d < r - 1.0 {
                    1.0
                } else if d < r {
                    r - d
                } else {
                    0.0
                };
                self.put_pixel(
                    x + x_offset,
                    y + y_offset,
                    Pixel::gray((COLOR_FILL._r as f32 * v) as u8),
                );
            }
        }

        if self.height > self.width {
            self.draw_rect(self.x_center() - w * 0.5, 0.0, w, y_offset, COLOR_FILL);
        } else {
            self.draw_rect(0.0, self.y_center() - w * 0.5, x_offset, w, COLOR_FILL);
        }
    }


Review comment (suggestion):
nit: I think we generally don't write out the zero after dot.

```suggestion
                let v = if d < r - w - 1. {
```

Also, this `if else` chain can be improved by adding comments explaining a bit the logic behind it.

Code after:
        let stroke_size_f = stroke_size as f32;

        let mut x_offset = 0.;
        let mut y_offset = 0.;
        let (long_side, short_side, offset) = if self.height > self.width {
            (&self.height, &self.width, &mut y_offset)
        } else {
            (&self.width, &self.height, &mut x_offset)
        };
        let distance_bias = if short_side % 2 == stroke_size % 2 { 0. } else { 0.5 };
        *offset = *long_side as f32 / 2. - radius + stroke_size_f / 2.;
        if (self.width % 2 != self.height % 2) && (long_side % 2 == stroke_size % 2) {
            *offset += 1.;
        }

        let radius_i = (short_side + stroke_size + 1) / 2;
        for y in 0..radius_i {
            for x in 0..radius_i {
                let y = y as f32;
                let x = x as f32;
                let distance = x.hypot(y) + distance_bias;
                let value = if distance < radius - stroke_size_f - 1. {
                    // Inside the circle.
                    0.
                } else if distance < radius - stroke_size_f {
                    // On the inner border.
                    1. + distance - (radius - stroke_size_f)
                } else if distance < radius - 1. {
                    // Inside the stroke.
                    1.
                } else if distance < radius {
                    // On the outer border.
                    radius - distance
                } else {
                    // Outside of the circle.
                    0.
                };

                self.put_pixel(
                    x + x_offset,
                    y + y_offset,
                    Pixel::gray((COLOR_FILL._r as f32 * value) as u8),
                );
            }
        }

        if self.height > self.width {
            self.draw_rect(
                self.x_center() - stroke_size_f * 0.5,
                0.,
                stroke_size_f,