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

Skip to content

Commit f6ebac9

Browse files
committed
Merge pull request #566 from leejjoon/fix-fancy-style-annotation
fix fancy-style annotation causing an exception when the connecting path
2 parents 04f1ef0 + 4e6b883 commit f6ebac9

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

lib/matplotlib/bezier.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import warnings
1313

1414

15+
class NonIntersectingPathException(ValueError):
16+
pass
17+
1518
# some functions
1619

1720
def get_intersection(cx1, cy1, cos_t1, sin_t1,
@@ -126,7 +129,7 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedp
126129
end_inside = inside_closedpath(end)
127130

128131
if not xor(start_inside, end_inside):
129-
raise ValueError("the segment does not seemed to intersect with the path")
132+
raise NonIntersectingPathException("the segment does not seemed to intersect with the path")
130133

131134
while 1:
132135

lib/matplotlib/patches.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,13 +3459,24 @@ def transmute(self, path, mutation_size, linewidth):
34593459
head_length = self.head_length * mutation_size
34603460
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
34613461

3462+
from bezier import NonIntersectingPathException
3463+
34623464
# path for head
34633465
in_f = inside_circle(x2, y2, head_length)
3464-
path_out, path_in = \
3465-
split_bezier_intersecting_with_closedpath(arrow_path,
3466-
in_f,
3467-
tolerence=0.01)
3468-
path_head = path_in
3466+
try:
3467+
path_out, path_in = \
3468+
split_bezier_intersecting_with_closedpath(arrow_path,
3469+
in_f,
3470+
tolerence=0.01)
3471+
except NonIntersectingPathException:
3472+
# if this happens, make a straight line of the head_length long.
3473+
dx, dy = x2 - x1, y2 - y1
3474+
ff = head_length/(dx*dx+dy*dy)**.5
3475+
x0, y0 = x2 - ff*dx, y2 - ff*dy
3476+
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
3477+
path_head = arrow_path
3478+
else:
3479+
path_head = path_in
34693480

34703481
# path for head
34713482
in_f = inside_circle(x2, y2, head_length*.8)
@@ -3511,21 +3522,6 @@ def transmute(self, path, mutation_size, linewidth):
35113522
(Path.LINETO, tail_start),
35123523
(Path.CLOSEPOLY, tail_start),
35133524
]
3514-
patch_path2 = [(Path.MOVETO, tail_right[0]),
3515-
(Path.CURVE3, tail_right[1]),
3516-
(Path.CURVE3, tail_right[2]),
3517-
(Path.LINETO, head_right[0]),
3518-
(Path.CURVE3, head_right[1]),
3519-
(Path.CURVE3, head_right[2]),
3520-
(Path.CURVE3, head_left[1]),
3521-
(Path.CURVE3, head_left[0]),
3522-
(Path.LINETO, tail_left[2]),
3523-
(Path.CURVE3, tail_left[1]),
3524-
(Path.CURVE3, tail_left[0]),
3525-
(Path.CURVE3, tail_start),
3526-
(Path.CURVE3, tail_right[0]),
3527-
(Path.CLOSEPOLY, tail_right[0]),
3528-
]
35293525
path = Path([p for c, p in patch_path], [c for c, p in patch_path])
35303526

35313527
return path, True

0 commit comments

Comments
 (0)