|
371 | 371 | }; |
372 | 372 | } |
373 | 373 | else if (algorithm === "spectrum2") { |
374 | | - const axial_spread_factor = (radius, dim) => { |
375 | | - // If there's no radius, there's no spread to apply. |
376 | | - if (radius === 0) { |
377 | | - return 0; |
378 | | - } |
| 374 | + for (let corner in radii) { |
| 375 | + // Calculate the min diameter's ratio to the overall dimension, clamping at 1. |
| 376 | + const dimRatio = Math.min( |
| 377 | + 1, |
| 378 | + (2 * radii[corner][0]) / testCase.width, |
| 379 | + (2 * radii[corner][1]) / testCase.height, |
| 380 | + ); |
| 381 | + |
| 382 | + r[corner] = radii[corner].map(radius => { |
| 383 | + // If there's no radius, there's no spread to apply. |
| 384 | + if (radius === 0) { |
| 385 | + return 0; |
| 386 | + } |
379 | 387 |
|
380 | | - // Calculate the radius's ratio to the spread, clamping at 1. |
381 | | - const spreadRatio = 1 - Math.min(1, radius / testCase.spread); |
| 388 | + // Calculate the radius's ratio to the spread, clamping at 1. |
| 389 | + const spreadRatio = 1 - Math.min(1, radius / testCase.spread); |
382 | 390 |
|
383 | | - // Calculate the diameter's ratio to the overall dimension, clamping at 1. |
384 | | - const dimRatio = Math.min(1, (2 * radius) / dim); |
| 391 | + // These factors determine the amount of easing. They both approach 0 |
| 392 | + // as their respective ratios approach 1, which reduces the easing effect. |
| 393 | + const spreadEasingFactor = spreadRatio ** 3; |
| 394 | + const dimEasingFactor = 1 - dimRatio ** 3; |
385 | 395 |
|
386 | | - // These factors determine the amount of easing. They both approach 0 |
387 | | - // as their respective ratios approach 1, which reduces the easing effect. |
388 | | - const spreadEasingFactor = spreadRatio ** 3; |
389 | | - const dimEasingFactor = 1 - dimRatio ** 3; |
| 396 | + // The total reduction in spread is the product of the two easing factors. |
| 397 | + const totalReduction = dimEasingFactor * spreadEasingFactor; |
390 | 398 |
|
391 | | - // The total reduction in spread is the product of the two easing factors. |
392 | | - const totalReduction = dimEasingFactor * spreadEasingFactor; |
393 | | - return 1 - totalReduction; |
394 | | - } |
| 399 | + // Apply the reduction to the spread and add it to the original radius. |
| 400 | + const easedSpread = testCase.spread * (1 - totalReduction); |
395 | 401 |
|
396 | | - for (let corner in radii) { |
397 | | - let spread_factor = Math.min( |
398 | | - axial_spread_factor(radii[corner][0], testCase.width), |
399 | | - axial_spread_factor(radii[corner][1], testCase.height), |
400 | | - ); |
401 | | - r[corner] = radii[corner].map(radius => { |
402 | | - return radius + testCase.spread * spread_factor; |
| 402 | + return radius + easedSpread; |
403 | 403 | }); |
404 | 404 | } |
405 | 405 | } |
|
0 commit comments