Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,18 @@ def test_contains_branch(self):
assert x is sx is False
assert y is sy is True

# A branch that lives in the first child of a composite, or that spans
# the boundary between its two children, must be reported in both
# dimensions, consistently with contains_branch (issue #32099).
assert self.stack2.contains_branch(self.stack2_subset)
assert (self.stack2.contains_branch_separately(self.stack2_subset)
== (True, True))
assert (self.stack1.contains_branch_separately(self.ta2 + self.ta3)
== (True, True))
# A transform that is not a branch stays False in both dimensions.
assert (self.stack2.contains_branch_separately(self.tn1)
== (False, False))

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
13 changes: 12 additions & 1 deletion lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,18 @@ def contains_branch_separately(self, other_transform):
'transforms with 2 output dimensions')
if self == other_transform:
return (True, True)
return self._b.contains_branch_separately(other_transform)
# The second (suffix) child may report per-dimension results when it
# is a blended transform, so query it separately first.
x, y = self._b.contains_branch_separately(other_transform)
if not (x and y):
# Otherwise the branch may lie in the first child or span the
# boundary between the two children. Such a branch is a suffix of
# the whole composite and therefore matches in both dimensions, so
# fall back to the (non-per-dimension) whole-transform check.
in_branch = self.contains_branch(other_transform)
x = x or in_branch
y = y or in_branch
return (x, y)

depth = property(lambda self: self._a.depth + self._b.depth)
is_affine = property(lambda self: self._a.is_affine and self._b.is_affine)
Expand Down
Loading