From 4b1778a5fae3d48c53b7ee46105fceb526bb077c Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Sun, 14 Apr 2024 22:49:06 -0700 Subject: [PATCH 01/11] Update documentation and typings for ParametricFunction --- manim/mobject/graphing/functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index 970ddb0ce6..0bb4234257 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -23,7 +23,7 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL): Parameters ---------- function - The function to be plotted in the form of ``(lambda x: x**2)`` + The function to be plotted in the form of ``(lambda t: (x(t), y(t), z(t)))`` t_range Determines the length that the function spans. By default ``[0, 1]`` scaling @@ -97,8 +97,8 @@ def construct(self): def __init__( self, - function: Callable[[float, float], float], - t_range: Sequence[float] | None = None, + function: Callable[[float], Sequence[float] | np.ndarray], + t_range: Sequence[float] | np.ndarray | None = None, scaling: _ScaleBase = LinearBase(), dt: float = 1e-8, discontinuities: Iterable[float] | None = None, From 3f276d71849c6777adda30fc1a73a72413e987be Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Mon, 15 Apr 2024 09:02:15 -0700 Subject: [PATCH 02/11] Use manim tyings Co-authored-by: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> --- manim/mobject/graphing/functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index 0bb4234257..f611a1e823 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -97,8 +97,8 @@ def construct(self): def __init__( self, - function: Callable[[float], Sequence[float] | np.ndarray], - t_range: Sequence[float] | np.ndarray | None = None, + function: Callable[[float], Point3D], + t_range: Sequence[float] | npt.NDArray | None = None, scaling: _ScaleBase = LinearBase(), dt: float = 1e-8, discontinuities: Iterable[float] | None = None, From dc17e5ccbe40fc0c8bed09cbb1c53b2d43071ffc Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Mon, 15 Apr 2024 09:11:04 -0700 Subject: [PATCH 03/11] fix typings --- manim/mobject/graphing/functions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index f611a1e823..c530f9f02a 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -8,12 +8,14 @@ from typing import Callable, Iterable, Sequence import numpy as np +import numpy.typing as npt from isosurfaces import plot_isoline from manim import config from manim.mobject.graphing.scale import LinearBase, _ScaleBase from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL from manim.mobject.types.vectorized_mobject import VMobject +from manim.typing import Point2D, Point3D from manim.utils.color import YELLOW @@ -98,7 +100,7 @@ def construct(self): def __init__( self, function: Callable[[float], Point3D], - t_range: Sequence[float] | npt.NDArray | None = None, + t_range: Point2D | None = None, scaling: _ScaleBase = LinearBase(), dt: float = 1e-8, discontinuities: Iterable[float] | None = None, From d860e52d7b336ac1a6d8346f139fecc9d36be2c3 Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Mon, 15 Apr 2024 13:25:20 -0700 Subject: [PATCH 04/11] a few doc fixes --- manim/mobject/graphing/functions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index c530f9f02a..7c9d64374e 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -8,7 +8,6 @@ from typing import Callable, Iterable, Sequence import numpy as np -import numpy.typing as npt from isosurfaces import plot_isoline from manim import config @@ -27,7 +26,7 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL): function The function to be plotted in the form of ``(lambda t: (x(t), y(t), z(t)))`` t_range - Determines the length that the function spans. By default ``[0, 1]`` + Determines the length that the function spans in the form of [t_min, t_max, step=0.01]. By default ``[0, 1]`` scaling Scaling class applied to the points of the function. Default of :class:`~.LinearBase`. use_smoothing From 4a34c9f889433877710e7b67c5573b95062c4880 Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Thu, 18 Apr 2024 08:01:32 -0700 Subject: [PATCH 05/11] Update manim/mobject/graphing/functions.py Co-authored-by: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> --- manim/mobject/graphing/functions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index 7c9d64374e..f3f9001e3e 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -14,7 +14,8 @@ from manim.mobject.graphing.scale import LinearBase, _ScaleBase from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL from manim.mobject.types.vectorized_mobject import VMobject -from manim.typing import Point2D, Point3D +if TYPE_CHECKING: + from manim.typing import Point2D, Point3D from manim.utils.color import YELLOW From 99efc2324c3ca839dd887ac7545c491ceabf082d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:02:11 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/graphing/functions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index f3f9001e3e..5193d3b3a7 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -14,8 +14,10 @@ from manim.mobject.graphing.scale import LinearBase, _ScaleBase from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL from manim.mobject.types.vectorized_mobject import VMobject + if TYPE_CHECKING: from manim.typing import Point2D, Point3D + from manim.utils.color import YELLOW From af93c23d65cfd02e3ca8e5689f8075e5409e375f Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Thu, 18 Apr 2024 08:02:16 -0700 Subject: [PATCH 07/11] update typings --- manim/mobject/graphing/functions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index f3f9001e3e..1234179ed6 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -14,8 +14,10 @@ from manim.mobject.graphing.scale import LinearBase, _ScaleBase from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL from manim.mobject.types.vectorized_mobject import VMobject + if TYPE_CHECKING: from manim.typing import Point2D, Point3D + from manim.utils.color import YELLOW @@ -27,7 +29,7 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL): function The function to be plotted in the form of ``(lambda t: (x(t), y(t), z(t)))`` t_range - Determines the length that the function spans in the form of [t_min, t_max, step=0.01]. By default ``[0, 1]`` + Determines the length that the function spans in the form of (t_min, t_max, step=0.01). By default ``[0, 1]`` scaling Scaling class applied to the points of the function. Default of :class:`~.LinearBase`. use_smoothing @@ -100,7 +102,7 @@ def construct(self): def __init__( self, function: Callable[[float], Point3D], - t_range: Point2D | None = None, + t_range: Point2D | Point3D = (0, 1), scaling: _ScaleBase = LinearBase(), dt: float = 1e-8, discontinuities: Iterable[float] | None = None, @@ -109,7 +111,7 @@ def __init__( **kwargs, ): self.function = function - t_range = [0, 1, 0.01] if t_range is None else t_range + t_range = (0, 1, 0.01) if t_range is None else t_range if len(t_range) == 2: t_range = np.array([*t_range, 0.01]) From 63b3a4f529fbaa988daccc68e97d9ed8b1c65639 Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Thu, 18 Apr 2024 08:04:18 -0700 Subject: [PATCH 08/11] remove extraneous line --- manim/mobject/graphing/functions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index 1234179ed6..0bd1d2ee6e 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -111,7 +111,6 @@ def __init__( **kwargs, ): self.function = function - t_range = (0, 1, 0.01) if t_range is None else t_range if len(t_range) == 2: t_range = np.array([*t_range, 0.01]) From 9ef00017a3e64a07c22f40d97c4c75403f118591 Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Thu, 18 Apr 2024 08:06:38 -0700 Subject: [PATCH 09/11] update example code --- manim/mobject/graphing/functions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index 0bd1d2ee6e..d92b0e41ce 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -53,10 +53,10 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL): class PlotParametricFunction(Scene): def func(self, t): - return np.array((np.sin(2 * t), np.sin(3 * t), 0)) + return (np.sin(2 * t), np.sin(3 * t), 0) def construct(self): - func = ParametricFunction(self.func, t_range = np.array([0, TAU]), fill_opacity=0).set_color(RED) + func = ParametricFunction(self.func, t_range = (0, TAU), fill_opacity=0).set_color(RED) self.add(func.scale(3)) .. manim:: ThreeDParametricSpring @@ -65,11 +65,11 @@ def construct(self): class ThreeDParametricSpring(ThreeDScene): def construct(self): curve1 = ParametricFunction( - lambda u: np.array([ + lambda u: ( 1.2 * np.cos(u), 1.2 * np.sin(u), u * 0.05 - ]), color=RED, t_range = np.array([-3*TAU, 5*TAU, 0.01]) + ), color=RED, t_range = (-3*TAU, 5*TAU, 0.01) ).set_shade_in_3d(True) axes = ThreeDAxes() self.add(axes, curve1) From 87bb2d5242c89feefc6513c318e34cf823fe8cd2 Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Thu, 18 Apr 2024 08:08:55 -0700 Subject: [PATCH 10/11] add line back for comptibility --- manim/mobject/graphing/functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index d92b0e41ce..a0c75416ab 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -111,6 +111,7 @@ def __init__( **kwargs, ): self.function = function + t_range = (0, 1, 0.01) if t_range is None else t_range if len(t_range) == 2: t_range = np.array([*t_range, 0.01]) From e52f99d41bc651c403a319a8ded6a34f71ceffa5 Mon Sep 17 00:00:00 2001 From: Daniel Zhu Date: Thu, 18 Apr 2024 08:14:52 -0700 Subject: [PATCH 11/11] import TYPE_CHECKING --- manim/mobject/graphing/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/graphing/functions.py b/manim/mobject/graphing/functions.py index a0c75416ab..aae20c2e59 100644 --- a/manim/mobject/graphing/functions.py +++ b/manim/mobject/graphing/functions.py @@ -5,7 +5,7 @@ __all__ = ["ParametricFunction", "FunctionGraph", "ImplicitFunction"] -from typing import Callable, Iterable, Sequence +from typing import TYPE_CHECKING, Callable, Iterable, Sequence import numpy as np from isosurfaces import plot_isoline