Open JustZambetti opened 10 months ago
Hi, thanks for your interest in this! Some general comments:
_renderEllipse
called directly from multiple user-facing functions? If so, maybe it makes sense for it to internally adapt its inputs however it needs, and then pass those new inputs into another internal function that only accepts a cleaner subset of inputs?Hi @davepagurek, I noticed some issues in the 2D Primitives test suite and made the following improvements:
p5.prototype.ellipse
suite, addressed the missing param #2 and #3 issues.p5.prototype.rect
suite, fixed the case where missing param #5 was not throwing a validation error.p5.prototype.square
suite to handle missing param #3 appropriately.p5.prototype.line
suite where incorrect parameters were not triggering validation errors.p5.prototype.triangle
suite for better clarity.Before proceeding, I wanted to check if you have any specific considerations or if it's okay for me to submit a pull request with these changes. Looking forward to your feedback.
Best regards, tanmay
There may be a case for this to be looked at as part of the 2.0 RFC at #6678. If so we can turn this into a proposal for refactoring the 2D renderer in general.
Increasing Access
It would make the code shorter and more readable
Most appropriate sub-area of p5.js?
Feature enhancement details
I think that 2d_primitives.js could be refactored a bit. These are some suggestions:
_normalizeArcAngles signature
Problems:
From this:
To this:
_normalizeArcAngles angle constraint
Code:
Problems:
Proposal:
_normalizeArcAngles abs
Code:
Problem:
Proposal:
_normalizeArcAngles angle scaling
Code:
Problems:
Proposal:
makeDrawRegionRelative(region){ region.start = makeAngleRelative(region.start); region.stop = makeAngleRelative(region.stop); return region; }
//I don't understand the math behind completely so I'm not able to simplify it further, // this method is actually too long but it's still an improvement //TODO: simplify this method makeAngleRelative(angle){ const THREE_PI = 3 * constants.HALF_PI; let offsetAngle = 0;
if(angle < constants.PI) offsetAngle = 0; else if (angle <= THREE_PI) offsetAngle = constants.PI; else offsetAngle = constants.TWO_PI;
return Math.atan(width / height * Math.tan(angle)) + offsetAngle; }
Problem:
But I would leave the comment inside of the function because it's not obvious
arc function signature
Problem:
function has too many arguments but it's a public API so it's better to just group them and call another function
Proposal:
arc function premature return
Code:
Problem:
Code should expain itself so the comment should not be necessary
Proposal:
arc function size abs
Code:
Problem:
a function should only contain one level of abstraction
Proposal:
circle inline documentation
Problem:
I don't think it is necessary to explain what a circle is.
circle function
Code:
Problem:
code could be simplified
Proposal:
_renderEllipse signature
Code:
Problem:
too many arguments
Proposal:
_renderEllipse code
Code:
Opinion:
Proposal:
I noticed that in many functions x and y, width and height are separate arguments but I think it's preferable to use position and size instead.
I would like to be assigned to this issue.