Skip to content

Commit

Permalink
Enhancement: Remove redundancy in FunctionGraph arguments (3b1b#1018)
Browse files Browse the repository at this point in the history
* Fix x_min, x_max and color of FunctionGraph

* Add graphical unit test to FunctionGraph

* Apply review suggestions

* Pass color as argument instead of updating kwargs and run black
  • Loading branch information
abhijithmuthyala committed Feb 14, 2021
1 parent 3ad385a commit dd74b00
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
17 changes: 13 additions & 4 deletions manim/mobject/functions.py
Expand Up @@ -119,12 +119,21 @@ def generate_points(self):


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_max
self.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 = function

Expand Down
Binary file not shown.
23 changes: 23 additions & 0 deletions 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"


@pytest.mark.parametrize("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)

0 comments on commit dd74b00

Please sign in to comment.