7
7
import math
8
8
from numbers import Number
9
9
import textwrap
10
+ from types import SimpleNamespace
10
11
from collections import namedtuple
11
12
12
13
import numpy as np
@@ -2698,59 +2699,35 @@ class _Base:
2698
2699
helper methods.
2699
2700
"""
2700
2701
2702
+ @_api .deprecated ("3.7" )
2701
2703
class SimpleEvent :
2702
2704
def __init__ (self , xy ):
2703
2705
self .x , self .y = xy
2704
2706
2705
- def _clip (self , path , patchA , patchB ):
2707
+ def _in_patch (self , patch ):
2706
2708
"""
2707
- Clip the path to the boundary of the patchA and patchB.
2708
- The starting point of the path needed to be inside of the
2709
- patchA and the end point inside the patch B. The *contains*
2710
- methods of each patch object is utilized to test if the point
2711
- is inside the path.
2709
+ Return a predicate function testing whether a point *xy* is
2710
+ contained in *patch*.
2712
2711
"""
2712
+ return lambda xy : patch .contains (
2713
+ SimpleNamespace (x = xy [0 ], y = xy [1 ]))[0 ]
2713
2714
2714
- if patchA :
2715
- def insideA (xy_display ):
2716
- xy_event = ConnectionStyle ._Base .SimpleEvent (xy_display )
2717
- return patchA .contains (xy_event )[0 ]
2718
-
2719
- try :
2720
- left , right = split_path_inout (path , insideA )
2721
- except ValueError :
2722
- right = path
2723
-
2724
- path = right
2725
-
2726
- if patchB :
2727
- def insideB (xy_display ):
2728
- xy_event = ConnectionStyle ._Base .SimpleEvent (xy_display )
2729
- return patchB .contains (xy_event )[0 ]
2730
-
2731
- try :
2732
- left , right = split_path_inout (path , insideB )
2733
- except ValueError :
2734
- left = path
2735
-
2736
- path = left
2737
-
2738
- return path
2739
-
2740
- def _shrink (self , path , shrinkA , shrinkB ):
2715
+ def _clip (self , path , in_start , in_stop ):
2741
2716
"""
2742
- Shrink the path by fixed size (in points) with shrinkA and shrinkB.
2717
+ Clip *path* at its start by the region where *in_start* returns
2718
+ True, and at its stop by the region where *in_stop* returns True.
2719
+
2720
+ The original path is assumed to start in the *in_start* region and
2721
+ to stop in the *in_stop* region.
2743
2722
"""
2744
- if shrinkA :
2745
- insideA = inside_circle (* path .vertices [0 ], shrinkA )
2723
+ if in_start :
2746
2724
try :
2747
- left , path = split_path_inout (path , insideA )
2725
+ _ , path = split_path_inout (path , in_start )
2748
2726
except ValueError :
2749
2727
pass
2750
- if shrinkB :
2751
- insideB = inside_circle (* path .vertices [- 1 ], shrinkB )
2728
+ if in_stop :
2752
2729
try :
2753
- path , right = split_path_inout (path , insideB )
2730
+ path , _ = split_path_inout (path , in_stop )
2754
2731
except ValueError :
2755
2732
pass
2756
2733
return path
@@ -2762,9 +2739,17 @@ def __call__(self, posA, posB,
2762
2739
*posB*; then clip and shrink the path.
2763
2740
"""
2764
2741
path = self .connect (posA , posB )
2765
- clipped_path = self ._clip (path , patchA , patchB )
2766
- shrunk_path = self ._shrink (clipped_path , shrinkA , shrinkB )
2767
- return shrunk_path
2742
+ path = self ._clip (
2743
+ path ,
2744
+ self ._in_patch (patchA ) if patchA else None ,
2745
+ self ._in_patch (patchB ) if patchB else None ,
2746
+ )
2747
+ path = self ._clip (
2748
+ path ,
2749
+ inside_circle (* path .vertices [0 ], shrinkA ) if shrinkA else None ,
2750
+ inside_circle (* path .vertices [- 1 ], shrinkB ) if shrinkB else None
2751
+ )
2752
+ return path
2768
2753
2769
2754
@_register_style (_style_list )
2770
2755
class Arc3 (_Base ):
0 commit comments