Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 19d7c4a

Browse filesBrowse files
committed
Add RuntimeWarning guard.
1 parent 7aed240 commit 19d7c4a
Copy full SHA for 19d7c4a

File tree

Expand file treeCollapse file tree

2 files changed

+13
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-5
lines changed

‎lib/mpl_toolkits/mplot3d/proj3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/proj3d.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ 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)
27-
d = np.hypot(x01 - u*x21, y01 - u*y21)
28-
29-
return d
29+
return np.hypot(x01 - u*x21, y01 - u*y21)
3030

3131

3232
def world_transformation(xmin, xmax,

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.