@@ -729,59 +729,35 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
729
729
**kwargs : `.Patch` properties
730
730
%(Patch)s
731
731
"""
732
-
733
732
super ().__init__ (** kwargs )
734
-
735
733
self ._x0 = xy [0 ]
736
734
self ._y0 = xy [1 ]
737
-
738
735
self ._width = width
739
736
self ._height = height
740
-
741
- self ._x1 = self ._x0 + self ._width
742
- self ._y1 = self ._y0 + self ._height
743
-
744
737
self .angle = float (angle )
745
- # Note: This cannot be calculated until this is added to an Axes
746
- self ._rect_transform = transforms .IdentityTransform ()
738
+ self ._convert_units () # Validate the inputs.
747
739
748
740
def get_path (self ):
749
741
"""Return the vertices of the rectangle."""
750
742
return Path .unit_rectangle ()
751
743
752
- def _update_patch_transform (self ):
753
- """
754
- Notes
755
- -----
756
- This cannot be called until after this has been added to an Axes,
757
- otherwise unit conversion will fail. This makes it very important to
758
- call the accessor method and not directly access the transformation
759
- member variable.
760
- """
761
- x0 , y0 , x1 , y1 = self ._convert_units ()
762
- bbox = transforms .Bbox .from_extents (x0 , y0 , x1 , y1 )
763
- rot_trans = transforms .Affine2D ()
764
- rot_trans .rotate_deg_around (x0 , y0 , self .angle )
765
- self ._rect_transform = transforms .BboxTransformTo (bbox )
766
- self ._rect_transform += rot_trans
767
-
768
- def _update_x1 (self ):
769
- self ._x1 = self ._x0 + self ._width
770
-
771
- def _update_y1 (self ):
772
- self ._y1 = self ._y0 + self ._height
773
-
774
744
def _convert_units (self ):
775
745
"""Convert bounds of the rectangle."""
776
746
x0 = self .convert_xunits (self ._x0 )
777
747
y0 = self .convert_yunits (self ._y0 )
778
- x1 = self .convert_xunits (self ._x1 )
779
- y1 = self .convert_yunits (self ._y1 )
748
+ x1 = self .convert_xunits (self ._x0 + self . _width )
749
+ y1 = self .convert_yunits (self ._y0 + self . _height )
780
750
return x0 , y0 , x1 , y1
781
751
782
752
def get_patch_transform (self ):
783
- self ._update_patch_transform ()
784
- return self ._rect_transform
753
+ # Note: This cannot be called until after this has been added to
754
+ # an Axes, otherwise unit conversion will fail. This makes it very
755
+ # important to call the accessor method and not directly access the
756
+ # transformation member variable.
757
+ bbox = self .get_bbox ()
758
+ return (transforms .BboxTransformTo (bbox )
759
+ + transforms .Affine2D ().rotate_deg_around (
760
+ bbox .x0 , bbox .y0 , self .angle ))
785
761
786
762
def get_x (self ):
787
763
"""Return the left coordinate of the rectangle."""
@@ -806,13 +782,11 @@ def get_height(self):
806
782
def set_x (self , x ):
807
783
"""Set the left coordinate of the rectangle."""
808
784
self ._x0 = x
809
- self ._update_x1 ()
810
785
self .stale = True
811
786
812
787
def set_y (self , y ):
813
788
"""Set the bottom coordinate of the rectangle."""
814
789
self ._y0 = y
815
- self ._update_y1 ()
816
790
self .stale = True
817
791
818
792
def set_xy (self , xy ):
@@ -824,20 +798,16 @@ def set_xy(self, xy):
824
798
xy : (float, float)
825
799
"""
826
800
self ._x0 , self ._y0 = xy
827
- self ._update_x1 ()
828
- self ._update_y1 ()
829
801
self .stale = True
830
802
831
803
def set_width (self , w ):
832
804
"""Set the width of the rectangle."""
833
805
self ._width = w
834
- self ._update_x1 ()
835
806
self .stale = True
836
807
837
808
def set_height (self , h ):
838
809
"""Set the height of the rectangle."""
839
810
self ._height = h
840
- self ._update_y1 ()
841
811
self .stale = True
842
812
843
813
def set_bounds (self , * args ):
@@ -859,8 +829,6 @@ def set_bounds(self, *args):
859
829
self ._y0 = b
860
830
self ._width = w
861
831
self ._height = h
862
- self ._update_x1 ()
863
- self ._update_y1 ()
864
832
self .stale = True
865
833
866
834
def get_bbox (self ):
@@ -876,8 +844,8 @@ class RegularPolygon(Patch):
876
844
877
845
def __str__ (self ):
878
846
s = "RegularPolygon((%g, %g), %d, radius=%g, orientation=%g)"
879
- return s % (self ._xy [0 ], self ._xy [1 ], self ._numVertices , self ._radius ,
880
- self ._orientation )
847
+ return s % (self .xy [0 ], self .xy [1 ], self .numvertices , self .radius ,
848
+ self .orientation )
881
849
882
850
@docstring .dedent_interpd
883
851
def __init__ (self , xy , numVertices , radius = 5 , orientation = 0 ,
@@ -902,63 +870,22 @@ def __init__(self, xy, numVertices, radius=5, orientation=0,
902
870
903
871
%(Patch)s
904
872
"""
905
- self ._xy = xy
906
- self ._numVertices = numVertices
907
- self ._orientation = orientation
908
- self ._radius = radius
873
+ self .xy = xy
874
+ self .numvertices = numVertices
875
+ self .orientation = orientation
876
+ self .radius = radius
909
877
self ._path = Path .unit_regular_polygon (numVertices )
910
- self ._poly_transform = transforms .Affine2D ()
911
- self ._update_transform ()
912
-
878
+ self ._patch_transform = transforms .Affine2D ()
913
879
super ().__init__ (** kwargs )
914
880
915
- def _update_transform (self ):
916
- self ._poly_transform .clear () \
917
- .scale (self .radius ) \
918
- .rotate (self .orientation ) \
919
- .translate (* self .xy )
920
-
921
- @property
922
- def xy (self ):
923
- return self ._xy
924
-
925
- @xy .setter
926
- def xy (self , xy ):
927
- self ._xy = xy
928
- self ._update_transform ()
929
-
930
- @property
931
- def orientation (self ):
932
- return self ._orientation
933
-
934
- @orientation .setter
935
- def orientation (self , orientation ):
936
- self ._orientation = orientation
937
- self ._update_transform ()
938
-
939
- @property
940
- def radius (self ):
941
- return self ._radius
942
-
943
- @radius .setter
944
- def radius (self , radius ):
945
- self ._radius = radius
946
- self ._update_transform ()
947
-
948
- @property
949
- def numvertices (self ):
950
- return self ._numVertices
951
-
952
- @numvertices .setter
953
- def numvertices (self , numVertices ):
954
- self ._numVertices = numVertices
955
-
956
881
def get_path (self ):
957
882
return self ._path
958
883
959
884
def get_patch_transform (self ):
960
- self ._update_transform ()
961
- return self ._poly_transform
885
+ return self ._patch_transform .clear () \
886
+ .scale (self .radius ) \
887
+ .rotate (self .orientation ) \
888
+ .translate (* self .xy )
962
889
963
890
964
891
class PathPatch (Patch ):
@@ -1461,7 +1388,7 @@ class CirclePolygon(RegularPolygon):
1461
1388
1462
1389
def __str__ (self ):
1463
1390
s = "CirclePolygon((%g, %g), radius=%g, resolution=%d)"
1464
- return s % (self ._xy [0 ], self ._xy [1 ], self ._radius , self ._numVertices )
1391
+ return s % (self .xy [0 ], self .xy [1 ], self .radius , self .numvertices )
1465
1392
1466
1393
@docstring .dedent_interpd
1467
1394
def __init__ (self , xy , radius = 5 ,
0 commit comments