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

Skip to content

Commit b834f3f

Browse files
committed
Remove mlab.dist, mlab.dist_point_to_segment
1 parent aed15da commit b834f3f

File tree

4 files changed

+31
-42
lines changed

4 files changed

+31
-42
lines changed

doc/api/next_api_changes/2018-09-18-DS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ in Matplotlib 2.2 has been removed. See below for a list:
1919
- `mlab.bivariate_normal`
2020
- `mlab.get_xyz_where`
2121
- `mlab.get_sparse_matrix`
22+
- `mlab.dist` (use numpy.hypot instead)
23+
- `mlab.dist_point_to_segment`
2224
- `mlab.donothing_callback`

examples/event_handling/poly_editor.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import numpy as np
1010
from matplotlib.lines import Line2D
1111
from matplotlib.artist import Artist
12-
from matplotlib.mlab import dist_point_to_segment
1312

1413

1514
class PolygonInteractor(object):
@@ -85,6 +84,32 @@ def get_ind_under_point(self, event):
8584

8685
return ind
8786

87+
def dist(self, x, y):
88+
"""
89+
Return the distance between two points.
90+
"""
91+
d = x-y
92+
return np.sqrt(np.dot(d, d))
93+
94+
def dist_point_to_segment(self, p, s0, s1):
95+
"""
96+
Get the distance of a point to a segment.
97+
*p*, *s0*, *s1* are *xy* sequences
98+
This algorithm from
99+
http://geomalgorithms.com/a02-_lines.html
100+
"""
101+
v = s1 - s0
102+
w = p - s0
103+
c1 = np.dot(w, v)
104+
if c1 <= 0:
105+
return self.dist(p, s0)
106+
c2 = np.dot(v, v)
107+
if c2 <= c1:
108+
return self.dist(p, s1)
109+
b = c1 / c2
110+
pb = s0 + b * v
111+
return self.dist(p, pb)
112+
88113
def button_press_callback(self, event):
89114
'whenever a mouse button is pressed'
90115
if not self.showverts:
@@ -124,7 +149,7 @@ def key_press_callback(self, event):
124149
for i in range(len(xys) - 1):
125150
s0 = xys[i]
126151
s1 = xys[i + 1]
127-
d = dist_point_to_segment(p, s0, s1)
152+
d = self.dist_point_to_segment(p, s0, s1)
128153
if d <= self.epsilon:
129154
self.poly.xy = np.insert(
130155
self.poly.xy, i+1,

lib/matplotlib/mlab.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,44 +1194,6 @@ def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none, window=window_hanning,
11941194
return Cxy, f
11951195

11961196

1197-
@cbook.deprecated('2.2', 'numpy.hypot')
1198-
def dist(x, y):
1199-
"""
1200-
Return the distance between two points.
1201-
"""
1202-
d = x-y
1203-
return np.sqrt(np.dot(d, d))
1204-
1205-
1206-
@cbook.deprecated('2.2')
1207-
def dist_point_to_segment(p, s0, s1):
1208-
"""
1209-
Get the distance of a point to a segment.
1210-
1211-
*p*, *s0*, *s1* are *xy* sequences
1212-
1213-
This algorithm from
1214-
http://geomalgorithms.com/a02-_lines.html
1215-
"""
1216-
p = np.asarray(p, float)
1217-
s0 = np.asarray(s0, float)
1218-
s1 = np.asarray(s1, float)
1219-
v = s1 - s0
1220-
w = p - s0
1221-
1222-
c1 = np.dot(w, v)
1223-
if c1 <= 0:
1224-
return dist(p, s0)
1225-
1226-
c2 = np.dot(v, v)
1227-
if c2 <= c1:
1228-
return dist(p, s1)
1229-
1230-
b = c1 / c2
1231-
pb = s0 + b * v
1232-
return dist(p, pb)
1233-
1234-
12351197
@cbook.deprecated('2.2')
12361198
def segments_intersect(s1, s2):
12371199
"""

lib/matplotlib/pylab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@
231231

232232
from matplotlib.mlab import (
233233
amap, base_repr, binary_repr, csv2rec,
234-
demean, detrend, detrend_linear, detrend_mean, detrend_none, dist,
235-
dist_point_to_segment, distances_along_curve, exp_safe,
234+
demean, detrend, detrend_linear, detrend_mean, detrend_none,
235+
distances_along_curve, exp_safe,
236236
fftsurr, frange, griddata,
237237
identity, inside_poly, is_closed_polygon, ispower2, isvector, l1norm,
238238
l2norm, log2, movavg, norm_flat,

0 commit comments

Comments
 (0)