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 e6e20e3

Browse filesBrowse files
authored
Merge pull request #22628 from oscargus/proj3derrorstate
Add RuntimeWarning guard around division-by-zero
2 parents a5fec21 + 503d7b9 commit e6e20e3
Copy full SHA for e6e20e3

File tree

Expand file treeCollapse file tree

2 files changed

+17
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-3
lines changed

‎lib/mpl_toolkits/mplot3d/proj3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/proj3d.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ def _line2d_seg_dist(p1, p2, p0):
1414
p0[1] = y(s)
1515
1616
intersection point p = p1 + u*(p2-p1)
17-
and intersection point lies within segment if u is between 0 and 1
17+
and intersection point lies within segment if u is between 0 and 1.
18+
19+
If p1 and p2 are identical, the distance between them and p0 is returned.
1820
"""
1921

20-
x21 = p2[0] - p1[0]
21-
y21 = p2[1] - p1[1]
2222
x01 = np.asarray(p0[0]) - p1[0]
2323
y01 = np.asarray(p0[1]) - p1[1]
24+
if np.all(p1 == p2):
25+
return np.hypot(x01, y01)
2426

27+
x21 = p2[0] - p1[0]
28+
y21 = p2[1] - p1[1]
2529
u = (x01*x21 + y01*y21) / (x21**2 + y21**2)
2630
u = np.clip(u, 0, 1)
2731
d = np.hypot(x01 - u*x21, y01 - u*y21)

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,16 @@ 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+
p0 = np.array(p0)
1012+
proj3d._line2d_seg_dist(p0, p0, p1)
1013+
1014+
10051015
def test_autoscale():
10061016
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
10071017
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.