Fix numerical instability in tick generation (division by zero / NaN propagation) - #7
Open
samanthataylor3 wants to merge 1 commit into
Open
Conversation
Guard tickStep() and timeTickStep() against division by zero when count <= 0 by changing Math.max(0, count) to Math.max(1, count). Clamp secondary tick count in getLogTicks() to at least 1 to prevent passing zero or negative count to ticks() when secondaryTickCount <= 2. Add early return in ticks() for non-positive count values. Closes #3 Co-Authored-By: Samantha Taylor <samantha.taylor@cognition.ai>
Original prompt from Samantha
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3
Describe your changes:
Two defects in
src/plugins/plot/tickUtils.jsallow non-finite values (Infinity,NaN) to propagate into plot rendering, corrupting tick marks or causing infinite loops.Defect 1 —
tickStep()/timeTickStep()division by zero:Changed
Math.max(0, count)→Math.max(1, count)in both functions to guarantee a positive divisor.Defect 2 —
getLogTicks()passes non-positive count toticks():This is hit in practice:
MctTicks.vuecallsgetLogTicks(…, SECONDARY_TICK_NUMBER)whereSECONDARY_TICK_NUMBER = 2, sosecondaryTickCount - 2 = 0.Clamped to
Math.max(1, secondaryTickCount - 2)and added an early-return guard inticks()itself for defense-in-depth.All 4 locations fixed in one file:
tickStep()L23Math.max(0, count)→Math.max(1, count)timeTickStep()L41getLogTicks()L223secondaryTickCount - 2→Math.max(1, secondaryTickCount - 2)ticks()L237[]whencount < 1All Submissions:
Author Checklist
type:label? Note: this is not necessarily the same as the original issue.Reviewer Checklist
Link to Devin session: https://app.devin.ai/sessions/dcf6ca69fe8f4bd88047d072b3daeb19
Requested by: @samanthataylor3
Devin Review