|
59 | 59 | </label> |
60 | 60 | <label> |
61 | 61 | <input type="radio" name="algorithm" value="linear-edge-portion"> |
62 | | - Rounded portion of edges (linear) |
| 62 | + Cap by rounded portion of edges (linear) |
63 | 63 | </label> |
64 | 64 | <label> |
65 | 65 | <input type="radio" name="algorithm" value="cubic-edge-portion"> |
66 | | - Rounded portion of edges (cubic) |
| 66 | + Cap by rounded portion of edges (cubic) |
67 | 67 | </label> |
68 | 68 | <label> |
69 | | - <input type="radio" name="algorithm" value="interpolate-straight-rounded"> |
70 | | - Interpolation based on straight/rounded (linear) |
| 69 | + <input type="radio" name="algorithm" value="linear-edge-ratio"> |
| 70 | + Cap by rounded/straight ratio of edges (linear) |
| 71 | + </label> |
| 72 | + <label> |
| 73 | + <input type="radio" name="algorithm" value="cubic-edge-ratio"> |
| 74 | + Cap by rounded/straight ratio of edges (cubic) |
| 75 | + </label> |
| 76 | + <label> |
| 77 | + <input type="radio" name="algorithm" value="interpolate-straight-rounded-portion"> |
| 78 | + Interpolation based on rounded portion of edges |
| 79 | + </label> |
| 80 | + <label> |
| 81 | + <input type="radio" name="algorithm" value="interpolate-straight-rounded-ratio"> |
| 82 | + Interpolation based on rounded/straight ratio |
71 | 83 | </label> |
72 | 84 | </form> |
73 | 85 | <div id="output"></div> |
|
81 | 93 | {width: 200, height: 40, spread: 50, borderRadius: "100px / 20px"}, |
82 | 94 | {width: 200, height: 40, spread: 50, borderRadius: "20px / 4px"}, |
83 | 95 | {width: 500, height: 50, spread: 30, borderRadius: "15px"}, |
| 96 | + {width: 500, height: 50, spread: 30, borderRadius: "25px"}, |
84 | 97 | {width: 500, height: 50, spread: 30, borderRadius: "1px 1px 49px 49px"}, |
85 | 98 | {width: 500, height: 50, spread: 30, borderRadius: "50%"}, |
86 | 99 | {width: 500, height: 50, spread: 30, borderRadius: "50% 50% 1px 50%"}, |
|
264 | 277 | } |
265 | 278 | case "linear-edge-portion": |
266 | 279 | case "cubic-edge-portion": |
267 | | - case "interpolate-straight-rounded": { |
| 280 | + case "linear-edge-ratio": |
| 281 | + case "cubic-edge-ratio": |
| 282 | + case "interpolate-straight-rounded-portion": |
| 283 | + case "interpolate-straight-rounded-ratio": { |
268 | 284 | // The portion of each edge that is rounded |
269 | 285 | const portion = { |
270 | 286 | top: (radii.topLeft[0] + radii.topRight[0]) / testCase.width, |
271 | 287 | right: (radii.topRight[1] + radii.bottomRight[1]) / testCase.height, |
272 | 288 | bottom: (radii.bottomLeft[0] + radii.bottomRight[0]) / testCase.width, |
273 | 289 | left: (radii.topLeft[1] + radii.bottomLeft[1]) / testCase.height, |
274 | 290 | }; |
275 | | - const map = (value, cap, idx) => { |
| 291 | + const map = (value, ratio, idx) => { |
276 | 292 | if (value >= testCase.spread) { |
277 | 293 | return value + testCase.spread; |
278 | 294 | } |
279 | 295 | switch (algorithm.value) { |
| 296 | + case "linear-edge-ratio": |
| 297 | + ratio = Math.min(ratio / (1 - ratio), 1); |
| 298 | + // fallthrough |
280 | 299 | case "linear-edge-portion": { |
281 | 300 | let r = value / testCase.spread; |
282 | | - return value + testCase.spread * Math.max(1 + (r - 1)**3, cap); |
| 301 | + return value + testCase.spread * Math.max(1 + (r - 1)**3, ratio); |
283 | 302 | } |
| 303 | + case "cubic-edge-ratio": |
| 304 | + ratio = Math.min(ratio / (1 - ratio), 1); |
| 305 | + // fallthrough |
284 | 306 | case "cubic-edge-portion": { |
285 | | - let r = Math.max(value / testCase.spread, cap); |
| 307 | + let r = Math.max(value / testCase.spread, ratio); |
286 | 308 | return value + testCase.spread * (1 + (r - 1)**3); |
287 | 309 | } |
288 | | - case "interpolate-straight-rounded": { |
289 | | - const straight = 1 - cap; |
290 | | - const ratio = Math.min(straight / cap, 1); |
| 310 | + case "interpolate-straight-rounded-ratio": |
| 311 | + ratio = 1 - Math.min((1 - ratio) / ratio, 1); |
| 312 | + // fallthrough |
| 313 | + case "interpolate-straight-rounded-portion": { |
| 314 | + ratio = 1 - ratio; |
291 | 315 |
|
292 | 316 | const r = value / testCase.spread; |
293 | 317 | const cubic = value + testCase.spread * (1 + (r - 1)**3); |
|
0 commit comments