Repository navigation
Conversation
|
Hi maintainers.. @davepagurek @perminder-17 Just checking in on this PR. It fixes a potential division-by-zero case in If there’s any additional changes or improvements needed, I’ll be happy to update the PR quickly. |
|
Hi maintainers.. @davepagurek @perminder-17 Just checking in on this PR. It fixes a potential division-by-zero case in map() when start1 === stop1, which currently produces Infinity/NaN and can affect drawing logic. If there’s any additional changes or improvements needed, I’ll be happy to update the PR quickly. |
|
@VIPAX-JIT Please wait for assignment in the original issue before filing a PR. There are still discussions that needs to be resolved before we can decide if a PR is needed or not in this case. Thanks. |
|
Having the value be |
Resolves #8282
Changes:
This PR introduces a small but important defensive check to the
map()function located insrc/math/calculation.js.Currently, when
start1 === stop1, the expression:(n - start1) / (stop1 - start1)
results in a division-by-zero case. This produces
InfinityorNaN, which then propagates through subsequent drawing and color computations. These invalid values are especially confusing for beginners, as this scenario frequently occurs in sketches involving sliders, dynamic ranges, or programmatically determined bounds.This PR adds an early return when the input range collapses, defaulting the mapped value to
start2. This matches the intuitive expectation that if no mapping is possible (because the source range has zero width), the target output should fall back to its lower bound. The normal behavior ofmap()for all valid ranges remains fully preserved.Why this change:
NaNandInfinityvalues from appearing in sketchesAdditional Notes:
This fix is intentionally minimal and avoids introducing any behavior that would alter existing valid mappings. It simply guards an undefined mathematical case while keeping the function’s logic identical for all standard uses. No documentation or unit test changes are strictly required, as the current behavior is undefined for
start1 === stop1and this PR only stabilizes that edge condition.PR Checklist
npm run lintpasses