summaryrefslogtreecommitdiff
path: root/library/src/math/align.rs
diff options
context:
space:
mode:
authorAlex Saveau <saveau.alexandre@gmail.com>2023-04-24 02:16:13 -0700
committerGitHub <noreply@github.com>2023-04-24 11:16:13 +0200
commitbc802bd8fb1656e5004b7c1b8a4e02ec7fc31aa8 (patch)
treef299db167684d0c553b1dd132b92a3ea348617ba /library/src/math/align.rs
parent5ccc6876194a3f9329021bf22e7c8d0ed6bf74a1 (diff)
Fix broken matrices with alignment and optimize code while we're at it (#935)
Diffstat (limited to 'library/src/math/align.rs')
-rw-r--r--library/src/math/align.rs15
1 files changed, 13 insertions, 2 deletions
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<Abs>,
+ pub width: Abs,
+}
+
/// Determine the position of the alignment points.
-pub(super) fn alignments(rows: &[MathRow]) -> Vec<Abs> {
+pub(super) fn alignments(rows: &[MathRow]) -> AlignmentResult {
let mut widths = Vec::<Abs>::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<Abs> {
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<Abs> {
width += fragment.width();
}
}
+ pending_width.set_max(width);
}
let mut points = widths;
@@ -42,5 +50,8 @@ pub(super) fn alignments(rows: &[MathRow]) -> Vec<Abs> {
let prev = points[i - 1];
points[i] += prev;
}
- points
+ AlignmentResult {
+ width: points.last().copied().unwrap_or_default() + pending_width,
+ points,
+ }
}