@@ -736,13 +736,6 @@ def __init__(self, xy, width, height, angle=0.0, *,
736
736
self ._height = height
737
737
self .angle = float (angle )
738
738
self .rotation_point = rotation_point
739
- # Required for RectangleSelector with axes aspect ratio != 1
740
- # The patch is defined in data coordinates and when changing the
741
- # selector with square modifier and not in data coordinates, we need
742
- # to correct for the aspect ratio difference between the data and
743
- # display coordinate systems. Its value is typically provide by
744
- # Axes._get_aspect_ratio()
745
- self ._aspect_ratio_correction = 1.0
746
739
self ._convert_units () # Validate the inputs.
747
740
748
741
def get_path (self ):
@@ -770,13 +763,11 @@ def get_patch_transform(self):
770
763
rotation_point = bbox .x0 , bbox .y0
771
764
else :
772
765
rotation_point = self .rotation_point
773
- return transforms .BboxTransformTo (bbox ) \
774
- + transforms .Affine2D () \
775
- .translate (- rotation_point [0 ], - rotation_point [1 ]) \
776
- .scale (1 , self ._aspect_ratio_correction ) \
777
- .rotate_deg (self .angle ) \
778
- .scale (1 , 1 / self ._aspect_ratio_correction ) \
779
- .translate (* rotation_point )
766
+ return (transforms .BboxTransformTo (bbox ) +
767
+ transforms .Affine2D ()
768
+ .translate (- rotation_point [0 ], - rotation_point [1 ])
769
+ .rotate_deg (self .angle )
770
+ .translate (* rotation_point ))
780
771
781
772
@property
782
773
def rotation_point (self ):
@@ -806,6 +797,24 @@ def get_xy(self):
806
797
"""Return the left and bottom coords of the rectangle as a tuple."""
807
798
return self ._x0 , self ._y0
808
799
800
+ def get_edge_midpoints (self ):
801
+ """
802
+ Return the edge midpoints of the rectangle, moving clockwise from the
803
+ center of the left-hand edge.
804
+ """
805
+ return self .get_patch_transform ().transform (
806
+ [(0 , 0.5 ), (0.5 , 1 ), (1 , 0.5 ), (0.5 , 0 )])
807
+
808
+ def get_corners (self ):
809
+ """
810
+ Return the corners of the rectangle, moving clockwise from (x, y).
811
+ """
812
+ return self .get_patch_transform ().transform (
813
+ [(0 , 0 ), (1 , 0 ), (1 , 1 ), (0 , 1 )])
814
+
815
+ def get_center (self ):
816
+ return self .get_patch_transform ().transform ((0.5 , 0.5 ))
817
+
809
818
def get_width (self ):
810
819
"""Return the width of the rectangle."""
811
820
return self ._width
@@ -1551,12 +1560,6 @@ def __init__(self, xy, width, height, angle=0, **kwargs):
1551
1560
self ._width , self ._height = width , height
1552
1561
self ._angle = angle
1553
1562
self ._path = Path .unit_circle ()
1554
- # Required for EllipseSelector with axes aspect ratio != 1
1555
- # The patch is defined in data coordinates and when changing the
1556
- # selector with square modifier and not in data coordinates, we need
1557
- # to correct for the aspect ratio difference between the data and
1558
- # display coordinate systems.
1559
- self ._aspect_ratio_correction = 1.0
1560
1563
# Note: This cannot be calculated until this is added to an Axes
1561
1564
self ._patch_transform = transforms .IdentityTransform ()
1562
1565
@@ -1574,9 +1577,8 @@ def _recompute_transform(self):
1574
1577
width = self .convert_xunits (self ._width )
1575
1578
height = self .convert_yunits (self ._height )
1576
1579
self ._patch_transform = transforms .Affine2D () \
1577
- .scale (width * 0.5 , height * 0.5 * self . _aspect_ratio_correction ) \
1580
+ .scale (width * 0.5 , height * 0.5 ) \
1578
1581
.rotate_deg (self .angle ) \
1579
- .scale (1 , 1 / self ._aspect_ratio_correction ) \
1580
1582
.translate (* center )
1581
1583
1582
1584
def get_path (self ):
@@ -1657,6 +1659,20 @@ def get_angle(self):
1657
1659
1658
1660
angle = property (get_angle , set_angle )
1659
1661
1662
+ def get_corners (self ):
1663
+ """
1664
+ Return the corners of the rectangle, moving clockwise from (x0, y0).
1665
+ """
1666
+ return self .get_patch_transform ().transform (
1667
+ [(- 1 , - 1 ), (1 , - 1 ), (1 , 1 ), (- 1 , 1 )])
1668
+
1669
+ def get_edge_midpoints (self ):
1670
+ """
1671
+ Return the corners of the rectangle, moving clockwise from (x, y).
1672
+ """
1673
+ return self .get_patch_transform ().transform (
1674
+ [(0 , - 1 ), (1 , 0 ), (0 , 1 ), (- 1 , 0 )])
1675
+
1660
1676
1661
1677
class Annulus (Patch ):
1662
1678
"""
0 commit comments