@@ -643,7 +643,7 @@ class Rectangle(Patch):
643
643
"""
644
644
645
645
def __str__ (self ):
646
- pars = self ._x , self ._y , self ._width , self ._height , self .angle
646
+ pars = self ._x0 , self ._y0 , self ._width , self ._height , self .angle
647
647
fmt = "Rectangle(xy=(%g, %g), width=%g, height=%g, angle=%g)"
648
648
return fmt % pars
649
649
@@ -662,10 +662,15 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
662
662
663
663
Patch .__init__ (self , ** kwargs )
664
664
665
- self ._x = xy [0 ]
666
- self ._y = xy [1 ]
665
+ self ._x0 = xy [0 ]
666
+ self ._y0 = xy [1 ]
667
+
667
668
self ._width = width
668
669
self ._height = height
670
+
671
+ self ._x1 = self ._x0 + self ._width
672
+ self ._y1 = self ._y0 + self ._height
673
+
669
674
self .angle = float (angle )
670
675
# Note: This cannot be calculated until this is added to an Axes
671
676
self ._rect_transform = transforms .IdentityTransform ()
@@ -682,31 +687,37 @@ def _update_patch_transform(self):
682
687
makes it very important to call the accessor method and
683
688
not directly access the transformation member variable.
684
689
"""
685
- x = self .convert_xunits (self ._x )
686
- y = self .convert_yunits (self ._y )
687
- width = self .convert_xunits (self ._width )
688
- height = self .convert_yunits (self ._height )
689
- bbox = transforms .Bbox .from_bounds ( x , y , width , height )
690
+ x0 = self .convert_xunits (self ._x0 )
691
+ y0 = self .convert_yunits (self ._y0 )
692
+ x1 = self .convert_xunits (self ._x1 )
693
+ y1 = self .convert_yunits (self ._y1 )
694
+ bbox = transforms .Bbox .from_extents ( x0 , y0 , x1 , y1 )
690
695
rot_trans = transforms .Affine2D ()
691
- rot_trans .rotate_deg_around (x , y , self .angle )
696
+ rot_trans .rotate_deg_around (x0 , y0 , self .angle )
692
697
self ._rect_transform = transforms .BboxTransformTo (bbox )
693
698
self ._rect_transform += rot_trans
694
699
700
+ def _update_x1 (self ):
701
+ self ._x1 = self ._x0 + self ._width
702
+
703
+ def _update_y1 (self ):
704
+ self ._y1 = self ._y0 + self ._height
705
+
695
706
def get_patch_transform (self ):
696
707
self ._update_patch_transform ()
697
708
return self ._rect_transform
698
709
699
710
def get_x (self ):
700
711
"Return the left coord of the rectangle"
701
- return self ._x
712
+ return self ._x0
702
713
703
714
def get_y (self ):
704
715
"Return the bottom coord of the rectangle"
705
- return self ._y
716
+ return self ._y0
706
717
707
718
def get_xy (self ):
708
719
"Return the left and bottom coords of the rectangle"
709
- return self ._x , self ._y
720
+ return self ._x0 , self ._y0
710
721
711
722
def get_width (self ):
712
723
"Return the width of the rectangle"
@@ -722,7 +733,8 @@ def set_x(self, x):
722
733
723
734
ACCEPTS: float
724
735
"""
725
- self ._x = x
736
+ self ._x0 = x
737
+ self ._update_x1 ()
726
738
self .stale = True
727
739
728
740
def set_y (self , y ):
@@ -731,7 +743,8 @@ def set_y(self, y):
731
743
732
744
ACCEPTS: float
733
745
"""
734
- self ._y = y
746
+ self ._y0 = y
747
+ self ._update_y1 ()
735
748
self .stale = True
736
749
737
750
def set_xy (self , xy ):
@@ -740,7 +753,9 @@ def set_xy(self, xy):
740
753
741
754
ACCEPTS: 2-item sequence
742
755
"""
743
- self ._x , self ._y = xy
756
+ self ._x0 , self ._y0 = xy
757
+ self ._update_x1 ()
758
+ self ._update_y1 ()
744
759
self .stale = True
745
760
746
761
def set_width (self , w ):
@@ -750,6 +765,7 @@ def set_width(self, w):
750
765
ACCEPTS: float
751
766
"""
752
767
self ._width = w
768
+ self ._update_x1 ()
753
769
self .stale = True
754
770
755
771
def set_height (self , h ):
@@ -759,6 +775,7 @@ def set_height(self, h):
759
775
ACCEPTS: float
760
776
"""
761
777
self ._height = h
778
+ self ._update_y1 ()
762
779
self .stale = True
763
780
764
781
def set_bounds (self , * args ):
@@ -771,15 +788,17 @@ def set_bounds(self, *args):
771
788
l , b , w , h = args [0 ]
772
789
else :
773
790
l , b , w , h = args
774
- self ._x = l
775
- self ._y = b
791
+ self ._x0 = l
792
+ self ._y0 = b
776
793
self ._width = w
777
794
self ._height = h
795
+ self ._update_x1 ()
796
+ self ._update_y1 ()
778
797
self .stale = True
779
798
780
799
def get_bbox (self ):
781
- return transforms .Bbox .from_bounds (self ._x , self ._y ,
782
- self ._width , self ._height )
800
+ return transforms .Bbox .from_extents (self ._x0 , self ._y0 ,
801
+ self ._x1 , self ._y1 )
783
802
784
803
xy = property (get_xy , set_xy )
785
804
0 commit comments