From e9278c55c34b72bb0beccf0d9b8bfe300aacac70 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Sun, 27 Nov 2022 08:37:59 +0100 Subject: This and that (#1727) * dont fail on satin with fill * fill stitch error message * convert to satin mac issue * auto_satin: add rung for two node old style satins * avoid divide by zero in intersect_region_with_grating * fix for incorrect stagger in guided fill * better rail sectioning algorithm * fix #1780 * fix #1816 Co-authored-by: Lex Neva --- lib/utils/geometry.py | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'lib/utils/geometry.py') diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py index 30457749..98f40709 100644 --- a/lib/utils/geometry.py +++ b/lib/utils/geometry.py @@ -39,6 +39,40 @@ def cut(line, distance, normalized=False): LineString([(cp.x, cp.y)] + coords[i:])] +def cut_multiple(line, distances, normalized=False): + """Cut a LineString at multiple distances along that line. + + Always returns a list of N + 1 members, where N is the number of distances + provided. Some members of the list may be None, indicating an empty + segment. This can happen if one of the distances is at the start or end + of the line, or if duplicate distances are provided. + + Returns: + a list of LineStrings or None values""" + + distances = list(sorted(distances)) + + segments = [line] + distance_so_far = 0 + nones = [] + + for distance in distances: + segment = segments.pop() + before, after = cut(segment, distance - distance_so_far, normalized) + + segments.append(before) + + if after is None: + nones.append(after) + else: + if before is not None: + distance_so_far += before.length + segments.append(after) + + segments.extend(nones) + return segments + + def roll_linear_ring(ring, distance, normalized=False): """Make a linear ring start at a different point. @@ -113,13 +147,6 @@ def cut_path(points, length): return [Point(*point) for point in subpath.coords] -def collapse_duplicate_point(geometry): - if geometry.area < 0.01: - return geometry.representative_point() - - return geometry - - class Point: def __init__(self, x, y): self.x = x -- cgit v1.2.3