Skip to content

Commit 6bdd085

Browse files
committed
[css-backgrounds-3] Add additional examples for w3c#7103.
This adds the additional examples originally added in w3c#7103 (comment) This adds 3 additional options. One of them is the old (discontinuous) behavior which is still what non-Chromium engines implement (along with old Chromium). The other two are an additional capping method that I came up with (with 2 variants).
1 parent 12f0d5a commit 6bdd085

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

css-backgrounds-3/radius-expansion-continuity.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<input type="radio" name="algorithm" value="increase-by-spread">
3434
Increase radius by spread
3535
</label>
36+
<label>
37+
<input type="radio" name="algorithm" value="old-spec">
38+
Old spec (discontinuous)
39+
</label>
3640
<label>
3741
<input type="radio" name="algorithm" value="current-spec">
3842
Current spec
@@ -53,6 +57,14 @@
5357
<input type="radio" name="algorithm" value="percentage-same-axis-ratio">
5458
Percentage of same axis,<br>ceiling to keep ratio if possible
5559
</label>
60+
<label>
61+
<input type="radio" name="algorithm" value="linear-edge-portion">
62+
Rounded portion of edges (linear)
63+
</label>
64+
<label>
65+
<input type="radio" name="algorithm" value="cubic-edge-portion">
66+
Rounded portion of edges (cubic)
67+
</label>
5668
</form>
5769
<div id="output"></div>
5870
<script>
@@ -142,6 +154,20 @@
142154
};
143155
break;
144156
}
157+
case "old-spec": {
158+
const map = (value) => {
159+
if (value == 0)
160+
return 0;
161+
return value + testCase.spread;
162+
}
163+
r = {
164+
topLeft: radii.topLeft.map(map),
165+
topRight: radii.topRight.map(map),
166+
bottomLeft: radii.bottomLeft.map(map),
167+
bottomRight: radii.bottomRight.map(map),
168+
};
169+
break;
170+
}
145171
case "current-spec": {
146172
const map = (value) => {
147173
if (value >= testCase.spread) {
@@ -234,6 +260,38 @@
234260
adjust("topRight", "bottomRight", 1);
235261
break;
236262
}
263+
case "linear-edge-portion":
264+
case "cubic-edge-portion": {
265+
// The portion of each edge that is rounded
266+
const portion = {
267+
top: (radii.topLeft[0] + radii.topRight[0]) / testCase.width,
268+
right: (radii.topRight[1] + radii.bottomRight[1]) / testCase.height,
269+
bottom: (radii.bottomLeft[0] + radii.bottomRight[0]) / testCase.width,
270+
left: (radii.topLeft[1] + radii.bottomLeft[1]) / testCase.height,
271+
};
272+
const map = (value, cap) => {
273+
if (value >= testCase.spread) {
274+
return value + testCase.spread;
275+
}
276+
switch (algorithm.value) {
277+
case "linear-edge-portion": {
278+
let r = value / testCase.spread;
279+
return value + testCase.spread * Math.max(1 + (r - 1)**3, cap);
280+
}
281+
case "cubic-edge-portion": {
282+
let r = Math.max(value / testCase.spread, cap);
283+
return value + testCase.spread * (1 + (r - 1)**3);
284+
}
285+
}
286+
}
287+
r = {
288+
topLeft: radii.topLeft.map((r) => map(r, Math.max(portion.top, portion.left))),
289+
topRight: radii.topRight.map((r) => map(r, Math.max(portion.top, portion.right))),
290+
bottomLeft: radii.bottomLeft.map((r) => map(r, Math.max(portion.bottom, portion.left))),
291+
bottomRight: radii.bottomRight.map((r) => map(r, Math.max(portion.bottom, portion.right))),
292+
};
293+
break;
294+
}
237295
default: {
238296
throw "Not implemented: " + algorithm.value;
239297
break;

0 commit comments

Comments
 (0)