Skip to content

Commit ffe81dd

Browse files
authored
Merge pull request #255 from VeriTas-arch/master
Vec2d class documentation update
2 parents a4d1945 + 3a46b22 commit ffe81dd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pymunk/vec2d.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,17 @@ def normalized_and_length(self) -> Tuple["Vec2d", float]:
286286
return Vec2d(0, 0), 0
287287

288288
def perpendicular(self) -> "Vec2d":
289+
"""Get a vertical vector rotated 90 degrees counterclockwise from the original vector.
290+
291+
:return: A new vector perpendicular to this vector.
292+
"""
289293
return Vec2d(-self.y, self.x)
290294

291295
def perpendicular_normal(self) -> "Vec2d":
296+
"""Get a vertical normalized vector rotated 90 degrees counterclockwise from the original vector.
297+
298+
:return: A new normalized vector perpendicular to this vector.
299+
"""
292300
length = self.length
293301
if length != 0:
294302
return Vec2d(-self.y / length, self.x / length)
@@ -314,15 +322,18 @@ def get_distance(self, other: Tuple[float, float]) -> float:
314322
def get_dist_sqrd(self, other: Tuple[float, float]) -> float:
315323
"""The squared distance between the vector and other vector
316324
It is more efficent to use this method than to call get_distance()
317-
first and then do a sqrt() on the result.
325+
first and then do a square() on the result.
318326
319327
:return: The squared distance
320328
"""
321329
assert len(other) == 2
322330
return (self.x - other[0]) ** 2 + (self.y - other[1]) ** 2
323331

324332
def projection(self, other: Tuple[float, float]) -> "Vec2d":
325-
"""Project this vector on top of other vector"""
333+
"""Project this vector on top of other vector
334+
335+
:return: The projected vector
336+
"""
326337
assert len(other) == 2
327338
other_length_sqrd = other[0] * other[0] + other[1] * other[1]
328339
if other_length_sqrd == 0.0:
@@ -341,6 +352,10 @@ def cross(self, other: Tuple[float, float]) -> float:
341352
return self.x * other[1] - self.y * other[0]
342353

343354
def interpolate_to(self, other: Tuple[float, float], range: float) -> "Vec2d":
355+
"""Vector interpolation between the current vector and another vector.
356+
357+
:return: The interpolated vector
358+
"""
344359
assert len(other) == 2
345360
return Vec2d(
346361
self.x + (other[0] - self.x) * range, self.y + (other[1] - self.y) * range
@@ -349,6 +364,10 @@ def interpolate_to(self, other: Tuple[float, float], range: float) -> "Vec2d":
349364
def convert_to_basis(
350365
self, x_vector: Tuple[float, float], y_vector: Tuple[float, float]
351366
) -> "Vec2d":
367+
"""Converts the vector to a new basis defined by the given x and y vectors.
368+
369+
:return: Vec2d: The vector converted to the new basis.
370+
"""
352371
assert len(x_vector) == 2
353372
assert len(y_vector) == 2
354373
x = self.dot(x_vector) / Vec2d(*x_vector).get_length_sqrd()

0 commit comments

Comments
 (0)