Repository: typst/typst
File: crates/typst/src/math/row.rs (Rust)

Code before:
    ) -> MathRowFrameBuilder {
        let rows: Vec<_> = self.rows();
        let row_count = rows.len();
        let alignments = alignments(&rows);

        let leading = if EquationElem::size_in(styles) >= MathSize::Text {
            ParElem::leading_in(styles)
        } else {
            let font_size = scaled_font_size(ctx, styles);
            TIGHT_LEADING.at(font_size)
        };

        let mut frames: Vec<(Frame, Point)> = vec![];
        let mut size = Size::zero();
        for (i, row) in rows.into_iter().enumerate() {
            if i == row_count - 1 && row.0.is_empty() {
                continue;
            }

            let sub = row.into_line_frame(&alignments.points, align);
            let sub_size = sub.size();
            if i > 0 {
                size.y += leading;
            }

            let mut pos = Point::with_y(size.y);
            if alignments.points.is_empty() {
                pos.x = align.position(alignments.width - sub_size.x);
            }
            size.x.set_max(sub.width());
            size.y += sub_size.y;
            frames.push((sub, pos));
        }

        MathRowFrameBuilder { size, frames }
    }

    /// Lay out `MathFragment`s into a one-row frame, with alignment points respected.
    pub fn into_line_frame(self, points: &[Abs], align: FixedAlignment) -> Frame {
        let ascent = self.ascent();
        let mut frame = Frame::soft(Size::new(Abs::zero(), ascent + self.descent()));
        frame.set_baseline(ascent);

        let mut next_x = {
            let mut widths = Vec::new();
            if !points.is_empty() && align != FixedAlignment::Start {
                let mut width = Abs::zero();
                for fragment in self.iter() {
                    if matches!(fragment, MathFragment::Align) {
                        widths.push(width);
                        width = Abs::zero();

Review comment (suggestion):
Is there a particular reason to change `sub.width()` to `sub_size.x`? I find the former easier to read.

Code after:
    ) -> MathRowFrameBuilder {
        let rows: Vec<_> = self.rows();
        let row_count = rows.len();
        let alignments = alignments(&rows);

        let leading = if EquationElem::size_in(styles) >= MathSize::Text {
            ParElem::leading_in(styles)
        } else {
            let font_size = scaled_font_size(ctx, styles);
            TIGHT_LEADING.at(font_size)
        };

        let mut frames: Vec<(Frame, Point)> = vec![];
        let mut size = Size::zero();
        for (i, row) in rows.into_iter().enumerate() {
            if i == row_count - 1 && row.0.is_empty() {
                continue;
            }

            let sub = row.into_line_frame(&alignments.points, align);
            if i > 0 {
                size.y += leading;
            }

            let mut pos = Point::with_y(size.y);
            if alignments.points.is_empty() {
                pos.x = align.position(alignments.width - sub.width());
            }
            size.x.set_max(sub.width());
            size.y += sub.height();
            frames.push((sub, pos));
        }

        MathRowFrameBuilder { size, frames }
    }

    /// Lay out `MathFragment`s into a one-row frame, with alignment points respected.
    pub fn into_line_frame(self, points: &[Abs], align: FixedAlignment) -> Frame {
        let ascent = self.ascent();
        let mut frame = Frame::soft(Size::new(Abs::zero(), ascent + self.descent()));
        frame.set_baseline(ascent);

        let mut next_x = {
            let mut widths = Vec::new();
            if !points.is_empty() && align != FixedAlignment::Start {
                let mut width = Abs::zero();
                for fragment in self.iter() {
                    if matches!(fragment, MathFragment::Align) {
                        widths.push(width);
                        width = Abs::zero();
                    } else {