Skip to content

Commit c4e7502

Browse files
JinchuLi2002MrDiverbehacklchopan050
authored
Fixed get_anchors() Return Type Inconsistency (#3214)
* changed return type of get_anchors() * Ensured consistency with OpenGLVMobject * Fixed CodeQl, updated docstring * Update manim/mobject/types/vectorized_mobject.py Co-authored-by: Benjamin Hackl <[email protected]> * Update manim/mobject/opengl/opengl_vectorized_mobject.py Co-authored-by: Benjamin Hackl <[email protected]> * fixed typo, t -> e * fixed doctest --------- Co-authored-by: Tristan Schulz <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Francisco Manríquez Novoa <[email protected]>
1 parent 1ce3edd commit c4e7502

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

manim/mobject/mobject.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,7 +2836,8 @@ def construct(self):
28362836
>>> result = rect.copy().become(circ, stretch=True)
28372837
>>> result.height, result.width
28382838
(2.0, 4.0)
2839-
>>> ellipse_eq = np.sum(result.get_anchors()**2 * [1/4, 1, 0], axis=1)
2839+
>>> ellipse_points = np.array(result.get_anchors())
2840+
>>> ellipse_eq = np.sum(ellipse_points**2 * [1/4, 1, 0], axis=1)
28402841
>>> np.allclose(ellipse_eq, 1)
28412842
True
28422843
@@ -2849,13 +2850,15 @@ def construct(self):
28492850
>>> result = rect.copy().become(circ, match_height=True)
28502851
>>> result.height, result.width
28512852
(2.0, 2.0)
2852-
>>> circle_eq = np.sum(result.get_anchors()**2, axis=1)
2853+
>>> circle_points = np.array(result.get_anchors())
2854+
>>> circle_eq = np.sum(circle_points**2, axis=1)
28532855
>>> np.allclose(circle_eq, 1)
28542856
True
28552857
>>> result = rect.copy().become(circ, match_width=True)
28562858
>>> result.height, result.width
28572859
(4.0, 4.0)
2858-
>>> circle_eq = np.sum(result.get_anchors()**2, axis=1)
2860+
>>> circle_points = np.array(result.get_anchors())
2861+
>>> circle_eq = np.sum(circle_points**2, axis=1)
28592862
>>> np.allclose(circle_eq, 2**2)
28602863
True
28612864

manim/mobject/opengl/opengl_vectorized_mobject.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def proportion_from_point(
10251025

10261026
return alpha
10271027

1028-
def get_anchors_and_handles(self):
1028+
def get_anchors_and_handles(self) -> Iterable[np.ndarray]:
10291029
"""
10301030
Returns anchors1, handles, anchors2,
10311031
where (anchors1[i], handles[i], anchors2[i])
@@ -1057,27 +1057,21 @@ def get_end_anchors(self) -> np.ndarray:
10571057
nppc = self.n_points_per_curve
10581058
return self.points[nppc - 1 :: nppc]
10591059

1060-
def get_anchors(self) -> np.ndarray:
1060+
def get_anchors(self) -> Iterable[np.ndarray]:
10611061
"""Returns the anchors of the curves forming the OpenGLVMobject.
10621062
10631063
Returns
10641064
-------
1065-
np.ndarray
1065+
Iterable[np.ndarray]
10661066
The anchors.
10671067
"""
10681068
points = self.points
10691069
if len(points) == 1:
10701070
return points
1071-
return np.array(
1072-
list(
1073-
it.chain(
1074-
*zip(
1075-
self.get_start_anchors(),
1076-
self.get_end_anchors(),
1077-
)
1078-
),
1079-
),
1080-
)
1071+
1072+
s = self.get_start_anchors()
1073+
e = self.get_end_anchors()
1074+
return list(it.chain.from_iterable(zip(s, e)))
10811075

10821076
def get_points_without_null_curves(self, atol=1e-9):
10831077
nppc = self.n_points_per_curve

manim/mobject/types/vectorized_mobject.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,9 +1553,10 @@ def get_anchors(self) -> Point3D_Array:
15531553
"""
15541554
if self.points.shape[0] == 1:
15551555
return self.points
1556-
return np.array(
1557-
tuple(it.chain(*zip(self.get_start_anchors(), self.get_end_anchors()))),
1558-
)
1556+
1557+
s = self.get_start_anchors()
1558+
e = self.get_end_anchors()
1559+
return list(it.chain.from_iterable(zip(s, e)))
15591560

15601561
def get_points_defining_boundary(self) -> Point3D_Array:
15611562
# Probably returns all anchors, but this is weird regarding the name of the method.

0 commit comments

Comments
 (0)