-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Update and simplify implementation of arc, ellipse, and possibly rect #6485
Comments
Both the native canvas ellipse and roundRect methods are pretty well supported across the board so I'm happy for this to go ahead as long as it doesn't change the user facing API (which it probably won't need to anyway). |
@limzykenneth Great! I'm not sure when I'd be able to work on this. Would it be good to add a Help Wanted label? |
Great suggestions @GregStanton. Just added the 'Help Wanted' label. |
Hello, i am new to open source and have been studying p5.js from somedays. I do get the lines after the tasks list, but i do not get the first line of the issue. Can someone please help me understand the issue? |
@GregStanton I would like to help with this issue |
so a good solution would be to create a blackbox using the web native canvas api, which can replace |
I'm not sure I fully follow what you mean by blackbox, but I think the rest sounds correct! the implementations of arc and ellipse could both be updated to use the native canvas ellipse method for their implementations. |
Hi @tuminzee! I'll add to @davepagurek's answer in case it helps. From the user's perspective, p5's However, developers contributing to p5 may need to look inside the boxes. If they look inside I hope that helps. P.S. If you want to simplify p5's implementation of |
@GregStanton this helps a lot 👍🏼 |
@GregStanton can you have a look at #6499 If you agree on this implementation I will continue the same for the remaining functions |
@tuminzee Excellent! Thanks for doing this. I didn't check every line, but this looks like what I had in mind. I did make a few minor comments about coding style on the commit itself. |
@GregStanton I have resolved your comments here b73af84 I will update the PR with the addition of other functions as well. |
That's great @tuminzee! About testing, @Qianqianye, @davepagurek, and @limzykenneth will have a better idea of p5's usual process. I'll share my thoughts about it, and hopefully they'll be able to provide feedback. Current tests: There are already some unit tests that should run automatically. However, the tests I found are pretty basic, so my inclination would be to add visual tests. Visual tests can be done manually, as you're doing, and it seems like that's the usual approach with p5 (although I'm not sure). Automated visual tests: Another approach is to automate the visual tests. In this case, the idea is to run sample input through p5's current implementation of Pros and cons:
|
Great @GregStanton I will try my best to come up with tests, if not I will at least finish the PR with manual testing |
Visual tests are something I've been thinking about as well, it feels a bit difficult to implement so that the results are consistent across systems and runs but I think is still worth exploring. That said I think it probably fits as a separate issue and for this feature, manual tests should suffice for now. |
Addresses #6485 Refactor ellipse drawing logic in p5.Renderer2D.js
Hello @limzykenneth , I see this has been reopened - could I ask what the status is? I saw the issue that refactored |
@ksen0 There is a small check list in the top issue body, essentially |
@limzykenneth thanks! I will work on this. Sorry if this has been covered elsewhere and I didn't see, but
(First time working on p5.js. |
@ksen0 What version of node.js and npm are you working with? Also your OS and version may be helpful to identify the issue as well. |
@limzykenneth 🙏 Mac OS 13.0 (22A380)
|
@ksen0 Those should be fine. Do you have Chrome installed? |
@limzykenneth yes. But anyway, it's not really an immediate blocker that 1 test doesn't pass. The suite as a whole runs, so I'll make an attempt at this issue for now:) Thanks for your quick responses. (Edited on aug 29 to add: I am working on this. Mode of |
Hello @limzykenneth! I just finished refactoring I tested with all the example arc code (https://p5js.org/reference/p5/arc/) as well as a few other manual tests, but there are no automated tests covering this. I also haven't been able to sort of out my
EDITED: I also updated But not sure how to resolve my local failing tests issue.. what should I do? Should I make a pull request for one/both of the commits above, or do you have any suggestions on how I could investigate my local build issue (was there before any work I did)? Thank you! Also, I realize it wasn't actually assigned to me, if someone else already did it, no worries. It was a nice introduction to the renderer. Sorry if actually working on it was not ok because it wasn't assigned, I'll just take it as a personal learning experience in that case. |
@ksen0 Please go ahead and file a single PR for both. The test can run as part of the PR so that can be another way to do it. For the local test setup, as I cannot reproduce, I would need you to try to debug as much as you can if you are able to. No worries if not but just to note that I can't offer much else in terms of possible resolution in this case as I don't have enough information to debug. |
Thanks @limzykenneth ! I added the PR above. |
Increasing Access
This enhancement would simplify p5's source code and would reduce the mathematical prerequisites for understanding it. This would increase access among p5 contributors.
Most appropriate sub-area of p5.js?
Feature enhancement details
Proposal
Use modern features of the native canvas API to simplify the implementation of
arc
,ellipse
, and possiblyrect
.The problem
The 2D renderer's current implementation of
arc
andellipse
is complicated by the fact that it uses Bézier curves, which cannot exactly represent either primitive. The implementation is complicated enough that the source comments link to an outside paper for an explanation of the underlying mathematics.The implementation of
rect
may also be more complicated than necessary, since rounded corners require clipping the radii and building the rectangle with the canvas'sarcTo
method.The solution
The use of Bézier curves in p5's 2D implementation of
arc
andellipse
dates to p5's addition ofellipse
on July 4, 2013. At that time, the canvas didn't have a native ellipse method. Now it does. The canvas'sellipse
method actually draws elliptical arcs, so it could be used to implement botharc
andellipse
in p5. This would be a significant simplification. Also,ellipse
has been available in Chrome since November 2013, so bugs and browser compatibility don't seem like a significant concern.The situation with
rect
is similar. After p5 already supported rectangles with rounded corners, theroundRect
method was added to the native Canvas API. However, this addition is much more recent (browsers began supporting it in 2022, with Firefox support only being added in 2023).Update:
Here's a task list to help us keep track of what work has been completed, since @tuminzee has already done the work for
ellipse()
(it just needs to be merged). Note that the task list does includerect()
, based on the comments on this issue.ellipse()
arc()
rect()
The text was updated successfully, but these errors were encountered: