Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit fe3ef95

Browse files
noamrmoz-wptsync-bot
authored andcommitted
Bug 1949142 [wpt PR 50795] - Simplify corner-shape inset formula, a=testonly
Automatic update from web-platform-tests Simplify corner-shape inset formula Undo the slope calculation which was done for uneven radius (e.g. due to percentage), as this would be incompatible with existing border-radius rendering. Instead, compute a simple offset based on the curvature and border width only. This would mean that elliptical corners would still look "scaled", but square corners would have the correct width. Bug: 394059604 Change-Id: If95876d166fdf7c2a83c3b1853e5be6cbb4bf657 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6280666 Reviewed-by: Fredrik Söderquist <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1421844} -- wpt-commits: 50268f9ef1ba7739f1d4b082b3b766b9a200144b wpt-pr: 50795
1 parent 78e172a commit fe3ef95

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

testing/web-platform/tests/css/css-borders/tentative/corner-shape/corner-shape-render-ref.html

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,22 @@
4848
}
4949

5050
const ctx = canvas.getContext("2d");
51-
51+
const keywords = {bevel: 1, round: 2};
5252
// Adjust outer width for curvature
5353
const outer_width = ["top", "bottom"].flatMap((vSide) =>
5454
["left", "right"].map((hSide) => {
5555
const corner = `${vSide}-${hSide}`;
56-
const shape = style[`corner-${corner}-shape`];
56+
let shape = style[`corner-${corner}-shape`];
57+
shape = keywords[shape] || shape;
5758
const radius = style[`border-${corner}-radius`];
58-
if (radius[0] === 0 || radius[1] === 0) return [0, 0];
59-
if (shape === "round") return [...radius];
60-
6159
const hWidth = style[`border-${hSide}-width`];
6260
const vWidth = style[`border-${vSide}-width`];
63-
let slope = radius[1] / radius[0];
64-
let perp = [-radius[0], radius[1]];
65-
const mag = Math.hypot(...radius);
66-
const translateX = [(perp[0] * hWidth) / mag, (perp[1] * hWidth) / mag];
67-
const translateY = [(perp[0] * vWidth) / mag, (perp[1] * vWidth) / mag];
68-
const vIntercept = Math.max(0, translateY[1] - slope * translateY[0]);
69-
const hIntercept = Math.max(0, translateX[1] - slope * translateX[0]);
70-
return [radius[0] + vWidth - vIntercept, radius[1] + hWidth - hIntercept];
61+
if (shape >= 2.)
62+
return radius;
63+
if (shape <= 0.5)
64+
return [radius[0] - vWidth, radius[1] - hWidth];
65+
const offset = Math.sqrt(2. / shape) - 1;
66+
return [radius[0] - vWidth * offset, radius[1] - hWidth * offset];
7167
})
7268
);
7369
let cursor = [];

0 commit comments

Comments
 (0)