|
33 | 33 | <input type="radio" name="algorithm" value="increase-by-spread"> |
34 | 34 | Increase radius by spread |
35 | 35 | </label> |
| 36 | + <label> |
| 37 | + <input type="radio" name="algorithm" value="old-spec"> |
| 38 | + Old spec (discontinuous) |
| 39 | + </label> |
36 | 40 | <label> |
37 | 41 | <input type="radio" name="algorithm" value="current-spec"> |
38 | 42 | Current spec |
|
53 | 57 | <input type="radio" name="algorithm" value="percentage-same-axis-ratio"> |
54 | 58 | Percentage of same axis,<br>ceiling to keep ratio if possible |
55 | 59 | </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> |
56 | 68 | </form> |
57 | 69 | <div id="output"></div> |
58 | 70 | <script> |
|
142 | 154 | }; |
143 | 155 | break; |
144 | 156 | } |
| 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 | + } |
145 | 171 | case "current-spec": { |
146 | 172 | const map = (value) => { |
147 | 173 | if (value >= testCase.spread) { |
|
234 | 260 | adjust("topRight", "bottomRight", 1); |
235 | 261 | break; |
236 | 262 | } |
| 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 | + } |
237 | 295 | default: { |
238 | 296 | throw "Not implemented: " + algorithm.value; |
239 | 297 | break; |
|
0 commit comments