Skip to content

PathSimplifier fails to ignore CLOSEPOLY vertices #17914

Closed
@brunobeltran

Description

@brunobeltran

Bug report

Bug summary

This bug does not seem to have surfaced anywhere yet, but Path's with NaN vertices at CLOSEPOLY can come through PathNanRemover in a "correct" state but then PathSimplifier can sometimes break it:

Code for reproduction/Actual Outcome

>>> p = Path([(0, 0), (1, 0), (1, 1), (np.nan, np.nan)],
         [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY])
>>> # correctly ignores CLOSEPOLY even though it's NaN
>>> p.cleaned(remove_nans=True)
Path(array([[ 0.,  0.],
       [ 1.,  0.],
       [ 1.,  1.],
       [nan, nan],
       [ 0.,  0.]]), array([ 1,  2,  2, 79,  0], dtype=uint8))
>>> # but now for some reason these NaN's are used to populate LINETO's
>>> p.cleaned(remove_nans=True, simplify=True)
Path(array([[ 0.,  0.],
       [ 1.,  0.],
       [ 1.,  1.],
       [nan, nan],
       [nan, nan],
       [ 0.,  0.]]), array([1, 2, 2, 2, 2, 0], dtype=uint8))

Expected outcome

The values of the vertices in a CLOSEPOLY should always be ignored, in favor of the most recent MOVETO's vertex values:

>>> p.cleaned(remove_nans=True, simplify=True)
Path(array([[ 0.,  0.],
       [ 1.,  0.],
       [ 1.,  1.],
       [0, 0],
       [ 0.,  0.]]), array([1, 2, 2, 2, 0], dtype=uint8))

Matplotlib version

  • Operating system:
  • Matplotlib version:
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions