-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Suggestion: include an error message when drawing shapes with NaN
values.
#5675
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already. |
@almchung @outofambit Would you like to have a look at this? I would imagine including a check for |
Good catch! The current
|
In the case of |
Sorry, I totally misread last time. I agree using Found another bug while testing: I still think drawing functions like |
Is anyone currently working on this? If not I might have a crack at implementing the finite/infinite checking aspect |
@oscarczer Please go ahead with a fix! Thanks. |
Just confirming that we want null to be accepted as an input? I was going to implement an additional check here alongside finite checking to ensure that the string "null" isn't considered a valid parameter (as I don't believe that isNaN accounts for this) but saw what @almchung said and am now not so sure. I feel as if null and 0 shouldn't necessarily be treated the same as they could likely occur from different situations but if you'd like this to be the case I'll leave it as it :) |
@oscarczer I agree that |
@almchung I was under the impression that isNaN(null) returns false as for some reason it is given the type of number (I think actually because of the instance it is able to be turned into 0?). I assumed that this would extent to isNaN("null") as well however I could definitely be wrong about that. Given this, it might also be worth putting a check for null in the first case of the param switch. However, irrespective of that I'm more than happy to add a check for isNaN("") as well as you're right about that also being an edge-case worth accounting for |
Javascript can be confusing -- it would be helpful to check their String coercion rules on the official reference here. I don't think we will need to add a separate case for checking Getting Hopefully this is helpful! |
Hi, I was wondering why we use |
@Bernice55231 For p5.js, it is possible to pass a number string (eg. |
Increasing Access
If the user tries to draw a shape where any of the arguments are
NaN
it does not draw anything. I would expect that it would log an error using the friendly error system so that the user knows why their code didn't do what they intended. This would make it much easier for beginners to debug their code.Most appropriate sub-area of p5.js?
Feature enhancement details
Initially I assumed that p5.js was somehow catching or avoiding a DOM error. Unfortunately it seems like the canvas API itself does not give any errors or warnings when encountering☹️ ). So p5.js would need to check and validate arguments on its own.
NaN
values (SVG doesWe would want to include an
NaN
check in all shape functions such asrect()
,line()
, etc.Here is an example code but it's very uninteresting. It doesn't do anything.
The text was updated successfully, but these errors were encountered: