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

Skip to content

Commit 17088f9

Browse files
authored
Merge pull request #13309 from anntzer/bezier
API/MNT: bezier cleanups.
2 parents e7c736f + a1dea90 commit 17088f9

File tree

3 files changed

+47
-53
lines changed

3 files changed

+47
-53
lines changed

doc/api/next_api_changes/2018-01-10-AL.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ Changes in parameter names
55
- The ``normed`` parameter to `Axes.hist2d` has been renamed to ``density``.
66
- The ``s`` parameter to `Annotation` (and indirectly `Axes.annotation`) has
77
been renamed to ``text``.
8+
- The ``tolerence`` parameter to
9+
`bezier.find_bezier_t_intersecting_with_closedpath`,
10+
`bezier.split_bezier_intersecting_with_closedpath`,
11+
`bezier.find_r_to_boundary_of_closedpath`,
12+
`bezier.split_path_inout` and `bezier.check_if_parallel` has been renamed to
13+
``tolerance``.
814

915
In each case, the old parameter name remains supported (it cannot be used
1016
simultaneously with the new name), but suppport for it will be dropped in
1117
Matplotlib 3.3.
18+
19+
Deprecations
20+
````````````
21+
22+
The ``bezier.find_r_to_boundary_of_closedpath`` function is deprecated (it has
23+
always returned None instead of the requested radius).

lib/matplotlib/bezier.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,15 @@ def split_de_casteljau(beta, t):
9494
return left_beta, right_beta
9595

9696

97-
# FIXME spelling mistake in the name of the parameter ``tolerence``
98-
def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
99-
inside_closedpath,
100-
t0=0., t1=1., tolerence=0.01):
97+
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
98+
def find_bezier_t_intersecting_with_closedpath(
99+
bezier_point_at_t, inside_closedpath, t0=0., t1=1., tolerance=0.01):
101100
""" Find a parameter t0 and t1 of the given bezier path which
102101
bounds the intersecting points with a provided closed
103102
path(*inside_closedpath*). Search starts from *t0* and *t1* and it
104103
uses a simple bisecting algorithm therefore one of the end point
105104
must be inside the path while the orther doesn't. The search stop
106-
when |t0-t1| gets smaller than the given tolerence.
105+
when |t0-t1| gets smaller than the given tolerance.
107106
value for
108107
109108
- bezier_point_at_t : a function which returns x, y coordinates at *t*
@@ -125,8 +124,8 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
125124

126125
while True:
127126

128-
# return if the distance is smaller than the tolerence
129-
if np.hypot(start[0] - end[0], start[1] - end[1]) < tolerence:
127+
# return if the distance is smaller than the tolerance
128+
if np.hypot(start[0] - end[0], start[1] - end[1]) < tolerance:
130129
return t0, t1
131130

132131
# calculate the middle point
@@ -177,9 +176,9 @@ def point_at_t(self, t):
177176
return _x, _y
178177

179178

180-
def split_bezier_intersecting_with_closedpath(bezier,
181-
inside_closedpath,
182-
tolerence=0.01):
179+
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
180+
def split_bezier_intersecting_with_closedpath(
181+
bezier, inside_closedpath, tolerance=0.01):
183182

184183
"""
185184
bezier : control points of the bezier segment
@@ -190,17 +189,17 @@ def split_bezier_intersecting_with_closedpath(bezier,
190189
bz = BezierSegment(bezier)
191190
bezier_point_at_t = bz.point_at_t
192191

193-
t0, t1 = find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
194-
inside_closedpath,
195-
tolerence=tolerence)
192+
t0, t1 = find_bezier_t_intersecting_with_closedpath(
193+
bezier_point_at_t, inside_closedpath, tolerance=tolerance)
196194

197195
_left, _right = split_de_casteljau(bezier, (t0 + t1) / 2.)
198196
return _left, _right
199197

200198

201-
def find_r_to_boundary_of_closedpath(inside_closedpath, xy,
202-
cos_t, sin_t,
203-
rmin=0., rmax=1., tolerence=0.01):
199+
@cbook.deprecated("3.1")
200+
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
201+
def find_r_to_boundary_of_closedpath(
202+
inside_closedpath, xy, cos_t, sin_t, rmin=0., rmax=1., tolerance=0.01):
204203
"""
205204
Find a radius r (centered at *xy*) between *rmin* and *rmax* at
206205
which it intersect with the path.
@@ -216,14 +215,14 @@ def find_r_to_boundary_of_closedpath(inside_closedpath, xy,
216215
def _f(r):
217216
return cos_t * r + cx, sin_t * r + cy
218217

219-
find_bezier_t_intersecting_with_closedpath(_f, inside_closedpath,
220-
t0=rmin, t1=rmax,
221-
tolerence=tolerence)
218+
find_bezier_t_intersecting_with_closedpath(
219+
_f, inside_closedpath, t0=rmin, t1=rmax, tolerance=tolerance)
222220

223221
# matplotlib specific
224222

225223

226-
def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):
224+
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
225+
def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):
227226
""" divide a path into two segment at the point where inside(x, y)
228227
becomes False.
229228
"""
@@ -252,7 +251,7 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):
252251

253252
bp = bezier_path.reshape((-1, 2))
254253
left, right = split_bezier_intersecting_with_closedpath(
255-
bp, inside, tolerence)
254+
bp, inside, tolerance)
256255
if len(left) == 2:
257256
codes_left = [Path.LINETO]
258257
codes_right = [Path.MOVETO, Path.LINETO]
@@ -305,7 +304,8 @@ def get_cos_sin(x0, y0, x1, y1):
305304
return dx / d, dy / d
306305

307306

308-
def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5):
307+
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
308+
def check_if_parallel(dx1, dy1, dx2, dy2, tolerance=1.e-5):
309309
""" returns
310310
* 1 if two lines are parralel in same direction
311311
* -1 if two lines are parralel in opposite direction
@@ -314,9 +314,9 @@ def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5):
314314
theta1 = np.arctan2(dx1, dy1)
315315
theta2 = np.arctan2(dx2, dy2)
316316
dtheta = np.abs(theta1 - theta2)
317-
if dtheta < tolerence:
317+
if dtheta < tolerance:
318318
return 1
319-
elif np.abs(dtheta - np.pi) < tolerence:
319+
elif np.abs(dtheta - np.pi) < tolerance:
320320
return -1
321321
else:
322322
return False

lib/matplotlib/patches.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,28 +2770,20 @@ def insideB(xy_display):
27702770

27712771
def _shrink(self, path, shrinkA, shrinkB):
27722772
"""
2773-
Shrink the path by fixed size (in points) with shrinkA and shrinkB
2773+
Shrink the path by fixed size (in points) with shrinkA and shrinkB.
27742774
"""
27752775
if shrinkA:
2776-
x, y = path.vertices[0]
2777-
insideA = inside_circle(x, y, shrinkA)
2778-
2776+
insideA = inside_circle(*path.vertices[0], shrinkA)
27792777
try:
2780-
left, right = split_path_inout(path, insideA)
2781-
path = right
2778+
left, path = split_path_inout(path, insideA)
27822779
except ValueError:
27832780
pass
2784-
27852781
if shrinkB:
2786-
x, y = path.vertices[-1]
2787-
insideB = inside_circle(x, y, shrinkB)
2788-
2782+
insideB = inside_circle(*path.vertices[-1], shrinkB)
27892783
try:
2790-
left, right = split_path_inout(path, insideB)
2791-
path = left
2784+
path, right = split_path_inout(path, insideB)
27922785
except ValueError:
27932786
pass
2794-
27952787
return path
27962788

27972789
def __call__(self, posA, posB,
@@ -3720,9 +3712,8 @@ def transmute(self, path, mutation_size, linewidth):
37203712

37213713
try:
37223714
arrow_out, arrow_in = \
3723-
split_bezier_intersecting_with_closedpath(arrow_path,
3724-
in_f,
3725-
tolerence=0.01)
3715+
split_bezier_intersecting_with_closedpath(
3716+
arrow_path, in_f, tolerance=0.01)
37263717
except NonIntersectingPathException:
37273718
# if this happens, make a straight line of the head_length
37283719
# long.
@@ -3803,11 +3794,8 @@ def transmute(self, path, mutation_size, linewidth):
38033794
# path for head
38043795
in_f = inside_circle(x2, y2, head_length)
38053796
try:
3806-
path_out, path_in = \
3807-
split_bezier_intersecting_with_closedpath(
3808-
arrow_path,
3809-
in_f,
3810-
tolerence=0.01)
3797+
path_out, path_in = split_bezier_intersecting_with_closedpath(
3798+
arrow_path, in_f, tolerance=0.01)
38113799
except NonIntersectingPathException:
38123800
# if this happens, make a straight line of the head_length
38133801
# long.
@@ -3821,10 +3809,7 @@ def transmute(self, path, mutation_size, linewidth):
38213809
# path for head
38223810
in_f = inside_circle(x2, y2, head_length * .8)
38233811
path_out, path_in = split_bezier_intersecting_with_closedpath(
3824-
arrow_path,
3825-
in_f,
3826-
tolerence=0.01
3827-
)
3812+
arrow_path, in_f, tolerance=0.01)
38283813
path_tail = path_out
38293814

38303815
# head
@@ -3842,10 +3827,7 @@ def transmute(self, path, mutation_size, linewidth):
38423827
# path for head
38433828
in_f = inside_circle(x0, y0, tail_width * .3)
38443829
path_in, path_out = split_bezier_intersecting_with_closedpath(
3845-
arrow_path,
3846-
in_f,
3847-
tolerence=0.01
3848-
)
3830+
arrow_path, in_f, tolerance=0.01)
38493831
tail_start = path_in[-1]
38503832

38513833
head_right, head_left = head_r, head_l

0 commit comments

Comments
 (0)