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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

martinleopold
Copy link

@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
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
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?

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
2 participants