diff options
| author | Lex Neva <github.com@lexneva.name> | 2018-08-17 16:19:46 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2018-08-17 16:19:46 -0400 |
| commit | 0e4c3a3f1b76c1b655ec2788017335e87eff29da (patch) | |
| tree | 2075fc0292038b4a2e92fc018b503805cf30fdec /lib/utils/geometry.py | |
| parent | 19bb8a5a6dbe4244a590147187949d0555eb9fbc (diff) | |
| parent | ece81d0c91c8b96f7da2c0339f6807a47d57112e (diff) | |
Merge remote-tracking branch 'origin/master' into lexelby-no-embroider-command
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. |
