Skip to content

Commit affc719

Browse files
authored
Fixed Missing get_nth_curve_length_pieces in OpenGLVMobject (#2707)
* fix(opengl_vectorized_mobject): removed double definition of get_nth_curve_function_with_length * fix(opengl_vectorized_mobject): added definition of get_nth_curve_length_pieces from VMobject to OpenGLVMobject
1 parent 8d7e7cd commit affc719

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

manim/mobject/opengl/opengl_vectorized_mobject.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import itertools as it
44
import operator as op
55
from functools import reduce, wraps
6-
from typing import Callable, Iterable, Sequence
6+
from typing import Callable, Iterable, Optional, Sequence
77

88
import moderngl
99
import numpy as np
@@ -826,12 +826,28 @@ def get_nth_curve_length(
826826

827827
return length
828828

829-
def get_nth_curve_function_with_length(
829+
def get_curve_functions(
830+
self,
831+
) -> Iterable[Callable[[float], np.ndarray]]:
832+
"""Gets the functions for the curves of the mobject.
833+
834+
Returns
835+
-------
836+
Iterable[Callable[[float], np.ndarray]]
837+
The functions for the curves.
838+
"""
839+
840+
num_curves = self.get_num_curves()
841+
842+
for n in range(num_curves):
843+
yield self.get_nth_curve_function(n)
844+
845+
def get_nth_curve_length_pieces(
830846
self,
831847
n: int,
832848
sample_points: int | None = None,
833-
) -> tuple[Callable[[float], np.ndarray], float]:
834-
"""Returns the expression of the nth curve along with its (approximate) length.
849+
) -> np.ndarray:
850+
"""Returns the array of short line lengths used for length approximation.
835851
836852
Parameters
837853
----------
@@ -842,40 +858,18 @@ def get_nth_curve_function_with_length(
842858
843859
Returns
844860
-------
845-
curve : typing.Callable[[float], np.ndarray]
846-
The function for the nth curve.
847-
length : :class:`float`
848-
The length of the nth curve.
861+
np.ndarray
862+
The short length-pieces of the nth curve.
849863
"""
850-
851864
if sample_points is None:
852865
sample_points = 10
853866

854867
curve = self.get_nth_curve_function(n)
855-
856868
points = np.array([curve(a) for a in np.linspace(0, 1, sample_points)])
857869
diffs = points[1:] - points[:-1]
858870
norms = np.apply_along_axis(np.linalg.norm, 1, diffs)
859871

860-
length = np.sum(norms)
861-
862-
return curve, length
863-
864-
def get_curve_functions(
865-
self,
866-
) -> Iterable[Callable[[float], np.ndarray]]:
867-
"""Gets the functions for the curves of the mobject.
868-
869-
Returns
870-
-------
871-
Iterable[Callable[[float], np.ndarray]]
872-
The functions for the curves.
873-
"""
874-
875-
num_curves = self.get_num_curves()
876-
877-
for n in range(num_curves):
878-
yield self.get_nth_curve_function(n)
872+
return norms
879873

880874
def get_curve_functions_with_lengths(
881875
self, **kwargs

0 commit comments

Comments
 (0)