kopia lustrzana https://github.com/inkstitch/inkstitch
fix some shapelydeprecations
rodzic
fc3d05845a
commit
e6fcf11035
|
|
@ -90,7 +90,7 @@ def which_outline(shape, coords):
|
|||
# fail sometimes.
|
||||
|
||||
point = shgeo.Point(*coords)
|
||||
outlines = list(shape.boundary)
|
||||
outlines = list(shape.boundary.geoms)
|
||||
outline_indices = list(range(len(outlines)))
|
||||
closest = min(outline_indices,
|
||||
key=lambda index: outlines[index].distance(point))
|
||||
|
|
@ -104,7 +104,7 @@ def project(shape, coords, outline_index):
|
|||
This returns the distance along the outline at which the point resides.
|
||||
"""
|
||||
|
||||
outline = list(shape.boundary)[outline_index]
|
||||
outline = list(shape.boundary.geoms)[outline_index]
|
||||
return outline.project(shgeo.Point(*coords))
|
||||
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ def tag_nodes_with_outline_and_projection(graph, shape, nodes):
|
|||
|
||||
|
||||
def add_boundary_travel_nodes(graph, shape):
|
||||
for outline_index, outline in enumerate(shape.boundary):
|
||||
for outline_index, outline in enumerate(shape.boundary.geoms):
|
||||
prev = None
|
||||
for point in outline.coords:
|
||||
point = shgeo.Point(point)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from .sample_linestring import raster_line_string_with_priority_points
|
|||
from ..debug import debug
|
||||
from ..i18n import _
|
||||
from ..stitch_plan import Stitch
|
||||
from ..utils.geometry import Point as InkstitchPoint
|
||||
from ..utils.geometry import Point as InkstitchPoint, reverse_line_string
|
||||
|
||||
|
||||
@debug.time
|
||||
|
|
@ -276,7 +276,7 @@ def intersect_region_with_grating_guideline(shape, line, row_spacing, flip=False
|
|||
line_offsetted = repair_non_simple_lines(line_offsetted)
|
||||
|
||||
if row_spacing < 0:
|
||||
line_offsetted.coords = line_offsetted.coords[::-1]
|
||||
line_offsetted = reverse_line_string(line_offsetted)
|
||||
line_offsetted = line_offsetted.simplify(0.01, False)
|
||||
res = line_offsetted.intersection(shape)
|
||||
if row_spacing > 0 and not isinstance(res, (GeometryCollection, MultiLineString)):
|
||||
|
|
@ -290,7 +290,7 @@ def intersect_region_with_grating_guideline(shape, line, row_spacing, flip=False
|
|||
if not line_offsetted.is_simple:
|
||||
line_offsetted = repair_non_simple_lines(line_offsetted)
|
||||
# using negative row spacing leads as a side effect to reversed offsetted lines - here we undo this
|
||||
line_offsetted.coords = line_offsetted.coords[::-1]
|
||||
line_offsetted = reverse_line_string(line_offsetted)
|
||||
line_offsetted = line_offsetted.simplify(0.01, False)
|
||||
res = line_offsetted.intersection(shape)
|
||||
return rows
|
||||
|
|
|
|||
|
|
@ -33,81 +33,6 @@ def offset_linear_ring(ring, offset, resolution, join_style, mitre_limit):
|
|||
result_list.append(poly.exterior)
|
||||
return MultiLineString(result_list)
|
||||
|
||||
# """
|
||||
# Solves following problem: When shapely offsets a LinearRing the
|
||||
# start/end point might be handled wrongly since they
|
||||
# are only treated as LineString.
|
||||
# (See e.g. https://i.stack.imgur.com/vVh56.png as a problematic example)
|
||||
# This method checks first whether the start/end point form a problematic
|
||||
# edge with respect to the offset side. If it is not a problematic
|
||||
# edge we can use the normal offset_routine. Otherwise we need to
|
||||
# perform two offsets:
|
||||
# -offset the ring
|
||||
# -offset the start/end point + its two neighbors left and right
|
||||
# Finally both offsets are merged together to get the correct
|
||||
# offset of a LinearRing
|
||||
# """
|
||||
|
||||
# PROBLEM: Did not work in rare cases since it expects the point order be maintained after offsetting the curve
|
||||
# (e.g. the first point in the offsetted curve shall belong to the first point in the original curve). However, this
|
||||
# assumption seems to be not always true that is why this code was replaced by the buffer routine.
|
||||
|
||||
# coords = ring.coords[:]
|
||||
# # check whether edge at index 0 is concave or convex. Only for
|
||||
# # concave edges we need to spend additional effort
|
||||
# dx_seg1 = dy_seg1 = 0
|
||||
# if coords[0] != coords[-1]:
|
||||
# dx_seg1 = coords[0][0] - coords[-1][0]
|
||||
# dy_seg1 = coords[0][1] - coords[-1][1]
|
||||
# else:
|
||||
# dx_seg1 = coords[0][0] - coords[-2][0]
|
||||
# dy_seg1 = coords[0][1] - coords[-2][1]
|
||||
# dx_seg2 = coords[1][0] - coords[0][0]
|
||||
# dy_seg2 = coords[1][1] - coords[0][1]
|
||||
# # use cross product:
|
||||
# crossvalue = dx_seg1 * dy_seg2 - dy_seg1 * dx_seg2
|
||||
# sidesign = 1
|
||||
# if side == "left":
|
||||
# sidesign = -1
|
||||
|
||||
# # We do not need to take care of the joint n-0 since we
|
||||
# # offset along a concave edge:
|
||||
# if sidesign * offset * crossvalue <= 0:
|
||||
# return ring.parallel_offset(offset, side, resolution, join_style, mitre_limit)
|
||||
|
||||
# # We offset along a convex edge so we offset the joint n-0 separately:
|
||||
# if coords[0] != coords[-1]:
|
||||
# coords.append(coords[0])
|
||||
# offset_ring1 = ring.parallel_offset(
|
||||
# offset, side, resolution, join_style, mitre_limit
|
||||
# )
|
||||
# offset_ring2 = LineString((coords[-2], coords[0], coords[1])).parallel_offset(
|
||||
# offset, side, resolution, join_style, mitre_limit
|
||||
# )
|
||||
|
||||
# # Next we need to merge the results:
|
||||
# if offset_ring1.geom_type == "LineString":
|
||||
# return LinearRing(offset_ring2.coords[:] + offset_ring1.coords[1:-1])
|
||||
# else:
|
||||
# # We have more than one resulting LineString for offset of
|
||||
# # the geometry (ring) = offset_ring1.
|
||||
# # Hence we need to find the LineString which belongs to the
|
||||
# # offset of element 0 in coords =offset_ring2
|
||||
# # in order to add offset_ring2 geometry to it:
|
||||
# result_list = []
|
||||
# thresh = constants.offset_factor_for_adjacent_geometry * abs(offset)
|
||||
# for offsets in offset_ring1:
|
||||
# if (
|
||||
# abs(offsets.coords[0][0] - coords[0][0]) < thresh
|
||||
# and abs(offsets.coords[0][1] - coords[0][1]) < thresh
|
||||
# ):
|
||||
# result_list.append(
|
||||
# LinearRing(offset_ring2.coords[:] + offsets.coords[1:-1])
|
||||
# )
|
||||
# else:
|
||||
# result_list.append(LinearRing(offsets))
|
||||
# return MultiLineString(result_list)
|
||||
|
||||
|
||||
def take_only_valid_linear_rings(rings):
|
||||
"""
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue