Skip to content

Commit ba00602

Browse files
Fixed :meth:.CoordinateSystem.get_area when using few plot points and a boundary graph (#2244)
* make sure left and right endpoint of area are vertically above a, b * fix border when bounded_graph is passed * added test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update get_area test, also affected by changes * fix test data Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2f9e717 commit ba00602

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

manim/mobject/coordinate_systems.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,14 +1293,18 @@ def construct(self):
12931293

12941294
if bounded_graph is None:
12951295
points = (
1296-
[self.c2p(a)]
1296+
[self.c2p(a), graph.function(a)]
12971297
+ [p for p in graph.points if a <= self.p2c(p)[0] <= b]
1298-
+ [self.c2p(b)]
1298+
+ [graph.function(b), self.c2p(b)]
12991299
)
13001300
else:
1301-
points = [p for p in graph.points if a <= self.p2c(p)[0] <= b] + [
1302-
p for p in bounded_graph.points if a <= self.p2c(p)[0] <= b
1303-
][::-1]
1301+
graph_points, bounded_graph_points = (
1302+
[g.function(a)]
1303+
+ [p for p in g.points if a <= self.p2c(p)[0] <= b]
1304+
+ [g.function(b)]
1305+
for g in (graph, bounded_graph)
1306+
)
1307+
points = graph_points + bounded_graph_points[::-1]
13041308
return Polygon(*points, **kwargs).set_opacity(opacity).set_color(color)
13051309

13061310
def angle_of_tangent(
-937 Bytes
Binary file not shown.
Binary file not shown.

tests/test_graphical_units/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ def test_get_area(scene):
199199
scene.add(ax, curve1, curve2, area1, area2)
200200

201201

202+
@frames_comparison
203+
def test_get_area_with_boundary_and_few_plot_points(scene):
204+
ax = Axes(x_range=[-2, 2], y_range=[-2, 2], color=WHITE)
205+
f1 = ax.plot(lambda t: t, [-1, 1, 0.5])
206+
f2 = ax.plot(lambda t: 1, [-1, 1, 0.5])
207+
a1 = ax.get_area(f1, [-1, 0.75], color=RED)
208+
a2 = ax.get_area(f1, [-0.75, 1], bounded_graph=f2, color=GREEN)
209+
210+
scene.add(ax, f1, f2, a1, a2)
211+
212+
202213
@frames_comparison
203214
def test_get_riemann_rectangles(scene):
204215
ax = Axes(y_range=[-2, 10])

0 commit comments

Comments
 (0)