@@ -3459,13 +3459,24 @@ def transmute(self, path, mutation_size, linewidth):
3459
3459
head_length = self .head_length * mutation_size
3460
3460
arrow_path = [(x0 , y0 ), (x1 , y1 ), (x2 , y2 )]
3461
3461
3462
+ from bezier import NonIntersectingPathException
3463
+
3462
3464
# path for head
3463
3465
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
3469
3480
3470
3481
# path for head
3471
3482
in_f = inside_circle (x2 , y2 , head_length * .8 )
@@ -3511,21 +3522,6 @@ def transmute(self, path, mutation_size, linewidth):
3511
3522
(Path .LINETO , tail_start ),
3512
3523
(Path .CLOSEPOLY , tail_start ),
3513
3524
]
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
- ]
3529
3525
path = Path ([p for c , p in patch_path ], [c for c , p in patch_path ])
3530
3526
3531
3527
return path , True
0 commit comments