Skip to content

Commit 311a9f6

Browse files
Swap find_holes out for filter_polygons
1 parent 99eef8b commit 311a9f6

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Diff for: src/sectionproperties/pre/geometry.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -2514,16 +2514,24 @@ def load_dxf(
25142514
my_dxf.cleanup()
25152515

25162516
polygons = my_dxf.polygons
2517-
new_polygons = c2s.utils.find_holes(polygons)
2517+
new_polygons = c2s.utils.filter_polygons(polygons)
25182518

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

2524+
# ensure only Polygons are generated
2525+
for poly in new_polygons:
2526+
if not isinstance(poly, Polygon): # pyright: ignore [reportUnnecessaryIsInstance]
2527+
msg = f"Not all objects found in file: {dxf_filepath} are Polygons"
2528+
raise RuntimeError(msg)
2529+
2530+
if len(new_polygons) == 1:
2531+
return Geometry(new_polygons[0])
2532+
else:
2533+
return CompoundGeometry(MultiPolygon(new_polygons))
2534+
25272535

25282536
def create_facets(
25292537
points_list: list[tuple[float, float]],

Diff for: typings/cad_to_shapely/__init__.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .dxf import DxfImporter
2-
from .utils import find_holes
2+
from .utils import filter_polygons, find_holes

Diff for: typings/cad_to_shapely/utils.pyi

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
from shapely.geometry import Polygon
22

33
def find_holes(polygons: list[Polygon]) -> Polygon: ...
4+
def filter_polygons(
5+
polygons: list[Polygon],
6+
filter_flag: int = ...,
7+
) -> list[Polygon]: ...

0 commit comments

Comments
 (0)