Skip to content

Commit 1d457c0

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

File tree

2 files changed

+33
-43
lines changed

2 files changed

+33
-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: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import math
88
from numbers import Number
99
import textwrap
10+
from types import SimpleNamespace
1011
from collections import namedtuple
1112

1213
import numpy as np
@@ -2700,59 +2701,35 @@ class _Base:
27002701
helper methods.
27012702
"""
27022703

2704+
@_api.deprecated("3.7")
27032705
class SimpleEvent:
27042706
def __init__(self, xy):
27052707
self.x, self.y = xy
27062708

2707-
def _clip(self, path, patchA, patchB):
2709+
def _in_patch(self, patch):
27082710
"""
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.
2711+
Return a predicate function testing whether a point *xy* is
2712+
contained in *patch*.
27142713
"""
2714+
return lambda xy: patch.contains(
2715+
SimpleNamespace(x=xy[0], y=xy[1]))[0]
27152716

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):
2717+
def _clip(self, path, in_start, in_stop):
27432718
"""
2744-
Shrink the path by fixed size (in points) with shrinkA and shrinkB.
2719+
Clip *path* at its start by the region where *in_start* returns
2720+
True, and at its stop by the region where *in_stop* returns True.
2721+
2722+
The original path is assumed to start in the *in_start* region and
2723+
to stop in the *in_stop* region.
27452724
"""
2746-
if shrinkA:
2747-
insideA = inside_circle(*path.vertices[0], shrinkA)
2725+
if in_start:
27482726
try:
2749-
left, path = split_path_inout(path, insideA)
2727+
_, path = split_path_inout(path, in_start)
27502728
except ValueError:
27512729
pass
2752-
if shrinkB:
2753-
insideB = inside_circle(*path.vertices[-1], shrinkB)
2730+
if in_stop:
27542731
try:
2755-
path, right = split_path_inout(path, insideB)
2732+
path, _ = split_path_inout(path, in_stop)
27562733
except ValueError:
27572734
pass
27582735
return path
@@ -2764,9 +2741,17 @@ def __call__(self, posA, posB,
27642741
*posB*; then clip and shrink the path.
27652742
"""
27662743
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
2744+
path = self._clip(
2745+
path,
2746+
self._in_patch(patchA) if patchA else None,
2747+
self._in_patch(patchB) if patchB else None,
2748+
)
2749+
path = self._clip(
2750+
path,
2751+
inside_circle(*path.vertices[0], shrinkA) if shrinkA else None,
2752+
inside_circle(*path.vertices[-1], shrinkB) if shrinkB else None
2753+
)
2754+
return path
27702755

27712756
@_register_style(_style_list)
27722757
class Arc3(_Base):

0 commit comments

Comments
 (0)