summaryrefslogtreecommitdiff
path: root/lib/utils/geometry.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2022-11-27 08:37:59 +0100
committerGitHub <noreply@github.com>2022-11-27 08:37:59 +0100
commite9278c55c34b72bb0beccf0d9b8bfe300aacac70 (patch)
tree0bd9728003f1cf8b03ba2ed610fafdcd217267fd /lib/utils/geometry.py
parent9c0b64560cadc246b3555951ddb1e21960662553 (diff)
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
Diffstat (limited to 'lib/utils/geometry.py')
-rw-r--r--lib/utils/geometry.py41
1 files changed, 34 insertions, 7 deletions
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