Skip to content

Commit c327d94

Browse files
Loirooriolfantasaiyarusome
committed
Update radius-expansion.html with new algorithm and testcases
The new testcases are from https://yarusome.github.io/box-shadow-proposal/ Co-authored-by: fantasai <[email protected]> Co-authored-by: yarusome <[email protected]>
1 parent e97a09d commit c327d94

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

css-backgrounds-3/radius-expansion.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@
7272
</label>
7373
<label>
7474
<input type="radio" name="algorithm" value="oriol">
75-
Oriol's variant of current spec
75+
Oriol's variant of current spec (adding a cubic factor)
76+
</label>
77+
<label>
78+
<input type="radio" name="algorithm" value="oriol2">
79+
Oriol's variant of current spec (adding a linear factor)
7680
</label>
7781
</form>
7882
<output id="output"></output>
@@ -93,6 +97,8 @@
9397
{width: 500, height: 50, spread: 30, borderRadius: "50%"},
9498
{width: 500, height: 50, spread: 30, borderRadius: "50% 50% 1px 50%"},
9599
{width: 200, height: 40, spread: 50, borderRadius: "0 100% 0 100%"},
100+
{width: 200, height: 40, spread: 50, borderRadius: "10% 90% / 5%"},
101+
{width: 200, height: 40, spread: 50, borderRadius: "0 50% / 50%"},
96102
{width: 0, height: 0, spread: 30, borderRadius: "50px 0px 0px 0px"},
97103
{width: 500, height: 500, spread: 30, borderRadius: "50px"},
98104
];
@@ -302,6 +308,21 @@
302308
});
303309
}
304310
}
311+
else if (algorithm === "oriol2") {
312+
for (let corner in radii) {
313+
let coverage = Math.max(
314+
2 * radii[corner][0] / testCase.width,
315+
2 * radii[corner][1] / testCase.height,
316+
) || 0;
317+
r[corner] = radii[corner].map(value => {
318+
if (value >= testCase.spread || coverage >= 1) {
319+
return value + testCase.spread;
320+
}
321+
let r = 1 - value / testCase.spread;
322+
return value + testCase.spread * (1 - r**3 * (1 - coverage));
323+
});
324+
}
325+
}
305326

306327
return `${r.topLeft[0]}px ${r.topRight[0]}px ${r.bottomRight[0]}px ${r.bottomLeft[0]}px / ${r.topLeft[1]}px ${r.topRight[1]}px ${r.bottomRight[1]}px ${r.bottomLeft[1]}px`;
307328
}
@@ -312,4 +333,4 @@
312333
</script>
313334

314335
</body>
315-
</html>
336+
</html>

0 commit comments

Comments
 (0)