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

Skip to content

fix fancy-style annotation causing an exception when the connecting path #566

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
Nov 16, 2011
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
5 changes: 4 additions & 1 deletion lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import warnings


class NonIntersectingPathException(ValueError):
pass

# some functions

def get_intersection(cx1, cy1, cos_t1, sin_t1,
Expand Down Expand Up @@ -126,7 +129,7 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedp
end_inside = inside_closedpath(end)

if not xor(start_inside, end_inside):
raise ValueError("the segment does not seemed to intersect with the path")
raise NonIntersectingPathException("the segment does not seemed to intersect with the path")

while 1:

Expand Down
36 changes: 16 additions & 20 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3459,13 +3459,24 @@ def transmute(self, path, mutation_size, linewidth):
head_length = self.head_length * mutation_size
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]

from bezier import NonIntersectingPathException

# path for head
in_f = inside_circle(x2, y2, head_length)
path_out, path_in = \
split_bezier_intersecting_with_closedpath(arrow_path,
in_f,
tolerence=0.01)
path_head = path_in
try:
path_out, path_in = \
split_bezier_intersecting_with_closedpath(arrow_path,
in_f,
tolerence=0.01)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length long.
dx, dy = x2 - x1, y2 - y1
ff = head_length/(dx*dx+dy*dy)**.5
x0, y0 = x2 - ff*dx, y2 - ff*dy
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
path_head = arrow_path
else:
path_head = path_in

# path for head
in_f = inside_circle(x2, y2, head_length*.8)
Expand Down Expand Up @@ -3511,21 +3522,6 @@ def transmute(self, path, mutation_size, linewidth):
(Path.LINETO, tail_start),
(Path.CLOSEPOLY, tail_start),
]
patch_path2 = [(Path.MOVETO, tail_right[0]),
(Path.CURVE3, tail_right[1]),
(Path.CURVE3, tail_right[2]),
(Path.LINETO, head_right[0]),
(Path.CURVE3, head_right[1]),
(Path.CURVE3, head_right[2]),
(Path.CURVE3, head_left[1]),
(Path.CURVE3, head_left[0]),
(Path.LINETO, tail_left[2]),
(Path.CURVE3, tail_left[1]),
(Path.CURVE3, tail_left[0]),
(Path.CURVE3, tail_start),
(Path.CURVE3, tail_right[0]),
(Path.CLOSEPOLY, tail_right[0]),
]
path = Path([p for c, p in patch_path], [c for c, p in patch_path])

return path, True
Expand Down