Skip to content

Commit

Permalink
Fixed get_anchors() Return Type Inconsistency (#3214)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Apr 27, 2024
1 parent 1ce3edd commit c4e7502
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
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()
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

0 comments on commit c4e7502

Please sign in to comment.