Repository navigation
fix(brush): paint strokes reach the last clicked point - #57
Merged
Merged
Conversation
The relative curve of a paint stroke started with the origin and then repeated the first clicked point, which is also the origin, so it had n + 1 control points and n segments. The parameter was sampled over 0 to n - 1 and never reached the last segment. The curve now has one control point per clicked point, and a single-point stroke paints around that point. The equivalence test reference gets the same curve. The brush and the reference were wrong the same way, so the equivalence test passed. The docs illustration of the Paint Brush is regenerated. Claude-Session: https://claude.ai/code/session_01JavEedb4MyR9NehY3HusTn
Unit Test Results 43 files 43 suites 8s ⏱️ Results for commit c9d100c. |
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.
Cause
Since the 2.0 rewrite,
PaintBrush.sampleOffsetsbuilds the relative curve with the origin as a control point and then adds every clicked point, including the first one, which is the origin again. The curve therefore has n + 1 control points and n segments, while the parameter is sampled over0 .. n - 1. The last segment, from the second-to-last to the last clicked point, is never sampled, so the stroke stops one segment short.The upstream goPaint builds exactly one control point per clicked point (the candidate block first, then
block + (p_i - p_0)fori >= 1).Fix
ZEROfor the first point,p_i - firstfor the others. The parameter range0 .. n - 1is unchanged, andmaxCountis computed on the corrected spline.sampleOffsetsreturns the origin only. It paints around that point and does not callBezierSpline.getPointon a spline without segments.docs/images/brushes/paint-brush.svgis regenerated. Before the fix the painted stroke ends at the segment 5 to 6; after it, the stroke runs through point 6, and the painted block next to point 6 is gold. Sampling is about 0.4 blocks apart and floors to the block grid, so the block under the last click is not always painted itself.Equivalence test
PaintBrushEquivalenceTestpins the optimised brush to a copy of the original per-block algorithm. That copy had the same duplicated start control point, so brush and reference agreed on the wrong curve and the test passed. The reference now uses the corrected curve, and the comment inperBlockCurvessays so. The negative-offset and mixed-offset cases are kept.Tests
PaintBrushCurveTest.strokeReachesLastPoint(new): flat terrain, three points, the block at the last clicked point must be gold. It failed on the previous code (stoneat the last point) and passes now.PaintBrushCurveTest.singlePointStrokePaintsAroundIt(new): a one-point stroke paints the point and stays within the brush radius.PaintBrushEquivalenceTest: reference corrected, all four cases unchanged.Verification
./gradlew checkgreen: 43 suites, 203 tests, pluscheckDocsImages,checkDocsLinks,docsGenTestand spotless.docs/how-to/paint-a-path-with-the-paint-brush.mdanddocs/reference/brushes.mdalready describe the intended behaviour ("paints the curve through all points"), so no text change.https://claude.ai/code/session_01JavEedb4MyR9NehY3HusTn