Skip to content

Commit

Permalink
fixes #1003 - NumpyPath2d could contain a 3d vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Jan 4, 2024
1 parent 83771d1 commit f77f14a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions notes/pages/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ id:: 6588217b-c1d3-44c1-a0d7-e5ee465cc6de
- REMOVE: `ezdxf.math.linspace`, replaced by `numpy.linspace`
- BUGFIX: Restore lost links between `LAYOUT` and `BLOCK_RECORD` entities
- {{issue 997}}
- BUGFIX: `NumpyPath2d` could contain a 3d vertex
- {{issue 1003}}
-
- ## Version 1.1.4 - 2023-12-24
id:: 6568dc88-ce84-4f46-b490-43768c491a2b
Expand Down
1 change: 1 addition & 0 deletions src/ezdxf/addons/drawing/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def draw_path(self, path: BkPath2d, properties: BackendProperties):
"""Draw a solid line path, line type rendering is done by the
frontend since v0.18.1
"""

mpl_path = to_matplotlib_path([path])
try:
patch = PathPatch(
Expand Down
10 changes: 8 additions & 2 deletions src/ezdxf/npshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self, path: Optional[Path]) -> None:
vertices = [(v.x, v.y) for v in path.control_vertices()]
if len(vertices) == 0:
try: # control_vertices() does not return the start point of empty paths
vertices = [path.start]
vertices = [Vec2(path.start)]
except IndexError:
vertices = []
self._vertices = np.array(vertices, dtype=VertexNumpyType)
Expand Down Expand Up @@ -503,11 +503,17 @@ def to_matplotlib_path(paths: Iterable[NumpyPath2d], *, detect_holes=False):
vertices: list[np.ndarray] = []
codes: list[int] = []
for path in paths:

vertices.append(path.np_vertices())
codes.append(MPL_MOVETO)
for cmd in path.command_codes():
codes.extend(MPL_CODES[cmd])
return Path(np.concatenate(vertices), codes)
points = np.concatenate(vertices)
try:
return Path(points, codes)
except Exception as e:
raise ValueError(f"matplotlib.path.Path({str(points)}, {str(codes)}): {str(e)}")



def single_paths(paths: Iterable[NumpyPath2d]) -> list[NumpyPath2d]:
Expand Down

0 comments on commit f77f14a

Please sign in to comment.