Skip to content

Commit 5f5ecb9

Browse files
committed
Ensure that Path.arc works for any full circle.
Depending on the inputs, the range may get squashed down to ~0 when trying to remove extra 2pi revolutions. Fixes #8992.
1 parent 66270ba commit 5f5ecb9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/matplotlib/path.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False):
872872
eta1 = np.arctan2(np.sin(theta1), np.cos(theta1))
873873
eta2 = np.arctan2(np.sin(theta2), np.cos(theta2))
874874
eta2 -= twopi * np.floor((eta2 - eta1) / twopi)
875+
# Ensure 2pi range is not flattened to 0 due to floating-point errors.
876+
if theta2 - theta1 > np.pi and eta2 - eta1 < np.pi:
877+
eta2 += twopi
875878

876879
# number of curve segments to make
877880
if n is None:

lib/matplotlib/tests/test_path.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,15 @@ def test_path_deepcopy():
205205
path2 = Path(verts, codes)
206206
copy.deepcopy(path1)
207207
copy.deepcopy(path2)
208+
209+
210+
@pytest.mark.parametrize('offset', range(-720, 361, 45))
211+
def test_full_arc(offset):
212+
low = offset
213+
high = 360 + offset
214+
215+
path = Path.arc(low, high)
216+
mins = np.min(path.vertices, axis=0)
217+
maxs = np.max(path.vertices, axis=0)
218+
np.testing.assert_allclose(mins, -1)
219+
assert np.allclose(maxs, 1)

0 commit comments

Comments
 (0)