diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-08-17 16:16:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-17 16:16:32 -0400 |
| commit | ece81d0c91c8b96f7da2c0339f6807a47d57112e (patch) | |
| tree | 0daf0758b275a2eb4d794c202dc8d2c0e17749eb /lib/utils/geometry.py | |
| parent | d7fddb0c946e19c571325a88ae5516bcbd0df128 (diff) | |
| parent | 72b8c367db613c3f44bce1174a8a5e8226bd2863 (diff) | |
Merge pull request #268 from inkstitch/lexelby-auto-fill-run
avoid cutting corners in auto-fill running stitch
Diffstat (limited to 'lib/utils/geometry.py')
| -rw-r--r-- | lib/utils/geometry.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py index d0cb96cf..bfdcd3c0 100644 --- a/lib/utils/geometry.py +++ b/lib/utils/geometry.py @@ -9,21 +9,22 @@ def cut(line, distance): """ if distance <= 0.0 or distance >= line.length: return [LineString(line), None] - coords = list(line.coords) - for i, p in enumerate(coords): - # TODO: I think this doesn't work if the path doubles back on itself - pd = line.project(ShapelyPoint(p)) - if pd == distance: + coords = list(ShapelyPoint(p) for p in line.coords) + traveled = 0 + last_point = coords[0] + for i, p in enumerate(coords[1:], 1): + traveled += p.distance(last_point) + last_point = p + if traveled == distance: return [ LineString(coords[:i+1]), LineString(coords[i:])] - if pd > distance: + if traveled > distance: cp = line.interpolate(distance) return [ LineString(coords[:i] + [(cp.x, cp.y)]), LineString([(cp.x, cp.y)] + coords[i:])] - def cut_path(points, length): """Return a subsection of at the start of the path that is length units long. |
