Smoothing and clamping (#3772)

* smoothing: ensure start and end of original path
* clamp path: never intersecting path could also be entirely in the exterior of the shape
pull/3779/head dev-build-kaalleen-disable-live-preview-select-elements
Kaalleen 2025-06-04 20:01:53 +02:00 zatwierdzone przez GitHub
rodzic c27098508b
commit 547237d50a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 9 dodań i 5 usunięć

Wyświetl plik

@ -106,7 +106,10 @@ def clamp_path_to_polygon(path, polygon):
except FloatingPointError:
return path
if len(split_path.geoms) == 1:
# contains() checks can fail without the buffer.
buffered_polygon = prep(polygon.buffer(1e-9))
if len(split_path.geoms) == 1 and buffered_polygon.contains(split_path.geoms[0]):
# The path never intersects with the polygon, so it's entirely inside.
return path
@ -114,9 +117,6 @@ def clamp_path_to_polygon(path, polygon):
# start or end coincides with the polygon boundary
split_path = [ShapelyPoint(start), *split_path.geoms, ShapelyPoint(end)]
# contains() checks can fail without the buffer.
buffered_polygon = prep(polygon.buffer(1e-9))
last_point_inside = None
was_inside = False
result = []

Wyświetl plik

@ -57,4 +57,8 @@ def smooth_path(path, smoothness=1.0, iterations=5):
r[-1] = ll[-1]
points = ll * 0.75 + r * 0.25
return [Point(*coord) for coord in points]
# we want to keep the old start and end points
start = [Point(* path[0])]
end = [Point(* path[-1])]
return start + [Point(*coord) for coord in points] + end