Convert this path to a list of polygons or polylines. Each polygon/polyline is an (N, 2) array of vertices. In other words, each polygon has no `MOVETO` instructions or curves. This is useful for displaying in backends that do not support compound paths or
(self, transform=None, width=0, height=0, closed_only=True)
| 726 | return Path(vertices, new_codes) |
| 727 | |
| 728 | def to_polygons(self, transform=None, width=0, height=0, closed_only=True): |
| 729 | """ |
| 730 | Convert this path to a list of polygons or polylines. Each |
| 731 | polygon/polyline is an (N, 2) array of vertices. In other words, |
| 732 | each polygon has no `MOVETO` instructions or curves. This |
| 733 | is useful for displaying in backends that do not support |
| 734 | compound paths or Bézier curves. |
| 735 | |
| 736 | If *width* and *height* are both non-zero then the lines will |
| 737 | be simplified so that vertices outside of (0, 0), (width, |
| 738 | height) will be clipped. |
| 739 | |
| 740 | The resulting polygons will be simplified if the |
| 741 | :attr:`Path.should_simplify` attribute of the path is `True`. |
| 742 | |
| 743 | If *closed_only* is `True` (default), only closed polygons, |
| 744 | with the last point being the same as the first point, will be |
| 745 | returned. Any unclosed polylines in the path will be |
| 746 | explicitly closed. If *closed_only* is `False`, any unclosed |
| 747 | polygons in the path will be returned as unclosed polygons, |
| 748 | and the closed polygons will be returned explicitly closed by |
| 749 | setting the last point to the same as the first point. |
| 750 | """ |
| 751 | if len(self.vertices) == 0: |
| 752 | return [] |
| 753 | |
| 754 | if transform is not None: |
| 755 | transform = transform.frozen() |
| 756 | |
| 757 | if self.codes is None and (width == 0 or height == 0): |
| 758 | vertices = self.vertices |
| 759 | if closed_only: |
| 760 | if len(vertices) < 3: |
| 761 | return [] |
| 762 | elif np.any(vertices[0] != vertices[-1]): |
| 763 | vertices = [*vertices, vertices[0]] |
| 764 | |
| 765 | if transform is None: |
| 766 | return [vertices] |
| 767 | else: |
| 768 | return [transform.transform(vertices)] |
| 769 | |
| 770 | # Deal with the case where there are curves and/or multiple |
| 771 | # subpaths (using extension code) |
| 772 | return _path.convert_path_to_polygons( |
| 773 | self, transform, width, height, closed_only) |
| 774 | |
| 775 | _unit_rectangle = None |
| 776 |