`BboxTransform` linearly transforms points from one `Bbox` to another.
| 2583 | |
| 2584 | |
| 2585 | class BboxTransform(Affine2DBase): |
| 2586 | """ |
| 2587 | `BboxTransform` linearly transforms points from one `Bbox` to another. |
| 2588 | """ |
| 2589 | |
| 2590 | is_separable = True |
| 2591 | |
| 2592 | def __init__(self, boxin, boxout, **kwargs): |
| 2593 | """ |
| 2594 | Create a new `BboxTransform` that linearly transforms |
| 2595 | points from *boxin* to *boxout*. |
| 2596 | """ |
| 2597 | _api.check_isinstance(BboxBase, boxin=boxin, boxout=boxout) |
| 2598 | |
| 2599 | super().__init__(**kwargs) |
| 2600 | self._boxin = boxin |
| 2601 | self._boxout = boxout |
| 2602 | self.set_children(boxin, boxout) |
| 2603 | self._mtx = None |
| 2604 | self._inverted = None |
| 2605 | |
| 2606 | __str__ = _make_str_method("_boxin", "_boxout") |
| 2607 | |
| 2608 | def get_matrix(self): |
| 2609 | # docstring inherited |
| 2610 | if self._invalid: |
| 2611 | inl, inb, inw, inh = self._boxin.bounds |
| 2612 | outl, outb, outw, outh = self._boxout.bounds |
| 2613 | x_scale = outw / inw |
| 2614 | y_scale = outh / inh |
| 2615 | if DEBUG and (x_scale == 0 or y_scale == 0): |
| 2616 | raise ValueError( |
| 2617 | "Transforming from or to a singular bounding box") |
| 2618 | self._mtx = np.array([[x_scale, 0.0, -inl*x_scale+outl], |
| 2619 | [ 0.0, y_scale, -inb*y_scale+outb], |
| 2620 | [ 0.0, 0.0, 1.0]], |
| 2621 | float) |
| 2622 | self._inverted = None |
| 2623 | self._invalid = 0 |
| 2624 | return self._mtx |
| 2625 | |
| 2626 | |
| 2627 | class BboxTransformTo(Affine2DBase): |
no test coverage detected
searching dependent graphs…