py5coding / py5generator

Meta-programming project that creates the py5 library code.
https://py5coding.org/
GNU General Public License v3.0
52 stars 13 forks source link

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

Closed hx2A closed 1 year ago

hx2A commented 1 year ago
    > 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 https://github.com/py5coding/py5generator/discussions/242#discussioncomment-5185597

hx2A commented 1 year ago

To summarize:

hx2A commented 1 year ago

Fixed with #261. thank you, @AsadNizami !