Refactor arc and rect to use canvas methods rather than curves #7205
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.
Resolves #6485
Changes:
arc
, use canvasellipse
, removing the need for_acuteArcToBezier
rect
, use canvasroundRect
when there are rounded corners, rater thanArcTo
Screenshots of the change:
SCREENSHOT: Same code running with current p5 (left) and locally (right) demonstrating visual equivalence for
rect
with different rounded corners, one of them clipped.PR Checklist
npm run lint
passesNo additional unit tests have been included*. Manual testing was done with all the standard examples from the p5 documentation on both
arc
andrect
as well as some additional edge cases, like too-big corner radii (as in the screenshot above) and arc start/end values outside of(0, TWO_PI)
range (this is currently not breaking usage and so should not become breaking usage).Where out-of-domain parameters to canvas rendering context method is the source of the error, the error provided by p5 will reflect the different function usage:
SCREENSHOT:
Same code running with current p5 (left) and locally (right) demonstrating difference between badEdited to add: sorry, the nice error is just in the p5 editor. In plain browser, both errors are equally uncaught, just the name of the function is different.rect
input of negative radius. The p5 error provides the canvas error, which is different due to refactor, and the new error is not caught correctly. I am not sure where to update the corresponding code.*There is an idea in the original issue discussion to use visual automated tests (#6485 (comment): "...the idea is to run sample input through p5's current implementation of ellipse and create an image from that. Let's call this the base image. Then, you run the same input through your implementation and create another image. Let's call that the compare image. The test does a pixel-by-pixel comparison of the base image and the compare image. If there's a difference, the test fails.") which I think would be really good, and I would be happy to work on that, but it seems like a separate Issue/PR for workflow enhancement.