10
10
import matplotlib as mpl
11
11
from . import artist , cbook , colors , docstring , lines as mlines , transforms
12
12
from .bezier import (
13
- NonIntersectingPathException , get_cos_sin , get_intersection ,
14
- get_parallels , inside_circle , make_wedged_bezier2 ,
15
- split_bezier_intersecting_with_closedpath , split_path_inout )
13
+ NonIntersectingPathException , get_cos_sin , get_intersection , get_parallels ,
14
+ make_wedged_bezier2 , split_bezier_intersecting_with_closedpath )
16
15
from .path import Path
17
16
18
17
18
+ def _inside_circle (cx , cy , r ):
19
+ """
20
+ Return a function that checks whether a point is in a circle with center
21
+ (*cx*, *cy*) and radius *r*.
22
+
23
+ The returned function has the signature::
24
+
25
+ f(xy: Tuple[float, float]) -> bool
26
+ """
27
+ r2 = r ** 2
28
+
29
+ def _f (xy ):
30
+ x , y = xy
31
+ return (x - cx ) ** 2 + (y - cy ) ** 2 < r2
32
+ return _f
33
+
34
+
19
35
@cbook ._define_aliases ({
20
36
"antialiased" : ["aa" ],
21
37
"edgecolor" : ["ec" ],
@@ -2414,7 +2430,7 @@ def insideA(xy_display):
2414
2430
return patchA .contains (xy_event )[0 ]
2415
2431
2416
2432
try :
2417
- left , right = split_path_inout (path , insideA )
2433
+ left , right = path . split_path_inout (insideA )
2418
2434
except ValueError :
2419
2435
right = path
2420
2436
@@ -2426,7 +2442,7 @@ def insideB(xy_display):
2426
2442
return patchB .contains (xy_event )[0 ]
2427
2443
2428
2444
try :
2429
- left , right = split_path_inout (path , insideB )
2445
+ left , right = path . split_path_inout (insideB )
2430
2446
except ValueError :
2431
2447
left = path
2432
2448
@@ -2439,15 +2455,15 @@ def _shrink(self, path, shrinkA, shrinkB):
2439
2455
Shrink the path by fixed size (in points) with shrinkA and shrinkB.
2440
2456
"""
2441
2457
if shrinkA :
2442
- insideA = inside_circle (* path .vertices [0 ], shrinkA )
2458
+ insideA = _inside_circle (* path .vertices [0 ], shrinkA )
2443
2459
try :
2444
- left , path = split_path_inout (path , insideA )
2460
+ left , path = path . split_path_inout (insideA )
2445
2461
except ValueError :
2446
2462
pass
2447
2463
if shrinkB :
2448
- insideB = inside_circle (* path .vertices [- 1 ], shrinkB )
2464
+ insideB = _inside_circle (* path .vertices [- 1 ], shrinkB )
2449
2465
try :
2450
- path , right = split_path_inout (path , insideB )
2466
+ path , right = path . split_path_inout (insideB )
2451
2467
except ValueError :
2452
2468
pass
2453
2469
return path
@@ -2872,7 +2888,6 @@ def __call__(self, path, mutation_size, linewidth,
2872
2888
The __call__ method is a thin wrapper around the transmute method
2873
2889
and takes care of the aspect ratio.
2874
2890
"""
2875
-
2876
2891
if aspect_ratio is not None :
2877
2892
# Squeeze the given height by the aspect_ratio
2878
2893
vertices = path .vertices / [1 , aspect_ratio ]
@@ -3337,7 +3352,7 @@ def transmute(self, path, mutation_size, linewidth):
3337
3352
3338
3353
# divide the path into a head and a tail
3339
3354
head_length = self .head_length * mutation_size
3340
- in_f = inside_circle (x2 , y2 , head_length )
3355
+ in_f = _inside_circle (x2 , y2 , head_length )
3341
3356
arrow_path = [(x0 , y0 ), (x1 , y1 ), (x2 , y2 )]
3342
3357
3343
3358
try :
@@ -3420,7 +3435,7 @@ def transmute(self, path, mutation_size, linewidth):
3420
3435
arrow_path = [(x0 , y0 ), (x1 , y1 ), (x2 , y2 )]
3421
3436
3422
3437
# path for head
3423
- in_f = inside_circle (x2 , y2 , head_length )
3438
+ in_f = _inside_circle (x2 , y2 , head_length )
3424
3439
try :
3425
3440
path_out , path_in = split_bezier_intersecting_with_closedpath (
3426
3441
arrow_path , in_f , tolerance = 0.01 )
@@ -3435,7 +3450,7 @@ def transmute(self, path, mutation_size, linewidth):
3435
3450
path_head = path_in
3436
3451
3437
3452
# path for head
3438
- in_f = inside_circle (x2 , y2 , head_length * .8 )
3453
+ in_f = _inside_circle (x2 , y2 , head_length * .8 )
3439
3454
path_out , path_in = split_bezier_intersecting_with_closedpath (
3440
3455
arrow_path , in_f , tolerance = 0.01 )
3441
3456
path_tail = path_out
@@ -3453,7 +3468,7 @@ def transmute(self, path, mutation_size, linewidth):
3453
3468
w1 = 1. , wm = 0.6 , w2 = 0.3 )
3454
3469
3455
3470
# path for head
3456
- in_f = inside_circle (x0 , y0 , tail_width * .3 )
3471
+ in_f = _inside_circle (x0 , y0 , tail_width * .3 )
3457
3472
path_in , path_out = split_bezier_intersecting_with_closedpath (
3458
3473
arrow_path , in_f , tolerance = 0.01 )
3459
3474
tail_start = path_in [- 1 ]
0 commit comments