`BboxTransformFrom` linearly transforms points from a given `Bbox` to the unit bounding box.
| 2663 | |
| 2664 | |
| 2665 | class BboxTransformFrom(Affine2DBase): |
| 2666 | """ |
| 2667 | `BboxTransformFrom` linearly transforms points from a given `Bbox` to the |
| 2668 | unit bounding box. |
| 2669 | """ |
| 2670 | is_separable = True |
| 2671 | |
| 2672 | def __init__(self, boxin, **kwargs): |
| 2673 | _api.check_isinstance(BboxBase, boxin=boxin) |
| 2674 | |
| 2675 | super().__init__(**kwargs) |
| 2676 | self._boxin = boxin |
| 2677 | self.set_children(boxin) |
| 2678 | self._mtx = None |
| 2679 | self._inverted = None |
| 2680 | |
| 2681 | __str__ = _make_str_method("_boxin") |
| 2682 | |
| 2683 | def get_matrix(self): |
| 2684 | # docstring inherited |
| 2685 | if self._invalid: |
| 2686 | inl, inb, inw, inh = self._boxin.bounds |
| 2687 | if DEBUG and (inw == 0 or inh == 0): |
| 2688 | raise ValueError("Transforming from a singular bounding box.") |
| 2689 | x_scale = 1.0 / inw |
| 2690 | y_scale = 1.0 / inh |
| 2691 | self._mtx = np.array([[x_scale, 0.0, -inl*x_scale], |
| 2692 | [ 0.0, y_scale, -inb*y_scale], |
| 2693 | [ 0.0, 0.0, 1.0]], |
| 2694 | float) |
| 2695 | self._inverted = None |
| 2696 | self._invalid = 0 |
| 2697 | return self._mtx |
| 2698 | |
| 2699 | |
| 2700 | class ScaledTranslation(Affine2DBase): |
no test coverage detected
searching dependent graphs…