From fa6054bf86f7114fd645a32dba1cacbf751dd807 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 28 Jun 2024 04:28:56 -0400 Subject: [PATCH] Fix CompositeGenericTransform.contains_branch_seperately Formerly, this fell back to the the super-class Transform implementation, which returned `Transform.contains_branch` for both dimensions. This doesn't make sense for blended transforms, which have their own implementation that checks each side. However, it _also_ doesn't make sense for composite transforms, because those may contain blended transforms themselves, so add a specific implementation for it. Also fix type inconsistency for `Transform.contains_branch_seperately`. --- lib/matplotlib/tests/test_transforms.py | 7 +++++++ lib/matplotlib/transforms.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_transforms.py b/lib/matplotlib/tests/test_transforms.py index 959814de82db..3d12b90d5210 100644 --- a/lib/matplotlib/tests/test_transforms.py +++ b/lib/matplotlib/tests/test_transforms.py @@ -667,6 +667,13 @@ def test_contains_branch(self): assert not self.stack1.contains_branch(self.tn1 + self.ta2) + blend = mtransforms.BlendedGenericTransform(self.tn2, self.stack2) + x, y = blend.contains_branch_seperately(self.stack2_subset) + stack_blend = self.tn3 + blend + sx, sy = stack_blend.contains_branch_seperately(self.stack2_subset) + assert x is sx is False + assert y is sy is True + def test_affine_simplification(self): # tests that a transform stack only calls as much is absolutely # necessary "non-affine" allowing the best possible optimization with diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 5003e2113930..3575bd1fc14d 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -1423,7 +1423,7 @@ def contains_branch_seperately(self, other_transform): 'transforms with 2 output dimensions') # for a non-blended transform each separate dimension is the same, so # just return the appropriate shape. - return [self.contains_branch(other_transform)] * 2 + return (self.contains_branch(other_transform), ) * 2 def __sub__(self, other): """ @@ -2404,6 +2404,15 @@ def _iter_break_from_left_to_right(self): for left, right in self._b._iter_break_from_left_to_right(): yield self._a + left, right + def contains_branch_seperately(self, other_transform): + # docstring inherited + if self.output_dims != 2: + raise ValueError('contains_branch_seperately only supports ' + 'transforms with 2 output dimensions') + if self == other_transform: + return (True, True) + return self._b.contains_branch_seperately(other_transform) + depth = property(lambda self: self._a.depth + self._b.depth) is_affine = property(lambda self: self._a.is_affine and self._b.is_affine) is_separable = property( pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy