Skip to content

Commit 5165b14

Browse files
committed
[css-backgrounds-3] Add additional examples for w3c#7103.
This contains the update originally in w3c#7103 (comment) and adds @fantasai's proposal to this set of examples.
1 parent 6bdd085 commit 5165b14

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
<input type="radio" name="algorithm" value="cubic-edge-portion">
6666
Rounded portion of edges (cubic)
6767
</label>
68+
<label>
69+
<input type="radio" name="algorithm" value="interpolate-straight-rounded">
70+
Interpolation based on straight/rounded (linear)
71+
</label>
6872
</form>
6973
<div id="output"></div>
7074
<script>
@@ -209,7 +213,6 @@
209213
break;
210214
}
211215
case "percentage-same-axis": {
212-
debugger;
213216
const xRatio = 1 + 2 * testCase.spread / testCase.width;
214217
const yRatio = 1 + 2 * testCase.spread / testCase.height;
215218
const map = ([x, y]) => [x * xRatio, y * yRatio];
@@ -222,7 +225,6 @@
222225
break;
223226
}
224227
case "percentage-same-axis-ratio": {
225-
debugger;
226228
const xRatio = 1 + 2 * testCase.spread / testCase.width;
227229
const yRatio = 1 + 2 * testCase.spread / testCase.height;
228230
const map = ([x, y]) => [x * xRatio, y * yRatio];
@@ -261,15 +263,16 @@
261263
break;
262264
}
263265
case "linear-edge-portion":
264-
case "cubic-edge-portion": {
266+
case "cubic-edge-portion":
267+
case "interpolate-straight-rounded": {
265268
// The portion of each edge that is rounded
266269
const portion = {
267270
top: (radii.topLeft[0] + radii.topRight[0]) / testCase.width,
268271
right: (radii.topRight[1] + radii.bottomRight[1]) / testCase.height,
269272
bottom: (radii.bottomLeft[0] + radii.bottomRight[0]) / testCase.width,
270273
left: (radii.topLeft[1] + radii.bottomLeft[1]) / testCase.height,
271274
};
272-
const map = (value, cap) => {
275+
const map = (value, cap, idx) => {
273276
if (value >= testCase.spread) {
274277
return value + testCase.spread;
275278
}
@@ -282,13 +285,25 @@
282285
let r = Math.max(value / testCase.spread, cap);
283286
return value + testCase.spread * (1 + (r - 1)**3);
284287
}
288+
case "interpolate-straight-rounded": {
289+
const straight = 1 - cap;
290+
const ratio = Math.min(straight / cap, 1);
291+
292+
const r = value / testCase.spread;
293+
const cubic = value + testCase.spread * (1 + (r - 1)**3);
294+
295+
const pctratio = 1 + 2 * testCase.spread / ((idx == 0) ? testCase.width : testCase.height);
296+
const percentage = value * pctratio;
297+
298+
return (1 - ratio) * percentage + ratio * cubic;
299+
}
285300
}
286301
}
287302
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))),
303+
topLeft: radii.topLeft.map((r, idx) => map(r, Math.max(portion.top, portion.left, idx))),
304+
topRight: radii.topRight.map((r, idx) => map(r, Math.max(portion.top, portion.right, idx))),
305+
bottomLeft: radii.bottomLeft.map((r, idx) => map(r, Math.max(portion.bottom, portion.left, idx))),
306+
bottomRight: radii.bottomRight.map((r, idx) => map(r, Math.max(portion.bottom, portion.right, idx))),
292307
};
293308
break;
294309
}

0 commit comments

Comments
 (0)