Skip to content

Swap find_holes out for filter_polygons in load_dxf (geometry.py) #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
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
20 changes: 14 additions & 6 deletions src/sectionproperties/pre/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2514,16 +2514,24 @@ def load_dxf(
my_dxf.cleanup()

polygons = my_dxf.polygons
new_polygons = c2s.utils.find_holes(polygons)
new_polygons = c2s.utils.filter_polygons(polygons)

if isinstance(new_polygons, MultiPolygon):
return CompoundGeometry(new_polygons)
elif isinstance(new_polygons, Polygon): # pyright: ignore [reportUnnecessaryIsInstance]
return Geometry(new_polygons)
else:
# ensure list length > 0
if len(new_polygons) == 0:
msg = f"No shapely.Polygon objects found in file: {dxf_filepath}"
raise RuntimeError(msg)

# ensure only Polygons are generated
for poly in new_polygons:
if not isinstance(poly, Polygon): # pyright: ignore [reportUnnecessaryIsInstance]
msg = f"Not all objects found in file: {dxf_filepath} are Polygons"
raise RuntimeError(msg)

if len(new_polygons) == 1:
return Geometry(new_polygons[0])
else:
return CompoundGeometry(MultiPolygon(new_polygons))


def create_facets(
points_list: list[tuple[float, float]],
Expand Down
2 changes: 1 addition & 1 deletion typings/cad_to_shapely/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .dxf import DxfImporter
from .utils import find_holes
from .utils import filter_polygons, find_holes
4 changes: 4 additions & 0 deletions typings/cad_to_shapely/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from shapely.geometry import Polygon

def find_holes(polygons: list[Polygon]) -> Polygon: ...
def filter_polygons(
polygons: list[Polygon],
filter_flag: int = ...,
) -> list[Polygon]: ...