Skip to content

Fix zero-step SVG arc rendering for thin strokes in turtle-painter#5901

Open
kartikktripathi wants to merge 1 commit intosugarlabs:masterfrom
kartikktripathi:mathfix
Open

Fix zero-step SVG arc rendering for thin strokes in turtle-painter#5901
kartikktripathi wants to merge 1 commit intosugarlabs:masterfrom
kartikktripathi:mathfix

Conversation

@kartikktripathi
Copy link
Contributor

Summary

This PR fixes an incorrect use of Math.floor() in turtle-painter.js that allowed arc step calculations to become zero for thin stroke values. This silently broke SVG arc cap rendering for hollow lines and bezier curves.

Changes

  1. Corrected improper Math.floor usage where the minimum guard was mistakenly passed as a second argument:

    • Before:
      const steps = Math.max(Math.floor(savedStroke, 1));

    • After:
      const steps = Math.max(Math.floor(savedStroke), 1);

  2. Applied the same fix consistently in all four affected locations:

    • Line 349
    • Line 367
    • Line 607
    • Line 1041

This ensures that steps is always at least 1, preventing _svgArc() from receiving 0 steps.

Testing

  1. Set very thin pen sizes (e.g., 0.5, 1).
  2. Drew hollow lines, SVG arcs, and bezier curves.
  3. Verified:
    • No zero-step arcs
    • Proper round cap rendering
    • No regression in normal stroke rendering

Note

Math.floor(x, 1) ignores the second argument in JavaScript. The previous implementation effectively allowed steps to become 0, causing silent rendering issues. This fix enforces the intended minimum guard correctly.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@kartikktripathi
Copy link
Contributor Author

Hey @walterbender, this PR is ready to be reviewed. It fixes the incorrect use of Math.floor().
Thanks!

Copy link
Contributor

@mahesh-09-12 mahesh-09-12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kartikktripathi nice catch here, the previous Math.floor(savedStroke, 1) usage was incorrect and could result in zero steps for thin strokes. Clamping the computed value with Math.max(..., 1) makes the SVG arc rendering more robust and prevents subtle visual issues. The change is minimal and applied consistently.

@kartikktripathi
Copy link
Contributor Author

Thanks for the review, Mahesh!

Copy link
Contributor

@7se7en72025 7se7en72025 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants