From de3ef368a557a907187438a236fd38e0bcea68d5 Mon Sep 17 00:00:00 2001 From: VeriTas-arch <145042207+VeriTas-arch@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:48:05 +0800 Subject: [PATCH 1/2] Update Vec2d class documentation --- pymunk/vec2d.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pymunk/vec2d.py b/pymunk/vec2d.py index 3e287486..78629eb6 100644 --- a/pymunk/vec2d.py +++ b/pymunk/vec2d.py @@ -314,7 +314,7 @@ def get_distance(self, other: Tuple[float, float]) -> float: def get_dist_sqrd(self, other: Tuple[float, float]) -> float: """The squared distance between the vector and other vector It is more efficent to use this method than to call get_distance() - first and then do a sqrt() on the result. + first and then do a square() on the result. :return: The squared distance """ @@ -341,6 +341,10 @@ def cross(self, other: Tuple[float, float]) -> float: return self.x * other[1] - self.y * other[0] def interpolate_to(self, other: Tuple[float, float], range: float) -> "Vec2d": + """Vector interpolation between the current vector and another vector. + + :return: The interpolated vector + """ assert len(other) == 2 return Vec2d( self.x + (other[0] - self.x) * range, self.y + (other[1] - self.y) * range @@ -349,6 +353,10 @@ def interpolate_to(self, other: Tuple[float, float], range: float) -> "Vec2d": def convert_to_basis( self, x_vector: Tuple[float, float], y_vector: Tuple[float, float] ) -> "Vec2d": + """Converts the vector to a new basis defined by the given x and y vectors. + + :return: Vec2d: The vector converted to the new basis. + """ assert len(x_vector) == 2 assert len(y_vector) == 2 x = self.dot(x_vector) / Vec2d(*x_vector).get_length_sqrd() From 3a46b2274cffa080b7031c392a0e303819269df8 Mon Sep 17 00:00:00 2001 From: VeriTas-arch <145042207+VeriTas-arch@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:59:55 +0800 Subject: [PATCH 2/2] Update Vec2d class documentation --- pymunk/vec2d.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pymunk/vec2d.py b/pymunk/vec2d.py index 78629eb6..c5a038d2 100644 --- a/pymunk/vec2d.py +++ b/pymunk/vec2d.py @@ -286,9 +286,17 @@ def normalized_and_length(self) -> Tuple["Vec2d", float]: return Vec2d(0, 0), 0 def perpendicular(self) -> "Vec2d": + """Get a vertical vector rotated 90 degrees counterclockwise from the original vector. + + :return: A new vector perpendicular to this vector. + """ return Vec2d(-self.y, self.x) def perpendicular_normal(self) -> "Vec2d": + """Get a vertical normalized vector rotated 90 degrees counterclockwise from the original vector. + + :return: A new normalized vector perpendicular to this vector. + """ length = self.length if length != 0: return Vec2d(-self.y / length, self.x / length) @@ -322,7 +330,10 @@ def get_dist_sqrd(self, other: Tuple[float, float]) -> float: return (self.x - other[0]) ** 2 + (self.y - other[1]) ** 2 def projection(self, other: Tuple[float, float]) -> "Vec2d": - """Project this vector on top of other vector""" + """Project this vector on top of other vector + + :return: The projected vector + """ assert len(other) == 2 other_length_sqrd = other[0] * other[0] + other[1] * other[1] if other_length_sqrd == 0.0: