A mutable 2D affine transformation.
| 1939 | |
| 1940 | |
| 1941 | class Affine2D(Affine2DBase): |
| 1942 | """ |
| 1943 | A mutable 2D affine transformation. |
| 1944 | """ |
| 1945 | |
| 1946 | def __init__(self, matrix=None, **kwargs): |
| 1947 | """ |
| 1948 | Initialize an Affine transform from a 3x3 numpy float array:: |
| 1949 | |
| 1950 | a c e |
| 1951 | b d f |
| 1952 | 0 0 1 |
| 1953 | |
| 1954 | If *matrix* is None, initialize with the identity transform. |
| 1955 | """ |
| 1956 | super().__init__(**kwargs) |
| 1957 | if matrix is None: |
| 1958 | # A bit faster than np.identity(3). |
| 1959 | matrix = IdentityTransform._mtx |
| 1960 | self._mtx = matrix.copy() |
| 1961 | self._invalid = 0 |
| 1962 | |
| 1963 | _base_str = _make_str_method("_mtx") |
| 1964 | |
| 1965 | def __str__(self): |
| 1966 | return (self._base_str() |
| 1967 | if (self._mtx != np.diag(np.diag(self._mtx))).any() |
| 1968 | else f"Affine2D().scale({self._mtx[0, 0]}, {self._mtx[1, 1]})" |
| 1969 | if self._mtx[0, 0] != self._mtx[1, 1] |
| 1970 | else f"Affine2D().scale({self._mtx[0, 0]})") |
| 1971 | |
| 1972 | @staticmethod |
| 1973 | def from_values(a, b, c, d, e, f): |
| 1974 | """ |
| 1975 | Create a new Affine2D instance from the given values:: |
| 1976 | |
| 1977 | a c e |
| 1978 | b d f |
| 1979 | 0 0 1 |
| 1980 | |
| 1981 | . |
| 1982 | """ |
| 1983 | return Affine2D( |
| 1984 | np.array([a, c, e, b, d, f, 0.0, 0.0, 1.0], float).reshape((3, 3))) |
| 1985 | |
| 1986 | def get_matrix(self): |
| 1987 | """ |
| 1988 | Get the underlying transformation matrix as a 3x3 array:: |
| 1989 | |
| 1990 | a c e |
| 1991 | b d f |
| 1992 | 0 0 1 |
| 1993 | |
| 1994 | . |
| 1995 | """ |
| 1996 | if self._invalid: |
| 1997 | self._inverted = None |
| 1998 | self._invalid = 0 |
searching dependent graphs…