A community-maintained Python framework for creating mathematical animations.
Enhancement: Remove redundancy in FunctionGraph arguments (#1018)
Abhijith Muthyaladd74b0017272
diff --git a/manim/mobject/functions.py b/manim/mobject/functions.pyindex a73c1c984..0cb08990a 100644--- a/manim/mobject/functions.py+++ b/manim/mobject/functions.py@@ -119,12 +119,21 @@ class ParametricFunction(VMobject):class FunctionGraph(ParametricFunction):- def __init__(self, function, color=YELLOW, **kwargs):- self.x_min = -config["frame_x_radius"]- self.x_max = config["frame_x_radius"]+ def __init__(self, function, x_min=None, x_max=None, color=YELLOW, **kwargs):+ if x_min is None:+ x_min = -config["frame_x_radius"]+ if x_max is None:+ x_max = config["frame_x_radius"]+ self.x_min = x_min+ self.x_max = x_maxself.parametric_function = lambda t: np.array([t, function(t), 0])ParametricFunction.__init__(- self, self.parametric_function, t_min=self.x_min, t_max=self.x_max, **kwargs+ self,+ self.parametric_function,+ t_min=self.x_min,+ t_max=self.x_max,+ color=color,+ **kwargs)self.function = functiondiff --git a/tests/control_data/graphical_units_data/functions/FunctionGraphTest.npz b/tests/control_data/graphical_units_data/functions/FunctionGraphTest.npznew file mode 100644index 000000000..c414a552dBinary files /dev/null and b/tests/control_data/graphical_units_data/functions/FunctionGraphTest.npz differdiff --git a/tests/test_graphical_units/test_functions.py b/tests/test_graphical_units/test_functions.pynew file mode 100644index 000000000..b5db37c79--- /dev/null+++ b/tests/test_graphical_units/test_functions.py@@ -0,0 +1,23 @@+import pytest+import numpy as np++from manim import *+from ..utils.testing_utils import get_scenes_to_test+from ..utils.GraphicalUnitTester import GraphicalUnitTester+++class FunctionGraphTest(Scene):+ def construct(self):+ graph = FunctionGraph(+ lambda x: 2 * np.cos(0.5 * x), x_min=-PI, x_max=PI, color=BLUE+ )+ self.add(graph)+ self.wait()+++MODULE_NAME = "functions"++[email protected]("scene_to_test", get_scenes_to_test(__name__), indirect=False)+def test_scene(scene_to_test, tmpdir, show_diff):+ GraphicalUnitTester(scene_to_test[1], MODULE_NAME, tmpdir).test(show_diff=show_diff)