From ca0e471de2c4b8f789ea2954e1ad23becbd0fb1c Mon Sep 17 00:00:00 2001 From: Jinchu Li Date: Mon, 10 Apr 2023 01:14:08 -0400 Subject: [PATCH 1/7] changed return type of get_anchors() --- manim/mobject/types/vectorized_mobject.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index b5cf76ec08..4515b2a1ca 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1392,7 +1392,7 @@ def get_end_anchors(self) -> np.ndarray: nppcc = self.n_points_per_cubic_curve return self.points[nppcc - 1 :: nppcc] - def get_anchors(self) -> np.ndarray: + def get_anchors(self) -> typing.Iterable[np.ndarray]: """Returns the anchors of the curves forming the VMobject. Returns @@ -1402,9 +1402,10 @@ def get_anchors(self) -> np.ndarray: """ if self.points.shape[0] == 1: return self.points - return np.array( - list(it.chain(*zip(self.get_start_anchors(), self.get_end_anchors()))), - ) + + s = self.get_start_anchors() + e = self.get_end_anchors() + return [s[i // 2] if i % 2 == 0 else e[i // 2] for i in range(len(s) + len(e))] def get_points_defining_boundary(self): # Probably returns all anchors, but this is weird regarding the name of the method. From 5e7d7d1f11563c2d4509f1b93184ccf782c00f9e Mon Sep 17 00:00:00 2001 From: Jinchu Li Date: Tue, 11 Apr 2023 12:03:20 -0400 Subject: [PATCH 2/7] Ensured consistency with OpenGLVMobject --- .../opengl/opengl_vectorized_mobject.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index 8858a422f6..31a12cb7b5 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -2,6 +2,7 @@ import itertools as it import operator as op +import typing from functools import reduce, wraps from typing import Callable, Iterable, Optional, Sequence @@ -1013,7 +1014,7 @@ def proportion_from_point( return alpha - def get_anchors_and_handles(self): + def get_anchors_and_handles(self) -> typing.Iterable[np.ndarray]: """ Returns anchors1, handles, anchors2, where (anchors1[i], handles[i], anchors2[i]) @@ -1045,7 +1046,7 @@ def get_end_anchors(self) -> np.ndarray: nppc = self.n_points_per_curve return self.points[nppc - 1 :: nppc] - def get_anchors(self) -> np.ndarray: + def get_anchors(self) -> typing.Iterable[np.ndarray]: """Returns the anchors of the curves forming the OpenGLVMobject. Returns @@ -1056,16 +1057,10 @@ def get_anchors(self) -> np.ndarray: points = self.points if len(points) == 1: return points - return np.array( - list( - it.chain( - *zip( - self.get_start_anchors(), - self.get_end_anchors(), - ) - ), - ), - ) + + s = self.get_start_anchors() + e = self.get_end_anchors() + return [s[i // 2] if i % 2 == 0 else e[i // 2] for i in range(len(s) + len(e))] def get_points_without_null_curves(self, atol=1e-9): nppc = self.n_points_per_curve From d2d611046615c6c0c08cf73d5b9023e663c00d59 Mon Sep 17 00:00:00 2001 From: Jinchu Li Date: Tue, 11 Apr 2023 13:39:15 -0400 Subject: [PATCH 3/7] Fixed CodeQl, updated docstring --- manim/mobject/opengl/opengl_vectorized_mobject.py | 7 +++---- manim/mobject/types/vectorized_mobject.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index 31a12cb7b5..e8865faabf 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -2,7 +2,6 @@ import itertools as it import operator as op -import typing from functools import reduce, wraps from typing import Callable, Iterable, Optional, Sequence @@ -1014,7 +1013,7 @@ def proportion_from_point( return alpha - def get_anchors_and_handles(self) -> typing.Iterable[np.ndarray]: + def get_anchors_and_handles(self) -> Iterable[np.ndarray]: """ Returns anchors1, handles, anchors2, where (anchors1[i], handles[i], anchors2[i]) @@ -1046,12 +1045,12 @@ def get_end_anchors(self) -> np.ndarray: nppc = self.n_points_per_curve return self.points[nppc - 1 :: nppc] - def get_anchors(self) -> typing.Iterable[np.ndarray]: + def get_anchors(self) -> Iterable[np.ndarray]: """Returns the anchors of the curves forming the OpenGLVMobject. Returns ------- - np.ndarray + Iterable[np.ndarray] The anchors. """ points = self.points diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 4515b2a1ca..fd6e8708e7 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1397,7 +1397,7 @@ def get_anchors(self) -> typing.Iterable[np.ndarray]: Returns ------- - np.ndarray + typing.Iterable[np.ndarray] The anchors. """ if self.points.shape[0] == 1: From 8cbc5c0e97f8a87753f0d877491ac7b5d6b8d7ae Mon Sep 17 00:00:00 2001 From: Tristan Schulz Date: Sat, 5 Aug 2023 02:39:42 +0200 Subject: [PATCH 4/7] Update manim/mobject/types/vectorized_mobject.py Co-authored-by: Benjamin Hackl --- manim/mobject/types/vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index fd6e8708e7..d859c47305 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1405,7 +1405,7 @@ def get_anchors(self) -> typing.Iterable[np.ndarray]: s = self.get_start_anchors() e = self.get_end_anchors() - return [s[i // 2] if i % 2 == 0 else e[i // 2] for i in range(len(s) + len(e))] + return list(it.chain.from_iterable(zip(s, e))) def get_points_defining_boundary(self): # Probably returns all anchors, but this is weird regarding the name of the method. From 7e0c533b18ef4d18e1e7d5dbde3147c0d1faeb48 Mon Sep 17 00:00:00 2001 From: Tristan Schulz Date: Sat, 5 Aug 2023 02:39:48 +0200 Subject: [PATCH 5/7] Update manim/mobject/opengl/opengl_vectorized_mobject.py Co-authored-by: Benjamin Hackl --- manim/mobject/opengl/opengl_vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index e8865faabf..f306b8d109 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -1059,7 +1059,7 @@ def get_anchors(self) -> Iterable[np.ndarray]: s = self.get_start_anchors() e = self.get_end_anchors() - return [s[i // 2] if i % 2 == 0 else e[i // 2] for i in range(len(s) + len(e))] + return list(it.chain.from_iterable(zip(s, t))) def get_points_without_null_curves(self, atol=1e-9): nppc = self.n_points_per_curve From b7d0b8b27a5f66c02ba29c27fe22a5f6ed2d9067 Mon Sep 17 00:00:00 2001 From: Benjamin Hackl Date: Thu, 25 Apr 2024 00:17:27 +0200 Subject: [PATCH 6/7] fixed typo, t -> e --- manim/mobject/opengl/opengl_vectorized_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index c22157ae26..187a204639 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -1060,7 +1060,7 @@ def get_anchors(self) -> Iterable[np.ndarray]: s = self.get_start_anchors() e = self.get_end_anchors() - return list(it.chain.from_iterable(zip(s, t))) + return list(it.chain.from_iterable(zip(s, e))) def get_points_without_null_curves(self, atol=1e-9): nppc = self.n_points_per_curve From 57bf3e0f3952679b5ac25fc4d3b099ce9143abf3 Mon Sep 17 00:00:00 2001 From: Benjamin Hackl Date: Sat, 27 Apr 2024 23:33:29 +0200 Subject: [PATCH 7/7] fixed doctest --- manim/mobject/mobject.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 40bcd46336..9127c2a1d6 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -2836,7 +2836,8 @@ def construct(self): >>> result = rect.copy().become(circ, stretch=True) >>> result.height, result.width (2.0, 4.0) - >>> ellipse_eq = np.sum(result.get_anchors()**2 * [1/4, 1, 0], axis=1) + >>> ellipse_points = np.array(result.get_anchors()) + >>> ellipse_eq = np.sum(ellipse_points**2 * [1/4, 1, 0], axis=1) >>> np.allclose(ellipse_eq, 1) True @@ -2849,13 +2850,15 @@ def construct(self): >>> result = rect.copy().become(circ, match_height=True) >>> result.height, result.width (2.0, 2.0) - >>> circle_eq = np.sum(result.get_anchors()**2, axis=1) + >>> circle_points = np.array(result.get_anchors()) + >>> circle_eq = np.sum(circle_points**2, axis=1) >>> np.allclose(circle_eq, 1) True >>> result = rect.copy().become(circ, match_width=True) >>> result.height, result.width (4.0, 4.0) - >>> circle_eq = np.sum(result.get_anchors()**2, axis=1) + >>> circle_points = np.array(result.get_anchors()) + >>> circle_eq = np.sum(circle_points**2, axis=1) >>> np.allclose(circle_eq, 2**2) True