handle single linestrings properly (fixes #471)

pull/481/head
Lex Neva 2019-06-19 15:46:46 -04:00
rodzic 249c876ef5
commit e8bd745dfc
1 zmienionych plików z 11 dodań i 2 usunięć

Wyświetl plik

@ -312,6 +312,15 @@ def travel_grating(shape, angle, row_spacing):
return shgeo.MultiLineString(segments) return shgeo.MultiLineString(segments)
def ensure_multi_line_string(thing):
"""Given either a MultiLineString or a single LineString, return a MultiLineString"""
if isinstance(thing, shgeo.LineString):
return shgeo.MultiLineString([thing])
else:
return thing
def build_travel_edges(shape, fill_angle): def build_travel_edges(shape, fill_angle):
r"""Given a graph, compute the interior travel edges. r"""Given a graph, compute the interior travel edges.
@ -359,10 +368,10 @@ def build_travel_edges(shape, fill_angle):
for ls in mls for ls in mls
for coord in ls.coords] for coord in ls.coords]
diagonal_edges = grating1.symmetric_difference(grating2) diagonal_edges = ensure_multi_line_string(grating1.symmetric_difference(grating2))
# without this, floating point inaccuracies prevent the intersection points from lining up perfectly. # without this, floating point inaccuracies prevent the intersection points from lining up perfectly.
vertical_edges = snap(grating3.difference(grating1), diagonal_edges, 0.005) vertical_edges = ensure_multi_line_string(snap(grating3.difference(grating1), diagonal_edges, 0.005))
return endpoints, chain(diagonal_edges, vertical_edges) return endpoints, chain(diagonal_edges, vertical_edges)