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

raise an error, when Vector.normalize() tries to normalize a "zero-vector" #37

Closed
Devrim-Celik opened this issue Mar 9, 2018 · 1 comment

Comments

@Devrim-Celik
Copy link
Contributor

Devrim-Celik commented Mar 9, 2018

Test script:
Problem is, when you try to normalize a Vector Object, which only has zero value, it tries to divide
them by 0 (their current magnitude), setting the values to nan. It would be handy if a error would pop up.

from p5 import *

x = Vector(0, 0)

print(x.magnitude)
x.normalize()
print(x)
print(x.magnitude)

Expected behavior:

0.0
ValueError(...)

Actual behavior

0.0
Vector(nan, nan, nan)
nan

Errors produced (if any):

p5 version:
0.3.0a2

Python version:
Python 3.6.4

Operating System:
MacOS

arihantparsoya added a commit to arihantparsoya/p5 that referenced this issue Mar 9, 2018
Fixes p5py#37.

Added test condition in line 376 to raise ValueError when magnitude of vector is 0.
@arihantparsoya
Copy link
Member

See #38 .

@abhikpal abhikpal changed the title [Feature Request] raise an error, when Vector.normalize() tries to normalize a "zero-vector" raise an error, when Vector.normalize() tries to normalize a "zero-vector" May 1, 2018
@abhikpal abhikpal added this to the Pre-VisPy release milestone Jun 5, 2018
@abhikpal abhikpal self-assigned this Jun 5, 2018
@abhikpal abhikpal modified the milestones: Pre-VisPy release, Port backend to VisPy Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants