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

Small changes to Py5Vector set_mag() and normalize() to make it more consistent with PVector & Processing #243

Closed
hx2A opened this issue Mar 3, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@hx2A
Copy link
Collaborator

hx2A commented Mar 3, 2023

    > In Processing you can set the magnitude of a vector to a negative scalar... this will "flip" the heading...

That's interesting! Right now the Py5Vector will reject a negative value for the set_mag() method. I think we should allow negative values, like Processing does. This is an easy change.

Also Processing "fails silently" to set magnitude to a "null vector". Should we follow that?

I did some experimenting and I see that this is valid Processing code:

PVector v = new PVector();
v.normalize();
println(v);
// [ 0.0, 0.0, 0.0 ]

py5 would reject the similar code, not allowing you to normalize a vector with a magnitude of zero. This does bother me a bit, but being consistent with Processing is probably the better choice. And if this is allowed in py5, using set_mag() on a zero vector will also be allowed.

Originally posted by @hx2A in #242 (comment)

@hx2A hx2A added the good first issue Good for newcomers label Mar 5, 2023
@hx2A
Copy link
Collaborator Author

hx2A commented Mar 5, 2023

To summarize:

  • Py5Vector should let you set the magnitude to a negative magnitude. This would reverse the direction of the vector
  • Normalize should be allowed on zero vectors, but issue a Python warning

@hx2A
Copy link
Collaborator Author

hx2A commented Mar 14, 2023

Fixed with #261. thank you, @AsadNizami !

@hx2A hx2A closed this as completed Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant