diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-08-27 18:00:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-27 18:00:28 +0200 |
| commit | bf29b6c7bdffb86bf0265a143a0196bf2a8e5980 (patch) | |
| tree | 22fa549d0e4d7a2abc43983eca2c35e02cd17888 /lib/utils/clamp_path.py | |
| parent | 3be34ba8a3bff431160dd20cf14254a24d7d49a3 (diff) | |
fix camp weiredness (#3941)
Diffstat (limited to 'lib/utils/clamp_path.py')
| -rw-r--r-- | lib/utils/clamp_path.py | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/lib/utils/clamp_path.py b/lib/utils/clamp_path.py index 4c2ce7c5..c1f6fe25 100644 --- a/lib/utils/clamp_path.py +++ b/lib/utils/clamp_path.py @@ -131,31 +131,30 @@ def clamp_path_to_polygon(path, polygon): # The second part of this or condition checks whether part of the # path was removed by difference() above, because it coincided # with part of the shape border. - if not was_inside or last_point_inside.distance(start) > 0.01: - if last_point_inside is not None: - # We traveled outside or on the border of the shape for - # a while. In either case, we need to add a path along the - # border between the exiting and entering points. - - # First, find the two points. Buffer them just a bit to - # ensure intersection with the border. - exit_point = last_point_inside.buffer(0.01, quad_segs=1) - entry_point = ShapelyPoint(segment.coords[0]).buffer(0.01, quad_segs=1) - - if not exit_point.intersects(entry_point): - # Now break the border into pieces using those points. - border = find_border(polygon, exit_point) - border_pieces = ensure_multi_line_string(border.difference(MultiPolygon((entry_point, exit_point)))).geoms - border_pieces = fix_starting_point(border_pieces) - - # Pick the shortest way to get from the exiting to the - # entering point along the border. - shorter = min(border_pieces, key=lambda piece: piece.length) - - # We don't know which direction the polygon border - # piece should be. adjust_line_end() will figure - # that out. - result.append(adjust_line_end(shorter, entry_point)) + if not was_inside and last_point_inside is not None: + # We traveled outside or on the border of the shape for + # a while. In either case, we need to add a path along the + # border between the exiting and entering points. + + # First, find the two points. Buffer them just a bit to + # ensure intersection with the border. + exit_point = last_point_inside.buffer(0.01, quad_segs=1) + entry_point = ShapelyPoint(segment.coords[0]).buffer(0.01, quad_segs=1) + + if not exit_point.intersects(entry_point): + # Now break the border into pieces using those points. + border = find_border(polygon, exit_point) + border_pieces = ensure_multi_line_string(border.difference(MultiPolygon((entry_point, exit_point)))).geoms + border_pieces = fix_starting_point(border_pieces) + + # Pick the shortest way to get from the exiting to the + # entering point along the border. + shorter = min(border_pieces, key=lambda piece: piece.length) + + # We don't know which direction the polygon border + # piece should be. adjust_line_end() will figure + # that out. + result.append(adjust_line_end(shorter, entry_point)) result.append(segment) was_inside = True |
