From bc802bd8fb1656e5004b7c1b8a4e02ec7fc31aa8 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Mon, 24 Apr 2023 02:16:13 -0700 Subject: Fix broken matrices with alignment and optimize code while we're at it (#935) --- library/src/math/align.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'library/src/math/align.rs') diff --git a/library/src/math/align.rs b/library/src/math/align.rs index bbdda5fd..4e4a76e9 100644 --- a/library/src/math/align.rs +++ b/library/src/math/align.rs @@ -15,10 +15,16 @@ impl LayoutMath for AlignPointElem { } } +pub(super) struct AlignmentResult { + pub points: Vec, + pub width: Abs, +} + /// Determine the position of the alignment points. -pub(super) fn alignments(rows: &[MathRow]) -> Vec { +pub(super) fn alignments(rows: &[MathRow]) -> AlignmentResult { let mut widths = Vec::::new(); + let mut pending_width = Abs::zero(); for row in rows { let mut width = Abs::zero(); let mut alignment_index = 0; @@ -28,6 +34,7 @@ pub(super) fn alignments(rows: &[MathRow]) -> Vec { widths[alignment_index].set_max(width); } else { widths.push(width); + pending_width = Abs::zero(); } width = Abs::zero(); alignment_index += 1; @@ -35,6 +42,7 @@ pub(super) fn alignments(rows: &[MathRow]) -> Vec { width += fragment.width(); } } + pending_width.set_max(width); } let mut points = widths; @@ -42,5 +50,8 @@ pub(super) fn alignments(rows: &[MathRow]) -> Vec { let prev = points[i - 1]; points[i] += prev; } - points + AlignmentResult { + width: points.last().copied().unwrap_or_default() + pending_width, + points, + } } -- cgit v1.2.3