Skip to content

Commit 7f464cc

Browse files
sparshgbehacklpre-commit-ci[bot]
authored
Fix background lines drawn twice in NumberPlane (#2634)
* fix axis lines drawn twice in numberplane * simplified and fixed test, added comments * fixed background lines drawn when both x_min, x_max are negative * regenerated control data of failing tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3413ca2 commit 7f464cc

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

manim/mobject/graphing/coordinate_systems.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,8 +2422,9 @@ def _get_lines_parallel_to_axis(
24222422
# min/max used in case range does not include 0. i.e. if (2,6):
24232423
# the range becomes (0,4), not (0,6).
24242424
ranges = (
2425-
np.arange(0, min(x_max - x_min, x_max), step),
2426-
np.arange(0, max(x_min - x_max, x_min), -step),
2425+
[0],
2426+
np.arange(step, min(x_max - x_min, x_max), step),
2427+
np.arange(-step, max(x_min - x_max, x_min), -step),
24272428
)
24282429

24292430
for inputs in ranges:

tests/test_coordinate_system.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,16 @@ def test_NumberPlane():
5555
pos_y_range = (2, 6)
5656
neg_y_range = (-6, -2)
5757

58-
x_vals = [0, 1.5, 2, 2.8, 4, 6.25]
59-
y_vals = [2, 5, 4.25, 6, 4.5, 2.75]
60-
6158
testing_data = [
62-
(pos_x_range, pos_y_range, x_vals, y_vals),
63-
(pos_x_range, neg_y_range, x_vals, [-v for v in y_vals]),
64-
(neg_x_range, pos_y_range, [-v for v in x_vals], y_vals),
65-
(neg_x_range, neg_y_range, [-v for v in x_vals], [-v for v in y_vals]),
59+
(pos_x_range, pos_y_range),
60+
(pos_x_range, neg_y_range),
61+
(neg_x_range, pos_y_range),
62+
(neg_x_range, neg_y_range),
6663
]
6764

6865
for test_data in testing_data:
6966

70-
x_range, y_range, x_vals, y_vals = test_data
67+
x_range, y_range = test_data
7168

7269
x_start, x_end = x_range
7370
y_start, y_end = y_range
@@ -89,8 +86,11 @@ def test_NumberPlane():
8986
assert len(plane.x_lines) == num_x_lines
9087

9188
plane = NumberPlane((-5, 5, 0.5), (-8, 8, 2)) # <- test for different step values
92-
assert len(plane.x_lines) == 8
93-
assert len(plane.y_lines) == 20
89+
# horizontal lines: -6 -4, -2, 0, 2, 4, 6
90+
assert len(plane.x_lines) == 7
91+
# vertical lines: 0, +-0.5, +-1, +-1.5, +-2, +-2.5,
92+
# +-3, +-3.5, +-4, +-4.5
93+
assert len(plane.y_lines) == 19
9494

9595

9696
def test_point_to_coords():
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)