Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4cb1dbd

Browse files
committed
Add RuntimeWarning guard.
1 parent 7aed240 commit 4cb1dbd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ def _line2d_seg_dist(p1, p2, p0):
1717
and intersection point lies within segment if u is between 0 and 1
1818
"""
1919

20-
x21 = p2[0] - p1[0]
21-
y21 = p2[1] - p1[1]
2220
x01 = np.asarray(p0[0]) - p1[0]
2321
y01 = np.asarray(p0[1]) - p1[1]
22+
if p1 == p2: # Avoid RuntimeWarning
23+
return np.hypot(x01, y01)
2424

25+
x21 = p2[0] - p1[0]
26+
y21 = p2[1] - p1[1]
2527
u = (x01*x21 + y01*y21) / (x21**2 + y21**2)
2628
u = np.clip(u, 0, 1)
2729
d = np.hypot(x01 - u*x21, y01 - u*y21)

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,14 @@ def test_lines_dists():
10021002
ax.set_ylim(0, 300)
10031003

10041004

1005+
def test_lines_dists_nowarning():
1006+
# Smoke test to see that no RuntimeWarning is emitted when two first
1007+
# arguments are the same, see GH#22624
1008+
p0 = (10, 30)
1009+
p1 = (20, 150)
1010+
proj3d._line2d_seg_dist(p0, p0, p1)
1011+
1012+
10051013
def test_autoscale():
10061014
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
10071015
ax.margins(x=0, y=.1, z=.2)

0 commit comments

Comments
 (0)