Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed Missing `get_nth_curve_length_pieces` in `OpenGLVMobject` (#2707)

Tristan Schulzaffc719a634b
diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py
index 643a26da9..c866eb2bf 100644
--- a/manim/mobject/opengl/opengl_vectorized_mobject.py
+++ b/manim/mobject/opengl/opengl_vectorized_mobject.py
@@ -3,7 +3,7 @@ from __future__ import annotations
import itertools as it
import operator as op
from functools import reduce, wraps
-from typing import Callable, Iterable, Sequence
+from typing import Callable, Iterable, Optional, Sequence
import moderngl
import numpy as np
@@ -826,12 +826,28 @@ class OpenGLVMobject(OpenGLMobject):
return length
- def get_nth_curve_function_with_length(
+ def get_curve_functions(
+ self,
+ ) -> Iterable[Callable[[float], np.ndarray]]:
+ """Gets the functions for the curves of the mobject.
+
+ Returns
+ -------
+ Iterable[Callable[[float], np.ndarray]]
+ The functions for the curves.
+ """
+
+ num_curves = self.get_num_curves()
+
+ for n in range(num_curves):
+ yield self.get_nth_curve_function(n)
+
+ def get_nth_curve_length_pieces(
self,
n: int,
sample_points: int | None = None,
- ) -> tuple[Callable[[float], np.ndarray], float]:
- """Returns the expression of the nth curve along with its (approximate) length.
+ ) -> np.ndarray:
+ """Returns the array of short line lengths used for length approximation.
Parameters
----------
@@ -842,40 +858,18 @@ class OpenGLVMobject(OpenGLMobject):
Returns
-------
- curve : typing.Callable[[float], np.ndarray]
- The function for the nth curve.
- length : :class:`float`
- The length of the nth curve.
+ np.ndarray
+ The short length-pieces of the nth curve.
"""
-
if sample_points is None:
sample_points = 10
curve = self.get_nth_curve_function(n)
-
points = np.array([curve(a) for a in np.linspace(0, 1, sample_points)])
diffs = points[1:] - points[:-1]
norms = np.apply_along_axis(np.linalg.norm, 1, diffs)
- length = np.sum(norms)
-
- return curve, length
-
- def get_curve_functions(
- self,
- ) -> Iterable[Callable[[float], np.ndarray]]:
- """Gets the functions for the curves of the mobject.
-
- Returns
- -------
- Iterable[Callable[[float], np.ndarray]]
- The functions for the curves.
- """
-
- num_curves = self.get_num_curves()
-
- for n in range(num_curves):
- yield self.get_nth_curve_function(n)
+ return norms
def get_curve_functions_with_lengths(
self, **kwargs