[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Pygame 2D vector



On the 2D vector page, http://pygame.org/wiki/2DVectorClass
 
It has a get_angle() function, the first line of this checks if length_sqrd() == 0, and then returns the angle as 0. This seems wrong to me, if the vector is (1,-1), then length_sqrd (1**2 + -1**2) returns 0, and so the angle is returned as 0. The angle for the vector should return -0.78... (in radians) not 0.
 
I believe the problem is get_length_sqrd(), I think the lines:
x = -self.x if self.x < 0 else self.x
y = -self.y if self.y < 0 else self.y
should be added (and the same to get_length()). I just wanted to check if people agree, before I change the page.
 
I assume this function call is supposed to be faster that math.atan2, which is why it is checked first. With these extra lines of code, is it still beneficial to have this call in, or just to remove the call from get_angle()?
 
Thanks,
Sam Bull