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" ],
@@ -2411,7 +2427,7 @@ def insideA(xy_display):
2411
2427
return patchA .contains (xy_event )[0 ]
2412
2428
2413
2429
try :
2414
- left , right = split_path_inout (path , insideA )
2430
+ left , right = path . split_path_inout (insideA )
2415
2431
except ValueError :
2416
2432
right = path
2417
2433
@@ -2423,7 +2439,7 @@ def insideB(xy_display):
2423
2439
return patchB .contains (xy_event )[0 ]
2424
2440
2425
2441
try :
2426
- left , right = split_path_inout (path , insideB )
2442
+ left , right = path . split_path_inout (insideB )
2427
2443
except ValueError :
2428
2444
left = path
2429
2445
@@ -2436,15 +2452,15 @@ def _shrink(self, path, shrinkA, shrinkB):
2436
2452
Shrink the path by fixed size (in points) with shrinkA and shrinkB.
2437
2453
"""
2438
2454
if shrinkA :
2439
- insideA = inside_circle (* path .vertices [0 ], shrinkA )
2455
+ insideA = _inside_circle (* path .vertices [0 ], shrinkA )
2440
2456
try :
2441
- left , path = split_path_inout (path , insideA )
2457
+ left , path = path . split_path_inout (insideA )
2442
2458
except ValueError :
2443
2459
pass
2444
2460
if shrinkB :
2445
- insideB = inside_circle (* path .vertices [- 1 ], shrinkB )
2461
+ insideB = _inside_circle (* path .vertices [- 1 ], shrinkB )
2446
2462
try :
2447
- path , right = split_path_inout (path , insideB )
2463
+ path , right = path . split_path_inout (insideB )
2448
2464
except ValueError :
2449
2465
pass
2450
2466
return path
@@ -2869,7 +2885,6 @@ def __call__(self, path, mutation_size, linewidth,
2869
2885
The __call__ method is a thin wrapper around the transmute method
2870
2886
and takes care of the aspect ratio.
2871
2887
"""
2872
-
2873
2888
if aspect_ratio is not None :
2874
2889
# Squeeze the given height by the aspect_ratio
2875
2890
vertices = path .vertices / [1 , aspect_ratio ]
@@ -3334,7 +3349,7 @@ def transmute(self, path, mutation_size, linewidth):
3334
3349
3335
3350
# divide the path into a head and a tail
3336
3351
head_length = self .head_length * mutation_size
3337
- in_f = inside_circle (x2 , y2 , head_length )
3352
+ in_f = _inside_circle (x2 , y2 , head_length )
3338
3353
arrow_path = [(x0 , y0 ), (x1 , y1 ), (x2 , y2 )]
3339
3354
3340
3355
try :
@@ -3417,7 +3432,7 @@ def transmute(self, path, mutation_size, linewidth):
3417
3432
arrow_path = [(x0 , y0 ), (x1 , y1 ), (x2 , y2 )]
3418
3433
3419
3434
# path for head
3420
- in_f = inside_circle (x2 , y2 , head_length )
3435
+ in_f = _inside_circle (x2 , y2 , head_length )
3421
3436
try :
3422
3437
path_out , path_in = split_bezier_intersecting_with_closedpath (
3423
3438
arrow_path , in_f , tolerance = 0.01 )
@@ -3432,7 +3447,7 @@ def transmute(self, path, mutation_size, linewidth):
3432
3447
path_head = path_in
3433
3448
3434
3449
# path for head
3435
- in_f = inside_circle (x2 , y2 , head_length * .8 )
3450
+ in_f = _inside_circle (x2 , y2 , head_length * .8 )
3436
3451
path_out , path_in = split_bezier_intersecting_with_closedpath (
3437
3452
arrow_path , in_f , tolerance = 0.01 )
3438
3453
path_tail = path_out
@@ -3450,7 +3465,7 @@ def transmute(self, path, mutation_size, linewidth):
3450
3465
w1 = 1. , wm = 0.6 , w2 = 0.3 )
3451
3466
3452
3467
# path for head
3453
- in_f = inside_circle (x0 , y0 , tail_width * .3 )
3468
+ in_f = _inside_circle (x0 , y0 , tail_width * .3 )
3454
3469
path_in , path_out = split_bezier_intersecting_with_closedpath (
3455
3470
arrow_path , in_f , tolerance = 0.01 )
3456
3471
tail_start = path_in [- 1 ]
0 commit comments