Skip to content

Commit

Permalink
Warn and avoid crash on empty or unparseable path or polygon.
Browse files Browse the repository at this point in the history
Avoids crash on parts such as C397342.
  • Loading branch information
nibblesandbits authored Mar 18, 2024
1 parent 35784e7 commit 574a714
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions easyeda2kicad/kicad/export_kicad_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,20 @@ def convert_ee_polylines(
if isinstance(ee_polyline, EeSymbolPolygon) or ee_polyline.fill_color:
x_points.append(x_points[0])
y_points.append(y_points[0])

kicad_polygon = KiSymbolPolygon(
points=[
[x_points[i], y_points[i]]
for i in range(min(len(x_points), len(y_points)))
],
points_number=min(len(x_points), len(y_points)),
is_closed=x_points[0] == x_points[-1] and y_points[0] == y_points[-1],
)

kicad_polygons.append(kicad_polygon)

if (len(x_points) > 0 and len(y_points) > 0):
kicad_polygon = KiSymbolPolygon(
points=[
[x_points[i], y_points[i]]
for i in range(min(len(x_points), len(y_points)))
],
points_number=min(len(x_points), len(y_points)),
is_closed=x_points[0] == x_points[-1] and y_points[0] == y_points[-1],
)

kicad_polygons.append(kicad_polygon)
else:
logging.warning("Skipping polygon with no parseable points")

return kicad_polygons


Expand Down Expand Up @@ -281,17 +283,19 @@ def convert_ee_paths(
# if ee_path.fill_color:
# x_points.append(x_points[0])
# y_points.append(y_points[0])
if (len(x_points) > 0 and len(y_points) > 0):
ki_polygon = KiSymbolPolygon(
points=[
[x_points[i], y_points[i]]
for i in range(min(len(x_points), len(y_points)))
],
points_number=min(len(x_points), len(y_points)),
is_closed=x_points[0] == x_points[-1] and y_points[0] == y_points[-1],
)

ki_polygon = KiSymbolPolygon(
points=[
[x_points[i], y_points[i]]
for i in range(min(len(x_points), len(y_points)))
],
points_number=min(len(x_points), len(y_points)),
is_closed=x_points[0] == x_points[-1] and y_points[0] == y_points[-1],
)

kicad_polygons.append(ki_polygon)
kicad_polygons.append(ki_polygon)
else:
logging.warning("Skipping path with no parseable points")

return kicad_polygons, kicad_beziers

Expand Down

0 comments on commit 574a714

Please sign in to comment.