@@ -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
10BC0
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