Fix math.root frame size (#6021)

This commit is contained in:
Max 2025-03-11 10:18:15 +00:00 committed by GitHub
parent 3650859ae8
commit 96f6957371
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View File

@ -85,14 +85,15 @@ pub fn layout_root(
ascent.set_max(shift_up + index.ascent());
}
let radicand_x = sqrt_offset + sqrt.width();
let sqrt_x = sqrt_offset.max(Abs::zero());
let radicand_x = sqrt_x + sqrt.width();
let radicand_y = ascent - radicand.ascent();
let width = radicand_x + radicand.width();
let size = Size::new(width, ascent + descent);
// The extra "- thickness" comes from the fact that the sqrt is placed
// in `push_frame` with respect to its top, not its baseline.
let sqrt_pos = Point::new(sqrt_offset, radicand_y - gap - thickness);
let sqrt_pos = Point::new(sqrt_x, radicand_y - gap - thickness);
let line_pos = Point::new(radicand_x, radicand_y - gap - (thickness / 2.0));
let radicand_pos = Point::new(radicand_x, radicand_y);
@ -100,7 +101,8 @@ pub fn layout_root(
frame.set_baseline(ascent);
if let Some(index) = index {
let index_pos = Point::new(kern_before, ascent - index.ascent() - shift_up);
let index_x = -sqrt_offset.min(Abs::zero()) + kern_before;
let index_pos = Point::new(index_x, ascent - index.ascent() - shift_up);
frame.push_frame(index_pos, index);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B

View File

@ -44,3 +44,9 @@ $ root(2, x) quad
$ 2^3 = sqrt(2^3) $
$ (x+y) quad x quad x $
$ (2+3) = (sqrt(2)+3) $
--- math-root-frame-size-index ---
// Test size of final frame when there is an index.
$ a root(, 3) & a root(., 3) \
a sqrt(3) & a root(2, 3) \
a root(#h(-1em), 3) & a root(123, 3) $