Skip to content

Commit a7afc5b

Browse files
committed
Improve docs of Vec2d #274
1 parent 949a367 commit a7afc5b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Changelog
33
=========
44
.. Pymunk 7.0.0
55
Breaking: At least one of the two bodies attached to constraint/joint must be dynamic.
6-
New feature: ShapeFilter.rejects_collision() method
7-
New feature: Vec2d supports bool to test if zero. (bool(Vec2d(2,3) == True)
6+
7+
Extra thanks for aetle for a number of suggestions for improvements:
8+
New feature: ShapeFilter.rejects_collision()
9+
New feature: Vec2d supports bool to test if zero. (bool(Vec2d(2,3) == True)
810
Optimized Vec2d.angle and Vec2d.angle_degrees
11+
Improved vec2d documentation
912
1013
1114
Pymunk 6.11.1 (2025-02-09)

pymunk/vec2d.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,19 @@ def length(self) -> float:
287287
def scale_to_length(self, length: float) -> "Vec2d":
288288
"""Return a copy of this vector scaled to the given length.
289289
290+
Note that a zero length Vec2d cannot be scaled but will raise an
291+
exception.
292+
290293
>>> Vec2d(1, 0).scale_to_length(10)
291294
Vec2d(10.0, 0.0)
292295
>>> '%.2f, %.2f' % Vec2d(10, 20).scale_to_length(20)
293296
'8.94, 17.89'
294297
>>> Vec2d(1, 0).scale_to_length(0)
295298
Vec2d(0.0, 0.0)
299+
>>> Vec2d(0, 0).scale_to_length(1)
300+
Traceback (most recent call last):
301+
...
302+
ZeroDivisionError: float division by zero
296303
"""
297304
old_length = self.length
298305
return Vec2d(self.x * length / old_length, self.y * length / old_length)
@@ -374,7 +381,7 @@ def get_angle_degrees_between(self, other: "Vec2d") -> float:
374381

375382
def normalized(self) -> "Vec2d":
376383
"""Get a normalized copy of the vector.
377-
Note: This function will return 0 if the length of the vector is 0.
384+
Note: This function will return a Vec2d(0.0, 0.0) if the length of the vector is 0.
378385
379386
>>> Vec2d(3, 0).normalized()
380387
Vec2d(1.0, 0.0)

0 commit comments

Comments
 (0)