A community-maintained Python framework for creating mathematical animations.
Fixed :meth:`.CoordinateSystem.get_area` when using few plot points and a boundary graph (#2244)
Benjamin Hacklba00602daaa5
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.pyindex a2ef229bc..ddefc8d62 100644--- a/manim/mobject/coordinate_systems.py+++ b/manim/mobject/coordinate_systems.py@@ -1293,14 +1293,18 @@ class CoordinateSystem:if bounded_graph is None:points = (- [self.c2p(a)]+ [self.c2p(a), graph.function(a)]+ [p for p in graph.points if a <= self.p2c(p)[0] <= b]- + [self.c2p(b)]+ + [graph.function(b), self.c2p(b)])else:- points = [p for p in graph.points if a <= self.p2c(p)[0] <= b] + [- p for p in bounded_graph.points if a <= self.p2c(p)[0] <= b- ][::-1]+ graph_points, bounded_graph_points = (+ [g.function(a)]+ + [p for p in g.points if a <= self.p2c(p)[0] <= b]+ + [g.function(b)]+ for g in (graph, bounded_graph)+ )+ points = graph_points + bounded_graph_points[::-1]return Polygon(*points, **kwargs).set_opacity(opacity).set_color(color)def angle_of_tangent(diff --git a/tests/control_data/graphical_units_data/plot/get_area.npz b/tests/control_data/graphical_units_data/plot/get_area.npzindex 86f986ed4..0a7a70785 100644Binary files a/tests/control_data/graphical_units_data/plot/get_area.npz and b/tests/control_data/graphical_units_data/plot/get_area.npz differdiff --git a/tests/control_data/graphical_units_data/plot/get_area_with_boundary_and_few_plot_points.npz b/tests/control_data/graphical_units_data/plot/get_area_with_boundary_and_few_plot_points.npznew file mode 100644index 000000000..282bbe1c4Binary files /dev/null and b/tests/control_data/graphical_units_data/plot/get_area_with_boundary_and_few_plot_points.npz differdiff --git a/tests/test_graphical_units/test_axes.py b/tests/test_graphical_units/test_axes.pyindex 929377f27..a4412e8c2 100644--- a/tests/test_graphical_units/test_axes.py+++ b/tests/test_graphical_units/test_axes.py@@ -199,6 +199,17 @@ def test_get_area(scene):scene.add(ax, curve1, curve2, area1, area2)+@frames_comparison+def test_get_area_with_boundary_and_few_plot_points(scene):+ ax = Axes(x_range=[-2, 2], y_range=[-2, 2], color=WHITE)+ f1 = ax.plot(lambda t: t, [-1, 1, 0.5])+ f2 = ax.plot(lambda t: 1, [-1, 1, 0.5])+ a1 = ax.get_area(f1, [-1, 0.75], color=RED)+ a2 = ax.get_area(f1, [-0.75, 1], bounded_graph=f2, color=GREEN)++ scene.add(ax, f1, f2, a1, a2)++@frames_comparisondef test_get_riemann_rectangles(scene):ax = Axes(y_range=[-2, 10])