Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e72cba

Browse files
committed
Unify logic of ConnectionStyle._Base.{_clip,,_shrink}.
... and deprecate the SimpleEvent helper.
1 parent 9b4985e commit 2e72cba

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``SimpleEvent``
2+
~~~~~~~~~~~~~~~
3+
The ``SimpleEvent`` nested class (previously accessible via the public
4+
subclasses of ``ConnectionStyle._Base``, such as `.ConnectionStyle.Arc`, has
5+
been deprecated.

lib/matplotlib/patches.py

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,59 +2700,35 @@ class _Base:
27002700
helper methods.
27012701
"""
27022702

2703+
@_api.deprecated("3.7")
27032704
class SimpleEvent:
27042705
def __init__(self, xy):
27052706
self.x, self.y = xy
27062707

2707-
def _clip(self, path, patchA, patchB):
2708+
def _in_patch(self, patch):
27082709
"""
2709-
Clip the path to the boundary of the patchA and patchB.
2710-
The starting point of the path needed to be inside of the
2711-
patchA and the end point inside the patch B. The *contains*
2712-
methods of each patch object is utilized to test if the point
2713-
is inside the path.
2710+
Return a predicate function testing whether a point *xy* is
2711+
contained in *patch*.
27142712
"""
2713+
return lambda xy: patch.contains(
2714+
SimpleNamespace(x=xy[0], y=xy[1]))[0]
27152715

2716-
if patchA:
2717-
def insideA(xy_display):
2718-
xy_event = ConnectionStyle._Base.SimpleEvent(xy_display)
2719-
return patchA.contains(xy_event)[0]
2720-
2721-
try:
2722-
left, right = split_path_inout(path, insideA)
2723-
except ValueError:
2724-
right = path
2725-
2726-
path = right
2727-
2728-
if patchB:
2729-
def insideB(xy_display):
2730-
xy_event = ConnectionStyle._Base.SimpleEvent(xy_display)
2731-
return patchB.contains(xy_event)[0]
2732-
2733-
try:
2734-
left, right = split_path_inout(path, insideB)
2735-
except ValueError:
2736-
left = path
2737-
2738-
path = left
2739-
2740-
return path
2741-
2742-
def _shrink(self, path, shrinkA, shrinkB):
2716+
def _clip(self, path, in_start, in_stop):
27432717
"""
2744-
Shrink the path by fixed size (in points) with shrinkA and shrinkB.
2718+
Clip *path* at its start by the region where *in_start* returns
2719+
True, and at its stop by the region where *in_stop* returns True.
2720+
2721+
The original path is assumed to start in the *in_start* region and
2722+
to stop in the *in_stop* region.
27452723
"""
2746-
if shrinkA:
2747-
insideA = inside_circle(*path.vertices[0], shrinkA)
2724+
if in_start:
27482725
try:
2749-
left, path = split_path_inout(path, insideA)
2726+
_, path = split_path_inout(path, in_start)
27502727
except ValueError:
27512728
pass
2752-
if shrinkB:
2753-
insideB = inside_circle(*path.vertices[-1], shrinkB)
2729+
if in_stop:
27542730
try:
2755-
path, right = split_path_inout(path, insideB)
2731+
path, _ = split_path_inout(path, in_stop)
27562732
except ValueError:
27572733
pass
27582734
return path
@@ -2764,9 +2740,17 @@ def __call__(self, posA, posB,
27642740
*posB*; then clip and shrink the path.
27652741
"""
27662742
path = self.connect(posA, posB)
2767-
clipped_path = self._clip(path, patchA, patchB)
2768-
shrunk_path = self._shrink(clipped_path, shrinkA, shrinkB)
2769-
return shrunk_path
2743+
path = self._clip(
2744+
path,
2745+
self._in_patch(patchA) if patchA else None,
2746+
self._in_patch(patchB) if patchB else None,
2747+
)
2748+
path = self._clip(
2749+
path,
2750+
inside_circle(*path.vertices[0], shrinkA) if shrinkA else None,
2751+
inside_circle(*path.vertices[-1], shrinkB) if shrinkB else None
2752+
)
2753+
return path
27702754

27712755
@_register_style(_style_list)
27722756
class Arc3(_Base):

0 commit comments

Comments
 (0)