summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2018-09-29 14:00:36 -0600
committerGitHub <noreply@github.com>2018-09-29 14:00:36 -0600
commit8830eb7d40befa78c24de84694c69ab958384cac (patch)
treeeff5809a68c0c37375a5e31be8ba57763938b2dd /lib/utils
parent5139c13fd7f43bb4d829e3c8225c51268e4d27d1 (diff)
new extension: split satin (#315)
This branch adds a new command to split a satin column at a specified point. The split happens at a stitch boundary to ensure that the two resulting satins sew just like the original. All parameters set on the original satin remain set on the two new satins, and all rungs are retained. If one of the satins would have no rungs left, a new rung is added. How to use: 1. Select a satin column (simple satin doesn't work) 2. Attach the "Satin split point" command using the "Attach commands to selected objects" extension. 3. Move the symbol (or just the connector line's endpoint) to point to the exact spot you want the satin to be split at. 4. Select the satin column again. 5. Run "Split Satin Column". 6. The split point command and connector line disappear, and nothing else appears to have happened. Select your satin and you'll see that it's been split. This extension is a by-product of my initial work on #214. Ink/Stitch will need the ability to split a satin at an arbitrary point, and I figured, why not go ahead and release that functionality as an extension while I'm at it? :)
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/geometry.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py
index ef5f12b5..64f6f16f 100644
--- a/lib/utils/geometry.py
+++ b/lib/utils/geometry.py
@@ -7,8 +7,11 @@ def cut(line, distance):
This is an example in the Shapely documentation.
"""
- if distance <= 0.0 or distance >= line.length:
- return [LineString(line), None]
+ if distance <= 0.0:
+ return [None, line]
+ elif distance >= line.length:
+ return [line, None]
+
coords = list(ShapelyPoint(p) for p in line.coords)
traveled = 0
last_point = coords[0]
@@ -88,6 +91,9 @@ class Point:
def length(self):
return math.sqrt(math.pow(self.x, 2.0) + math.pow(self.y, 2.0))
+ def distance(self, other):
+ return (other - self).length()
+
def unit(self):
return self.mul(1.0 / self.length())