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

Code before:
                    self.buffer[index] + self.buffer[index - 1] / 2 + self.buffer[index + 1] / 2;
            }
        }
    }

    /// Fills the `Canvas` with the given `Color`.
    fn fill(&mut self, color: Pixel) {
        self.buffer.fill(color);
    }

    /// Consumes `Canvas` and returns its underlying storage as raw byte vector.
    fn into_raw(self) -> Vec<u8> {
        // SAFETY This is safe since we use `repr(packed)` on `Pixel` struct for underlying storage
        // of the `Canvas` buffer which consists of three u8 values.
        unsafe {
            let capacity = self.buffer.capacity() * mem::size_of::<Pixel>();
            let len = self.buffer.len() * mem::size_of::<Pixel>();
            let buf = self.buffer.as_ptr() as *mut u8;
            mem::forget(self.buffer);
            Vec::from_raw_parts(buf, len, capacity)
        }
    }
}

/// Size of the stroke to use.
fn calculate_stroke_size(width: usize) -> usize {
    // Use one eight of the cell width, since this is used as a step size for block elements.
    cmp::max((width as f32 / 8.).round() as usize, 1)
}

/// Equation for `f(x) = slope * x + offset.
struct LineEquation {
    slope: i32,
    offset: i32,
    x: i32,
    width: i32,
}

impl LineEquation {
    fn new(slope: i32, offset: i32, from_x: i32, width: i32) -> Self {
        Self { x: from_x - 1, width, slope, offset }
    }
}

impl Iterator for LineEquation {
    type Item = (f32, f32);

    fn next(&mut self) -> Option<Self::Item> {
        self.x += 1;
        if self.x >= self.width {
            None

Review comment (suggestion):
```suggestion
/// Compute line width.
fn calculate_stroke_size(cell_width: usize) -> usize {
```

My main problem here is the "to use" suffix in your docs which is confusing (to use for what?). Decided to reword it completely to provide additional value over the function name itself (synonyms are more useful to figure out purpose than using the same words again).

Code after:
                    self.buffer[index] + self.buffer[index - 1] / 2 + self.buffer[index + 1] / 2;
            }
        }
    }

    /// Fills the `Canvas` with the given `Color`.
    fn fill(&mut self, color: Pixel) {
        self.buffer.fill(color);
    }

    /// Consumes `Canvas` and returns its underlying storage as raw byte vector.
    fn into_raw(self) -> Vec<u8> {
        // SAFETY This is safe since we use `repr(packed)` on `Pixel` struct for underlying storage
        // of the `Canvas` buffer which consists of three u8 values.
        unsafe {
            let capacity = self.buffer.capacity() * mem::size_of::<Pixel>();
            let len = self.buffer.len() * mem::size_of::<Pixel>();
            let buf = self.buffer.as_ptr() as *mut u8;
            mem::forget(self.buffer);
            Vec::from_raw_parts(buf, len, capacity)
        }
    }
}

/// Compute line width.
fn calculate_stroke_size(cell_width: usize) -> usize {
    // Use one eight of the cell width, since this is used as a step size for block elements.
    cmp::max((cell_width as f32 / 8.).round() as usize, 1)
}

/// `f(x) = slope * x + offset` equation.
fn line_equation(slope: i32, x: i32, offset: i32) -> (f32, f32) {
    (x as f32, (slope * x + offset) as f32)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crossfont::Metrics;

    // Dummy metrics values to test builtin glyphs coverage.
    const METRICS: Metrics = Metrics {
        average_advance: 6.,
        line_height: 16.,
        descent: 4.,
        underline_position: 2.,
        underline_thickness: 2.,
        strikeout_position: 2.,
        strikeout_thickness: 2.,
    };