From af161a8b831277cce82a7de4567a3c12d02aeeef Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sat, 29 Jul 2023 15:30:57 +0200 Subject: [PATCH] AK+LibWeb: Round to int in clamp_to_int instead of truncating This caused inaccuracies in float->CssPixel conversions --- AK/Math.h | 10 +- Tests/LibWeb/Layout/expected/acid1.txt | 130 +++++------ ...-inline-with-percentage-vertical-align.txt | 12 +- ...d-right-with-justified-text-in-between.txt | 216 +++++++++--------- ...at-left-and-right-with-text-in-between.txt | 76 +++--- ...max-width-for-box-with-inline-children.txt | 28 +-- ...min-width-for-box-with-inline-children.txt | 20 +- ...-box-for-definite-sizes-without-layout.txt | 24 +- Tests/LibWeb/Layout/expected/css-ex-unit.txt | 12 +- .../Layout/expected/css-font-size-calc.txt | 12 +- .../Layout/expected/css-import-rule.txt | 8 +- .../css-imported-sheet-with-media-rule.txt | 8 +- ...css-line-height-percentage-inheritance.txt | 4 +- .../expected/css-namespace-rule-matches.txt | 16 +- .../expected/css-namespace-rule-no-match.txt | 16 +- .../css-values/trigonometric-functions.txt | 12 +- Tests/LibWeb/Layout/expected/flex-auto.txt | 18 +- .../flex-column-constrained-nowrap.txt | 18 +- ...n-height-constrained-width-constrained.txt | 18 +- .../flex-column-height-constrained.txt | 18 +- ...g-auto-width-with-max-width-constraint.txt | 8 +- .../flex-container-constrained-nowrap.txt | 18 +- .../flex-container-width-constrained.txt | 18 +- Tests/LibWeb/Layout/expected/flex-grow-1.txt | 10 +- Tests/LibWeb/Layout/expected/flex-grow-2.txt | 10 +- .../LibWeb/Layout/expected/flex-shrink-1.txt | 12 +- .../LibWeb/Layout/expected/flex-shrink-2.txt | 6 +- .../Layout/expected/flex/calc-flex-basis.txt | 16 +- ...layout-dependent-containing-block-size.txt | 4 +- ...-intrinsic-aspect-ratio-and-max-height.txt | 12 +- ...ut-with-space-between-and-space-around.txt | 36 +-- .../expected/font-with-many-normal-values.txt | 16 +- ...etComputedStyle-on-unconnected-element.txt | 12 +- Tests/LibWeb/Layout/expected/grid/borders.txt | 6 +- .../Layout/expected/grid/grid-gap-2.txt | 6 +- .../grid/grid-item-fixed-paddings.txt | 20 +- .../grid/grid-item-percentage-margins.txt | 4 +- .../grid/grid-item-percentage-width.txt | 4 +- .../Layout/expected/grid/grid-span-4.txt | 24 +- .../Layout/expected/grid/image-in-grid.txt | 20 +- .../grid/track-size-calc-with-percentage.txt | 25 +- ...-of-absolute-position-box-with-padding.txt | 8 +- .../input-element-with-display-inline.txt | 24 +- .../place-content-shorthand-property.txt | 6 +- ...seudo-element-with-custom-properties-2.txt | 74 +++--- .../expected/svg-transforms-and-viewboxes.txt | 28 +-- .../svg-negative-elliptical-arg-number.txt | 4 +- .../expected/svg/svg-symbol-with-viewbox.txt | 2 +- ...-auto-max-width-table-percentage-width.txt | 12 +- ...cell-relative-to-specified-table-width.txt | 48 ++-- .../table/colspan-percentage-width.txt | 30 +-- .../table/colspan-width-distribution.txt | 34 +-- .../table/long-caption-increases-width.txt | 36 +-- .../Layout/expected/table/multi-line-cell.txt | 20 +- .../table/percentage-width-columns.txt | 24 +- .../percentage-width-max-width-columns.txt | 18 +- ...percentage-column-widths-less-than-100.txt | 24 +- ...th-distribution-of-max-width-increment.txt | 30 +-- 58 files changed, 693 insertions(+), 692 deletions(-) diff --git a/AK/Math.h b/AK/Math.h index 8bb6c5a254a..185a4c2a700 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -1017,11 +1017,15 @@ constexpr T pow(T x, T y) template constexpr int clamp_to_int(T value) { - if (value >= NumericLimits::max()) { + if (value >= NumericLimits::max()) return NumericLimits::max(); - } else if (value <= NumericLimits::min()) { + + if (value <= NumericLimits::min()) return NumericLimits::min(); - } + + if constexpr (IsFloatingPoint) + return round_to(value); + return value; } diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt index 6596d426c3e..f0259c7d50e 100644 --- a/Tests/LibWeb/Layout/expected/acid1.txt +++ b/Tests/LibWeb/Layout/expected/acid1.txt @@ -1,15 +1,15 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline - BlockContainer at (0,0) content-size 800x419.921875 [BFC] children: not-inline + BlockContainer at (0,0) content-size 800x420 [BFC] children: not-inline BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline TextNode <#text> - BlockContainer at (20,20) content-size 480x379.921875 children: not-inline + BlockContainer at (20,20) content-size 480x380 children: not-inline BlockContainer <(anonymous)> at (20,20) content-size 480x0 children: inline TextNode <#text> BlockContainer
at (25,25) content-size 470x0 children: inline TextNode <#text> - BlockContainer
at (40,40) content-size 49.984375x280 floating [BFC] children: inline - line 0 width: 28.296875, height: 10, bottom: 10, baseline: 7.984375 - frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.296875x10] + BlockContainer
at (40,40) content-size 50x280 floating [BFC] children: inline + line 0 width: 28.3125, height: 10, bottom: 10, baseline: 8 + frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.3125x10] "toggle" TextNode <#text> TextNode <#text> @@ -19,55 +19,55 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer