Skip to content

Commit 0c3e26f

Browse files
committed
Fix: check_geometry_disjoint() implementation updated to build connectivity graph of Geometry polygons
1 parent 4d86d56 commit 0c3e26f

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

sectionproperties/pre/geometry.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,11 +1946,38 @@ def check_geometry_overlaps(lop: List[Polygon]) -> bool:
19461946

19471947
def check_geometry_disjoint(lop: List[Polygon]) -> bool:
19481948
"""
1949-
Returns True if all polygons in 'lop' are disjoint. Returns
1949+
Returns True if any polygons in 'lop' are disjoint. Returns
19501950
False, otherwise.
19511951
"""
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)
1952+
# Build polygon connectivity network
1953+
network = {}
1954+
for idx_i, poly1 in enumerate(lop):
1955+
for idx_j, poly2 in enumerate(lop):
1956+
if idx_i != idx_j:
1957+
connectivity = network.get(idx_i, set())
1958+
if poly1.intersection(poly2):
1959+
connectivity.add(idx_j)
1960+
network[idx_i] = connectivity
1961+
1962+
1963+
def walk_network(node: int, network: dict, nodes_visited: list[int]) -> list[int]:
1964+
"""
1965+
Walks the network modifying 'nodes_visited' as it walks.
1966+
"""
1967+
connections = network.get(node, set())
1968+
for connection in connections:
1969+
if connection in nodes_visited:
1970+
continue
1971+
else:
1972+
nodes_visited.append(connection)
1973+
walk_network(connection, network, nodes_visited)
1974+
return nodes_visited
1975+
1976+
# Traverse polygon connectivity network
1977+
nodes_visited = [0]
1978+
walk_network(0, network, nodes_visited)
1979+
print(nodes_visited)
1980+
print(network)
1981+
1982+
return set(nodes_visited) != set(network.keys())
1983+

0 commit comments

Comments
 (0)