Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed get_anchors() Return Type Inconsistency #3214

Merged
merged 9 commits into from
Apr 27, 2024
9 changes: 6 additions & 3 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
20 changes: 7 additions & 13 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ def proportion_from_point(

return alpha

def get_anchors_and_handles(self):
def get_anchors_and_handles(self) -> Iterable[np.ndarray]:
"""
Returns anchors1, handles, anchors2,
where (anchors1[i], handles[i], anchors2[i])
Expand Down Expand Up @@ -1057,27 +1057,21 @@ 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) -> Iterable[np.ndarray]:
"""Returns the anchors of the curves forming the OpenGLVMobject.

Returns
-------
np.ndarray
Iterable[np.ndarray]
The anchors.
"""
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()
Fixed Show fixed Hide fixed
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
Expand Down
7 changes: 4 additions & 3 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,9 +1553,10 @@ def get_anchors(self) -> Point3D_Array:
"""
if self.points.shape[0] == 1:
return self.points
return np.array(
tuple(it.chain(*zip(self.get_start_anchors(), self.get_end_anchors()))),
)

s = self.get_start_anchors()
e = self.get_end_anchors()
return list(it.chain.from_iterable(zip(s, e)))

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