Skip to content

Commit 4d86d56

Browse files
Merge pull request #224 from robbievanleeuwen/overlap_polys_fix
Update implementation of geometry.check_geometry_disjoint()
2 parents fd80b05 + ed5dc83 commit 4d86d56

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

sectionproperties/pre/geometry.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,8 @@ def check_geometry_disjoint(lop: List[Polygon]) -> bool:
19491949
Returns True if all polygons in 'lop' are disjoint. Returns
19501950
False, otherwise.
19511951
"""
1952-
geom_acc = Polygon()
1953-
for poly in lop:
1954-
geom_acc = geom_acc & poly
1955-
return geom_acc.is_empty
1952+
bool_acc = []
1953+
for idx, poly1 in enumerate(lop):
1954+
for poly2 in lop[idx + 1 :]:
1955+
bool_acc.append(poly1.intersection(poly2))
1956+
return not all(bool_acc)

sectionproperties/tests/test_sections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ def test_check_geometry_disjoint():
442442
small_sq = rectangular_section(d=100, b=75)
443443
small_hole = rectangular_section(d=40, b=30).align_center(small_sq)
444444

445+
rect2 = rectangular_section(d=50, b=50).shift_section(x_offset=50)
446+
assert check_geometry_disjoint([rect.geom, rect2.geom]) == False
447+
445448
assert check_geometry_disjoint([rect.geom, circ.geom]) == True
446-
assert check_geometry_overlaps([small_sq.geom, small_hole.geom]) == True
447449

448450
rect2 = rectangular_section(d=50, b=50).shift_section(x_offset=50)
449451
assert check_geometry_disjoint([rect.geom, rect2.geom]) == False

0 commit comments

Comments
 (0)