|
65 | 65 | <input type="radio" name="algorithm" value="cubic-edge-portion"> |
66 | 66 | Rounded portion of edges (cubic) |
67 | 67 | </label> |
| 68 | + <label> |
| 69 | + <input type="radio" name="algorithm" value="interpolate-straight-rounded"> |
| 70 | + Interpolation based on straight/rounded (linear) |
| 71 | + </label> |
68 | 72 | </form> |
69 | 73 | <div id="output"></div> |
70 | 74 | <script> |
|
209 | 213 | break; |
210 | 214 | } |
211 | 215 | case "percentage-same-axis": { |
212 | | - debugger; |
213 | 216 | const xRatio = 1 + 2 * testCase.spread / testCase.width; |
214 | 217 | const yRatio = 1 + 2 * testCase.spread / testCase.height; |
215 | 218 | const map = ([x, y]) => [x * xRatio, y * yRatio]; |
|
222 | 225 | break; |
223 | 226 | } |
224 | 227 | case "percentage-same-axis-ratio": { |
225 | | - debugger; |
226 | 228 | const xRatio = 1 + 2 * testCase.spread / testCase.width; |
227 | 229 | const yRatio = 1 + 2 * testCase.spread / testCase.height; |
228 | 230 | const map = ([x, y]) => [x * xRatio, y * yRatio]; |
|
261 | 263 | break; |
262 | 264 | } |
263 | 265 | case "linear-edge-portion": |
264 | | - case "cubic-edge-portion": { |
| 266 | + case "cubic-edge-portion": |
| 267 | + case "interpolate-straight-rounded": { |
265 | 268 | // The portion of each edge that is rounded |
266 | 269 | const portion = { |
267 | 270 | top: (radii.topLeft[0] + radii.topRight[0]) / testCase.width, |
268 | 271 | right: (radii.topRight[1] + radii.bottomRight[1]) / testCase.height, |
269 | 272 | bottom: (radii.bottomLeft[0] + radii.bottomRight[0]) / testCase.width, |
270 | 273 | left: (radii.topLeft[1] + radii.bottomLeft[1]) / testCase.height, |
271 | 274 | }; |
272 | | - const map = (value, cap) => { |
| 275 | + const map = (value, cap, idx) => { |
273 | 276 | if (value >= testCase.spread) { |
274 | 277 | return value + testCase.spread; |
275 | 278 | } |
|
282 | 285 | let r = Math.max(value / testCase.spread, cap); |
283 | 286 | return value + testCase.spread * (1 + (r - 1)**3); |
284 | 287 | } |
| 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 | + } |
285 | 300 | } |
286 | 301 | } |
287 | 302 | 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))), |
292 | 307 | }; |
293 | 308 | break; |
294 | 309 | } |
|
0 commit comments