3
3
import itertools as it
4
4
import operator as op
5
5
from functools import reduce , wraps
6
- from typing import Callable , Iterable , Sequence
6
+ from typing import Callable , Iterable , Optional , Sequence
7
7
8
8
import moderngl
9
9
import numpy as np
@@ -826,12 +826,28 @@ def get_nth_curve_length(
826
826
827
827
return length
828
828
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 (
830
846
self ,
831
847
n : int ,
832
848
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 .
835
851
836
852
Parameters
837
853
----------
@@ -842,40 +858,18 @@ def get_nth_curve_function_with_length(
842
858
843
859
Returns
844
860
-------
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.
849
863
"""
850
-
851
864
if sample_points is None :
852
865
sample_points = 10
853
866
854
867
curve = self .get_nth_curve_function (n )
855
-
856
868
points = np .array ([curve (a ) for a in np .linspace (0 , 1 , sample_points )])
857
869
diffs = points [1 :] - points [:- 1 ]
858
870
norms = np .apply_along_axis (np .linalg .norm , 1 , diffs )
859
871
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
879
873
880
874
def get_curve_functions_with_lengths (
881
875
self , ** kwargs
0 commit comments