Skip to content

Commit

Permalink
Merge pull request #28490 from meeseeksmachine/auto-backport-of-pr-28…
Browse files Browse the repository at this point in the history
…486-on-v3.9.x

Backport PR #28486 on branch v3.9.x (Fix CompositeGenericTransform.contains_branch_seperately)
  • Loading branch information
ksunden authored Jul 1, 2024
2 parents 51decc5 + b7d25c4 commit 8ccd2ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8ccd2ee

Please sign in to comment.