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

Skip to content

bezier cleanups. #13309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/api/next_api_changes/2018-01-10-AL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ Changes in parameter names
- The ``normed`` parameter to `Axes.hist2d` has been renamed to ``density``.
- The ``s`` parameter to `Annotation` (and indirectly `Axes.annotation`) has
been renamed to ``text``.
- The ``tolerence`` parameter to
`bezier.find_bezier_t_intersecting_with_closedpath`,
`bezier.split_bezier_intersecting_with_closedpath`,
`bezier.find_r_to_boundary_of_closedpath`,
`bezier.split_path_inout` and `bezier.check_if_parallel` has been renamed to
``tolerance``.

In each case, the old parameter name remains supported (it cannot be used
simultaneously with the new name), but suppport for it will be dropped in
Matplotlib 3.3.

Deprecations
````````````

The ``bezier.find_r_to_boundary_of_closedpath`` function is deprecated (it has
always returned None instead of the requested radius).
48 changes: 24 additions & 24 deletions lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,15 @@ def split_de_casteljau(beta, t):
return left_beta, right_beta


# FIXME spelling mistake in the name of the parameter ``tolerence``
def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
inside_closedpath,
t0=0., t1=1., tolerence=0.01):
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
def find_bezier_t_intersecting_with_closedpath(
bezier_point_at_t, inside_closedpath, t0=0., t1=1., tolerance=0.01):
""" Find a parameter t0 and t1 of the given bezier path which
bounds the intersecting points with a provided closed
path(*inside_closedpath*). Search starts from *t0* and *t1* and it
uses a simple bisecting algorithm therefore one of the end point
must be inside the path while the orther doesn't. The search stop
when |t0-t1| gets smaller than the given tolerence.
when |t0-t1| gets smaller than the given tolerance.
value for

- bezier_point_at_t : a function which returns x, y coordinates at *t*
Expand All @@ -125,8 +124,8 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,

while True:

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

# calculate the middle point
Expand Down Expand Up @@ -177,9 +176,9 @@ def point_at_t(self, t):
return _x, _y


def split_bezier_intersecting_with_closedpath(bezier,
inside_closedpath,
tolerence=0.01):
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
def split_bezier_intersecting_with_closedpath(
bezier, inside_closedpath, tolerance=0.01):

"""
bezier : control points of the bezier segment
Expand All @@ -190,17 +189,17 @@ def split_bezier_intersecting_with_closedpath(bezier,
bz = BezierSegment(bezier)
bezier_point_at_t = bz.point_at_t

t0, t1 = find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
inside_closedpath,
tolerence=tolerence)
t0, t1 = find_bezier_t_intersecting_with_closedpath(
bezier_point_at_t, inside_closedpath, tolerance=tolerance)

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


def find_r_to_boundary_of_closedpath(inside_closedpath, xy,
cos_t, sin_t,
rmin=0., rmax=1., tolerence=0.01):
@cbook.deprecated("3.1")
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
def find_r_to_boundary_of_closedpath(
inside_closedpath, xy, cos_t, sin_t, rmin=0., rmax=1., tolerance=0.01):
"""
Find a radius r (centered at *xy*) between *rmin* and *rmax* at
which it intersect with the path.
Expand All @@ -216,14 +215,14 @@ def find_r_to_boundary_of_closedpath(inside_closedpath, xy,
def _f(r):
return cos_t * r + cx, sin_t * r + cy

find_bezier_t_intersecting_with_closedpath(_f, inside_closedpath,
t0=rmin, t1=rmax,
tolerence=tolerence)
find_bezier_t_intersecting_with_closedpath(
_f, inside_closedpath, t0=rmin, t1=rmax, tolerance=tolerance)

# matplotlib specific


def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):
""" divide a path into two segment at the point where inside(x, y)
becomes False.
"""
Expand Down Expand Up @@ -252,7 +251,7 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):

bp = bezier_path.reshape((-1, 2))
left, right = split_bezier_intersecting_with_closedpath(
bp, inside, tolerence)
bp, inside, tolerance)
if len(left) == 2:
codes_left = [Path.LINETO]
codes_right = [Path.MOVETO, Path.LINETO]
Expand Down Expand Up @@ -305,7 +304,8 @@ def get_cos_sin(x0, y0, x1, y1):
return dx / d, dy / d


def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5):
@cbook._rename_parameter("3.1", "tolerence", "tolerance")
def check_if_parallel(dx1, dy1, dx2, dy2, tolerance=1.e-5):
""" returns
* 1 if two lines are parralel in same direction
* -1 if two lines are parralel in opposite direction
Expand All @@ -314,9 +314,9 @@ def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5):
theta1 = np.arctan2(dx1, dy1)
theta2 = np.arctan2(dx2, dy2)
dtheta = np.abs(theta1 - theta2)
if dtheta < tolerence:
if dtheta < tolerance:
return 1
elif np.abs(dtheta - np.pi) < tolerence:
elif np.abs(dtheta - np.pi) < tolerance:
return -1
else:
return False
Expand Down
40 changes: 11 additions & 29 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2770,28 +2770,20 @@ def insideB(xy_display):

def _shrink(self, path, shrinkA, shrinkB):
"""
Shrink the path by fixed size (in points) with shrinkA and shrinkB
Shrink the path by fixed size (in points) with shrinkA and shrinkB.
"""
if shrinkA:
x, y = path.vertices[0]
insideA = inside_circle(x, y, shrinkA)

insideA = inside_circle(*path.vertices[0], shrinkA)
try:
left, right = split_path_inout(path, insideA)
path = right
left, path = split_path_inout(path, insideA)
except ValueError:
pass

if shrinkB:
x, y = path.vertices[-1]
insideB = inside_circle(x, y, shrinkB)

insideB = inside_circle(*path.vertices[-1], shrinkB)
try:
left, right = split_path_inout(path, insideB)
path = left
path, right = split_path_inout(path, insideB)
except ValueError:
pass

return path

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

try:
arrow_out, arrow_in = \
split_bezier_intersecting_with_closedpath(arrow_path,
in_f,
tolerence=0.01)
split_bezier_intersecting_with_closedpath(
arrow_path, in_f, tolerance=0.01)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length
# long.
Expand Down Expand Up @@ -3803,11 +3794,8 @@ def transmute(self, path, mutation_size, linewidth):
# path for head
in_f = inside_circle(x2, y2, head_length)
try:
path_out, path_in = \
split_bezier_intersecting_with_closedpath(
arrow_path,
in_f,
tolerence=0.01)
path_out, path_in = split_bezier_intersecting_with_closedpath(
arrow_path, in_f, tolerance=0.01)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length
# long.
Expand All @@ -3821,10 +3809,7 @@ def transmute(self, path, mutation_size, linewidth):
# path for head
in_f = inside_circle(x2, y2, head_length * .8)
path_out, path_in = split_bezier_intersecting_with_closedpath(
arrow_path,
in_f,
tolerence=0.01
)
arrow_path, in_f, tolerance=0.01)
path_tail = path_out

# head
Expand All @@ -3842,10 +3827,7 @@ def transmute(self, path, mutation_size, linewidth):
# path for head
in_f = inside_circle(x0, y0, tail_width * .3)
path_in, path_out = split_bezier_intersecting_with_closedpath(
arrow_path,
in_f,
tolerence=0.01
)
arrow_path, in_f, tolerance=0.01)
tail_start = path_in[-1]

head_right, head_left = head_r, head_l
Expand Down