Skip to content

Commit

Permalink
fix(polyface): Implement better check for overlapping edges
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jan 21, 2023
1 parent 2b6a8d5 commit 312eb21
Show file tree
Hide file tree
Showing 5 changed files with 1,217 additions and 13 deletions.
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ pytest-cov==2.12.0
Sphinx==1.8.5;python_version<'3.0'
Sphinx==3.3.1;python_version>='3.6'
docutils==0.17;python_version>='3.6'
sphinx-bootstrap-theme==0.7.1
sphinx-bootstrap-theme==0.8.1
sphinxcontrib-fulltoc==1.2.0
sphinxcontrib-websupport==1.1.2;python_version<'3.0'
sphinxcontrib-websupport==1.2.4;python_version>='3.6'
sphinx-click==2.7.1
twine==1.13.0;python_version<'3.0'
twine==3.4.1;python_version>='3.6'
wheel==0.36.2
wheel==0.38.1
setuptools==44.1.0;python_version<'3.0'
setuptools==57.0.0;python_version>='3.6'
setuptools==65.5.1;python_version>='3.6'
importlib-metadata==2.0.0;python_version<'3.0'
importlib-metadata==4.0.1;python_version>='3.6'
jinja2==3.0.3;python_version>='3.6'
Expand Down
2 changes: 1 addition & 1 deletion ladybug_geometry/_polyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def _group_vertices(segments, tolerance):
Args:
segments: An array of LineSegment objects.
tolerance: The minimum difference in X, Y, and Z values at which Points
are considred equivalent. Segments with points that match within the
are considered equivalent. Segments with points that match within the
tolerance will be joined.
Returns:
Expand Down
46 changes: 39 additions & 7 deletions ladybug_geometry/geometry3d/polyface.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,32 +465,64 @@ def merge_overlapping_edges(self, tolerance, angle_tolerance):
# get all of the edges that are colinear with the first edge
coll_edges = list(naked_edge_ind[0])
coll_i = [naked_edge_i[0]]
kept_i = []
kept_i, maybe_kept_i = [], []
for edge, ind, nei, i in zip(
naked_edges[1:], naked_edge_ind[1:], naked_edge_i[1:],
xrange(1, len(naked_edges))):
try:
if edge.is_colinear(naked_edges[0], tolerance, angle_tolerance):
coll_edges.extend(ind)
coll_i.append(nei)
maybe_kept_i.append(i)
else:
kept_i.append(i)
except ZeroDivisionError: # duplicate vertices resulted in 0 length edge
coll_edges.extend(ind)
coll_i.append(nei)
maybe_kept_i.append(i)

# determine if colinear edges create a full double line along the edge
if len(coll_edges) == 1:
if len(coll_edges) == 1: # definitely a naked edge
overlapping = False
else:
else: # all colinear edges are likely a part of the same loop
final_vi = []
coll_edges.sort()
coll_edges_sort = sorted(coll_edges)
overlapping = True
for i in range(0, len(coll_edges), 2):
final_vi.append(coll_edges[i])
if not coll_edges[i] == coll_edges[i + 1]:
for i in range(0, len(coll_edges_sort), 2):
final_vi.append(coll_edges_sort[i])
if coll_edges_sort[i] != coll_edges_sort[i + 1]:
overlapping = False
break
# there's still a chance we have multiple colinear loops
if not overlapping:
dup = {x for x in coll_edges if coll_edges.count(x) > 1}
if coll_edges[0] in dup and coll_edges[1] in dup:
rebuilt_edges = [(coll_edges[i], coll_edges[i + 1])
for i in range(0, len(coll_edges), 2)]
loop_i = set(rebuilt_edges[0])
edge_to_check = rebuilt_edges[1:]
more_to_check = True
while more_to_check:
for i, r_seg in enumerate(edge_to_check):
if (r_seg[0] in loop_i or r_seg[1] in loop_i):
loop_i.add(r_seg[0])
loop_i.add(r_seg[1])
del edge_to_check[i]
break
else:
more_to_check = False
if all(li in dup for li in loop_i): # we have found a loop!
final_vi = list(loop_i)
new_coll_i = [coll_i[0]]
zip_obj = zip(rebuilt_edges[1:], coll_i[1:], maybe_kept_i)
for ind, nei, i in zip_obj:
if ind[0] in loop_i:
new_coll_i.append(nei)
else:
kept_i.append(i)
kept_i.sort()
coll_i = new_coll_i
overlapping = True

# if fully overlapping edges have been found, remake them into one
if overlapping:
Expand Down
Loading

0 comments on commit 312eb21

Please sign in to comment.