Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ellipseMode(CORNERS) and rectMode(CORNER) #7290

Merged
merged 7 commits into from
Oct 20, 2024

Conversation

martinleopold
Copy link
Contributor

@martinleopold martinleopold commented Sep 26, 2024

Resolves #7289

Changes:
This mainly resolves a rendering/crashing issues with ellipseMode(CORNERS) affecting ellipse() and arc(); see issue above). It also fixes a related issue with using rectMode(CORNER) and negative widths and/or heights.

The bulk of the changes are in modeAdjust() which should now properly handle the modes and return a normalized bounding box. As a result a few lines of handling negative widths and heights needed to be removed from arc() and _renderEllipse().

I've included a test sketch in test/shape-modes.html where you can cycle through all the different modes and shapes. I'm happy to update this, if somebody could direct me on how to properly test this case. I'm not sure, since it's mostly about the rendering output.

Screenshots of the change:
ellipse-fix

PR Checklist

Copy link

welcome bot commented Sep 26, 2024

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@perminder-17
Copy link
Contributor

Hi, Thanks for taking up this task. I believe I have tested this and it works well. I have a concern: are you planning to write tests for it in the test/shape-modes.html file?

If so, I don't think that approach would work for your case. Perhaps we could write unit or visual tests instead. What's your opinion?

test/shape-modes.html Outdated Show resolved Hide resolved
modeAdjust() now always returns the top-left corner and a positive width and height.
@martinleopold
Copy link
Contributor Author

Hi, I've added proper visual test and removed test/shape-modes.html. I had to update test/node/helpers.js (the test for modeAdjust() as well. npm run test passes all tests now. Please have a look and let me know if that works.

@martinleopold
Copy link
Contributor Author

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@all-contributors please add @martinleopold for bug, code

Copy link
Contributor

@martinleopold

I've put up a pull request to add @martinleopold! 🎉

@perminder-17 perminder-17 self-requested a review October 4, 2024 12:39
Copy link
Contributor

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Looks great so far. Just a few bits in the testing part. Thanks a lot for your work and your patience :)


for (let mode of MODES) {
visualTest(`Mode ${mode}`, function(p5, screenshot) {
p5.createCanvas(240, 500);
Copy link
Contributor

@perminder-17 perminder-17 Oct 5, 2024

Choose a reason for hiding this comment

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

Alright, I believe creating a larger canvas might be an issue. When the tests run, a bigger canvas could make them take a bit longer due to its size. Plus, including files that are 15-20kB could make the codebase pretty heavy. Could we perhaps reduce it to 50x50? That would probably take up minimal space in bytes.

By doing this, we could include the tests one by one. Like, for each quadrant we can add one tests or something like that? For reference, you might want to check out this link: https://github.com/processing/p5.js/pull/6783/files#diff-aefa4b8e5287fbd0cdf37a6ec8d27322a4e5c893e99ec74d32053e60e2bdfd7d

Quadrant-1 -> all modes -> 1 particular tests? Or do you have any idea how could 50X50 size canvas could be fit for testing? I am also not 100% sure.

Maybe by using a 50x50 size, we could adjust the parameter values of _shapeCorners accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case using many smaller canvases instead of a few bigger ones, will actually make things slower. Because then we'll have the overhead of createCanvas() i.e. creating a rendering context much more often, and the overall codebase size will also be larger with many small PNGs because of the PNG headers.

And to thoroughly test everything, we have 4 modes, times 3 shapes, times 4 quadrants, times 4 combinations of points, equals 192 shapes to draw. I see no way around that. Bear in mind this adds 192 test for fundamental drawing operations that were previously untested.

Therefore I propose making the canvas in the tests as small as possible, while still testing all the cases.
I have reduced the canvas size from 240x500 to 60x125 px, which reduces the total size of the generated PNGs from 223 to 12 kB.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good!

martinleopold

This comment was marked as outdated.

@perminder-17 perminder-17 self-requested a review October 13, 2024 17:07
Copy link
Contributor

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Requesting @davepagurek for a round of review since I haven't used ellipseMode() much, so needs another round of review. Also, very thanks for your patience @martinleopold I am really sorry for the delay on reviewing this PR, also thanks for your hardwork.

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks everyone!

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.

ellipseMode(CORNERS) broken in some cases
3 participants